Reset compiler.delims after parsing a template
This commit is contained in:
@@ -218,8 +218,16 @@ public class Mustache
|
|||||||
* Compiles the supplied template into a repeatedly executable intermediate form.
|
* Compiles the supplied template into a repeatedly executable intermediate form.
|
||||||
*/
|
*/
|
||||||
protected static Template compile (Reader source, Compiler compiler) {
|
protected static Template compile (Reader source, Compiler compiler) {
|
||||||
Accumulator accum = new Parser(compiler).parse(source);
|
String originalDelims = compiler.delims == null ? null : compiler.delims.toString();
|
||||||
return new Template(accum.finish(), compiler);
|
//compiler.delims.start1
|
||||||
|
try {
|
||||||
|
Accumulator accum = new Parser(compiler).parse(source);
|
||||||
|
return new Template(accum.finish(), compiler);
|
||||||
|
} finally {
|
||||||
|
if (originalDelims != null) {
|
||||||
|
compiler.delims.updateDelims(originalDelims);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Mustache () {} // no instantiateski
|
private Mustache () {} // no instantiateski
|
||||||
@@ -421,6 +429,26 @@ public class Mustache
|
|||||||
public boolean isStaches () {
|
public boolean isStaches () {
|
||||||
return start1 == '{' && start2 == '{' && end1 == '}' && end2 == '}';
|
return start1 == '{' && start2 == '{' && end1 == '}' && end2 == '}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a String representation that is compatible with
|
||||||
|
* {@link #updateDelims(java.lang.String)}.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append(start1);
|
||||||
|
if (start2 != NO_CHAR) {
|
||||||
|
builder.append(start2);
|
||||||
|
}
|
||||||
|
builder.append(" ");
|
||||||
|
builder.append(end1);
|
||||||
|
if (end2 != NO_CHAR) {
|
||||||
|
builder.append(end2);
|
||||||
|
}
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
public Delims updateDelims (String dtext) {
|
public Delims updateDelims (String dtext) {
|
||||||
String[] delims = dtext.split(" ");
|
String[] delims = dtext.split(" ");
|
||||||
|
|||||||
@@ -488,6 +488,18 @@ public class MustacheTest
|
|||||||
String nullvar = null;
|
String nullvar = null;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test public void testCompilingDoesntChangeCompilersDelimiters() {
|
||||||
|
Mustache.Compiler compiler = Mustache.compiler();
|
||||||
|
test(compiler,
|
||||||
|
"value", "{{=<% %>=}}<% variable %>", new Object() {
|
||||||
|
String variable = "value";
|
||||||
|
});
|
||||||
|
test(compiler,
|
||||||
|
"value", "{{=<% %>=}}<% variable %>", new Object() {
|
||||||
|
String variable = "value";
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Test public void testLambda1 () {
|
@Test public void testLambda1 () {
|
||||||
test("<b>Willy is awesome.</b>", "{{#bold}}{{name}} is awesome.{{/bold}}",
|
test("<b>Willy is awesome.</b>", "{{#bold}}{{name}} is awesome.{{/bold}}",
|
||||||
|
|||||||
Reference in New Issue
Block a user