use of com.google.template.soy.soytree.TemplateDelegateNode in project closure-templates by google.
the class AddHtmlCommentsForDebugPassTest method runPass.
/**
* Parses the given input as a Soy file content, runs the AddHtmlCommentsForDebug pass and returns
* a map that contains pairs of template names and rewritten template body.
*/
private static ImmutableMap<String, String> runPass(String input, String fileName) {
String soyFile = "{namespace ns}" + input;
IncrementingIdGenerator nodeIdGen = new IncrementingIdGenerator();
ErrorReporter boom = ErrorReporter.exploding();
SoyFileSetNode soyTree = SoyFileSetParserBuilder.forSuppliers(SoyFileSupplier.Factory.create(soyFile, SoyFileKind.SRC, fileName)).errorReporter(boom).parse().fileSet();
TemplateRegistry registry = new TemplateRegistry(soyTree, boom);
// We need to run HtmlRewritePass to produce HTML nodes. Otherwise we will not add any comments.
new HtmlRewritePass(boom).run(soyTree.getChild(0), nodeIdGen);
new AddHtmlCommentsForDebugPass().run(soyTree, registry);
ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
for (TemplateNode node : soyTree.getChild(0).getChildren()) {
StringBuilder sb = new StringBuilder();
node.appendSourceStringForChildren(sb);
String templateName = (node instanceof TemplateDelegateNode) ? ((TemplateDelegateNode) node).getDelTemplateName() : node.getTemplateName();
builder.put(templateName, sb.toString());
}
return builder.build();
}
Aggregations