-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Explicit block definition #1271
Comments
tldr, proposed changes are:
(Of course These changes make the block engine usable in single flat Jade files and will very likely eliminate a nasty bug with includes in combination with layouts. |
In light of the multiple issues discussed, the block feature obviously needs more explicit behavior. append and prepend should indeed not yield, as I described in #997 (comment). I like the idea of block replace: we explicitly say "I want to replace/implement the block named name". (I hesitate between replace and implement, since default values for block seem to not be the usual case: in many cases the extended layout just defines placeholders to yield something defined later.) Implicitly defining a block as it's done today mixes two notions: defining where to yield the content if we are not in the root level of an extending .jade (btw what happens if this extending .jade is also used by another extends?), and maybe replacing a previously defined block. This is confusing. This may however limit the possibilities with includes: we could maybe imagine a use-case where an include is both used in an extending and an extended .jade, but I'm not sure it's really an issue, as it's probably not possible today due to the multiple issues around this. Also, why resetting appended and prepended values when replacing a block? If we want to avoid implicit behaviors we could have block replace and block reset: this way replace works as block today: we don't reset the previously appended and prepended values. Finally, why multiple block with the same name? This creates new unexpected behaviors: we can define different default values, but we cannot modify only one of them, the replace, append and prepend will modify all of them. If you want multiple yield points for the same block maybe add a block yield feature, this way we explicit the behavior, and we refuse children for this one. Anyway, these changes are breaking changes: we break the main usage of block, this will have to be dealt with as the Jade project is use by many. Maybe use a different name than block? |
Maybe we really need All block operations (
p.friend
block friend
| Tobi
p.friend
block friend
| Meowingtons
p.no-friend
block friend
prepend friend
| I like
append friend
| . He's ony of my best friends. <p class="friend">I like Tobi. He's one of my best friends.</p>
<p class="friend">I like Meowingtons. He's one of my best friends.</p>
<p class="no-friend">I like . He's one of my best friends.</p> |
+1 for more explicit behaviour in blocks |
In short, you cannot append a block in the same file. EOD. If you want to append a block, then use |
Currently all three block statements (
block
,append
,prepend
) implicitly define a new block, if they can't already find a block with the same name in the extended layout.This is problematic, when using blocks in a single file without a layout (and for includes, but that's another topic).
This is caused by the ambigious use of the
block name
statement. On the one handblock test
could create a new block in its current place, on the other hand it could replace all other occurences.Apparently it does all together. Because changing
block test
toappend test
(which is short forblock prepare test
) leads to this rather funny result.IMHO blocks should get more explicit and so I made up my mind on this. (I'm rather sorry that this is somewhat f a cross-breed of a bug report and a Google Groups post.)
I would implement this myself and make a PR, but I'm not familiar enough with Jade's internal engine to be able to safely do it all alone and not produce 20 new bugs by the way. Yet I think, that this shouldn't be too much of a change in the code.
append
,prepend
andreplace
become something like a mixin (as in not yielding output) and the block engine gets a little twist so that multiple blocks of the same name are allowed.I find this much more predictable than the original interface and would like to hear your thoughts on this.
The text was updated successfully, but these errors were encountered: