Render blocks in the parent context and assure a block is passed to templates that use @partial-block#620
Conversation
templates that use @partial-block
|
|
||
|
|
||
| /** | ||
| * If true, given partial blocks are not evaluated when defined but when used. |
There was a problem hiding this comment.
Let's add two examples when this flag is on/off
There was a problem hiding this comment.
Hey I added two tests that deal with this pull request's changes. Is everything okay now?
|
|
||
| Template template = inlineTemplates.get(path); | ||
|
|
||
|
|
| } | ||
|
|
||
| } | ||
| context.data("callee", this); |
There was a problem hiding this comment.
This is something internal and it shouldn't be called callee. Let's create a name which is hard to override by users like Context. INVOCATION_STACK or/and by prefixing the class name: com.github.jknack.handlebars.internal.Partial.calle
| */ | ||
| private static boolean exists(final List<TemplateSource> invocationStack, | ||
| final String filename) { | ||
| final String filename) { |
There was a problem hiding this comment.
please revert all the whitespace changes
| final boolean parentIsNotLastPartialBlock = !isCalleeOf(callee, lastPartialBlock); | ||
|
|
||
| if (pathIsPartialBlock && parentIsNotLastPartialBlock) { | ||
| throw new IllegalArgumentException( |
There was a problem hiding this comment.
Already merged it, but I'm struggling to figure out why we do fail here, can you explain?
Here is a test case that fails today bc of this check:
shouldCompileTo("{{#> dude x=23}}{{#> dude x=12}}{{/dude}}{{/dude}}",
$("hash", $(), "partials",
$("dude", "<div {{#if x}}x={{x}}{{/if}}>{{> @partial-block}}</div>")),
"<div x=23><div x=12></div></div>");
There was a problem hiding this comment.
Hi and thanks for the merge! We'll get back to you about this asap.
We heavily use
@partial-blockin our project context. We noticed the following flaws with the current evaluation of partial-blocks in handlebars.java:@partial-blockthrows a stack overflow error (infinite recursion), when a block of a partial provides a template which also contains@partial-block(see example below). This is fixed by this pull request. Handlebars.js also supports this, see WIP: Possible fix for #1252: Using @partial-block twice in a template not possible handlebars-lang/handlebars.js#1290callee. It is used to check whether the last provided partial-block is the right partial block for the given call to{{> @partial-block}}.stack overflow example: