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.
|
||||
*/
|
||||
protected static Template compile (Reader source, Compiler compiler) {
|
||||
Accumulator accum = new Parser(compiler).parse(source);
|
||||
return new Template(accum.finish(), compiler);
|
||||
String originalDelims = compiler.delims == null ? null : compiler.delims.toString();
|
||||
//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
|
||||
@@ -422,6 +430,26 @@ public class Mustache
|
||||
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) {
|
||||
String[] delims = dtext.split(" ");
|
||||
if (delims.length != 2) throw new MustacheException(errmsg(dtext));
|
||||
|
||||
@@ -489,6 +489,18 @@ public class MustacheTest
|
||||
});
|
||||
}
|
||||
|
||||
@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("<b>Willy is awesome.</b>", "{{#bold}}{{name}} is awesome.{{/bold}}",
|
||||
context("name", "Willy", "bold", new Mustache.Lambda() {
|
||||
|
||||
Reference in New Issue
Block a user