Skip to content

Commit

Permalink
raw-helper inside conditional results in Exception fix #519
Browse files Browse the repository at this point in the history
  • Loading branch information
jknack committed Jul 10, 2016
1 parent 713cde6 commit bfd8db2
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -233,23 +233,11 @@ DELIM
.
;

mode RAW;

RAW_SPACE
:
[ \t\r\n]
;

RAW_CONTENT
:
{consumeUntil(start + "{{/")}? . -> popMode
;

mode VAR;

END_RAW
:
{endToken(end, "}}")}? . -> mode(RAW)
{endToken(end, "}}")}? . -> popMode
;

END_T
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ escape
text
:
TEXT
| RAW_CONTENT
| RAW_SPACE
;

spaces
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ public Template visitRawBlock(final RawBlockContext ctx) {

Template body = visitBody(ctx.thenBody);
if (body != null) {
block.body(body);
// rewrite raw template
block.body(new Text(handlebars, body.text()));
}
hasTag(true);
qualifier.removeLast();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.github.jknack.handlebars.issues;

import static org.junit.Assert.assertEquals;

import java.io.IOException;

import org.junit.Test;

import com.github.jknack.handlebars.AbstractTest;
import com.github.jknack.handlebars.Helper;
import com.github.jknack.handlebars.Options;

public class Hbs519 extends AbstractTest {

@Test
public void shouldCompileRawHelperStatementInsideConditional() throws IOException {
shouldCompileTo("{{#unless test}}{{{{raw-helper}}}}{{testing}}{{{{/raw-helper}}}}{{/unless}}",
$, $("raw-helper", new Helper<Object>() {

@Override
public Object apply(final Object context, final Options options) throws IOException {
return options.fn();
}

}), "{{testing}}");
}

@Test
public void shouldGetTextVersionOfRawHelperInsideConditional() throws IOException {
assertEquals("{{#unless test}}{{{{raw-helper}}}}{{testing}}{{{{/raw-helper}}}}{{/unless}}",
compile("{{#unless test}}{{{{raw-helper}}}}{{testing}}{{{{/raw-helper}}}}{{/unless}}")
.text());
}

}

0 comments on commit bfd8db2

Please sign in to comment.