Add mechism to visit template tags.

This is useful when you want to inspect the structure of the template without
executing it.
This commit is contained in:
Michael Bayne
2017-12-17 15:16:09 -08:00
parent 326f04cb1e
commit 37e31cbeac
3 changed files with 110 additions and 12 deletions
@@ -149,6 +149,16 @@ public class Template {
executeSegs(new Context(context, pctx, 0, false, false), out);
}
/**
* Visits the tags in this template (via {@code visitor}) without executing it.
* @param visitor the visitor to be called back on each tag in the template.
*/
public void visit (Mustache.Visitor visitor) {
for (Segment seg : _segs) {
seg.visit(visitor);
}
}
protected Template (Segment[] segs, Mustache.Compiler compiler) {
_segs = segs;
_compiler = compiler;
@@ -367,6 +377,8 @@ public class Template {
abstract void decompile (Mustache.Delims delims, StringBuilder into);
abstract void visit (Mustache.Visitor visitor);
protected static void write (Writer out, String data) {
try {
out.write(data);