Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow pug template inheritance #572

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

benblazak
Copy link

Fixes #459.

Allows for pug template inheritance.

The issue was that extends statements must occur first in a pug file, but the svelte mixins were being inserted at the top of the file contents before being passed to pug.

I made changes so that if an extends statement occurs as the first line in a file, it is split off from the rest of the content and inserted before the svelte mixins.

  • test
  • lint

notes

I wasn't able to research or test whether there are other things that should also be kept before svelte mixins.

// separate content that needs to come before the svelte mixins
let preContent = '';

if (content.startsWith('extends')) {
Copy link
Member

@kaisermann kaisermann Mar 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the example of inheritance from pug's documentation, what do you think of also adding support for files that start with a comment?

//- page-a.pug
extends layout.pug

block scripts
  script(src='/jquery.js')
  script(src='/pets.js')

@kaisermann
Copy link
Member

Hey @benblazak, thanks for this! Just added a small suggestion 🙏

@benblazak
Copy link
Author

Ahh good catch @kaisermann. To properly allow comments though, we'd probably need to parse them (there can be more than one before extends right? and multi-line comments are allowed in that location too?), which is more than I'm up for right now (in the middle of a move -> new job).

Thinking about it, it might make more sense to stop including mixins by default at all, and put them in a separate file for people to include if they want. But that would be a breaking change.

@simiraaaa simiraaaa mentioned this pull request May 11, 2023
1 task
@simiraaaa
Copy link
Contributor

@kaisermann @benblazak
#599

Fixed so that extends works with comments and prependData.
Please refer to it.

(Machine translation from Japanese to English at DeepL)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cannot use pug template inheritance
3 participants