Search in sources :

Example 11 with TemplateDelegateNode

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();
}
Also used : TemplateNode(com.google.template.soy.soytree.TemplateNode) TemplateDelegateNode(com.google.template.soy.soytree.TemplateDelegateNode) TemplateRegistry(com.google.template.soy.soytree.TemplateRegistry) ErrorReporter(com.google.template.soy.error.ErrorReporter) SoyFileSetNode(com.google.template.soy.soytree.SoyFileSetNode) IncrementingIdGenerator(com.google.template.soy.base.internal.IncrementingIdGenerator) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

TemplateDelegateNode (com.google.template.soy.soytree.TemplateDelegateNode)11 TemplateNode (com.google.template.soy.soytree.TemplateNode)5 ImmutableMap (com.google.common.collect.ImmutableMap)3 TemplateParam (com.google.template.soy.soytree.defn.TemplateParam)3 ImmutableList (com.google.common.collect.ImmutableList)2 SanitizedContentKind (com.google.template.soy.base.internal.SanitizedContentKind)2 TemplateBasicNode (com.google.template.soy.soytree.TemplateBasicNode)2 FieldDescriptor (com.google.protobuf.Descriptors.FieldDescriptor)1 IncrementingIdGenerator (com.google.template.soy.base.internal.IncrementingIdGenerator)1 IndentedLinesBuilder (com.google.template.soy.base.internal.IndentedLinesBuilder)1 UniqueNameGenerator (com.google.template.soy.base.internal.UniqueNameGenerator)1 SoyDataException (com.google.template.soy.data.SoyDataException)1 SoyValue (com.google.template.soy.data.SoyValue)1 IntegerData (com.google.template.soy.data.restricted.IntegerData)1 ErrorReporter (com.google.template.soy.error.ErrorReporter)1 ExprRootNode (com.google.template.soy.exprtree.ExprRootNode)1 FieldAccessNode (com.google.template.soy.exprtree.FieldAccessNode)1 GlobalNode (com.google.template.soy.exprtree.GlobalNode)1 ProtoInitNode (com.google.template.soy.exprtree.ProtoInitNode)1 VarRefNode (com.google.template.soy.exprtree.VarRefNode)1