Search in sources :

Example 1 with HtmlCommentNode

use of com.google.template.soy.soytree.HtmlCommentNode in project closure-templates by google.

the class AddHtmlCommentsForDebugPass method createSoyDebug.

/**
 * Generates an AST fragment that looks like:
 *
 * <p>{@code {if debugSoyTemplateInfo()}<!--dta_of...-->{/if}}
 *
 * @param insertionLocation The location where it is being inserted
 * @param nodeIdGen The id generator to use
 * @param htmlComment The content of the HTML comment
 */
private IfNode createSoyDebug(SourceLocation insertionLocation, IdGenerator nodeIdGen, String htmlComment) {
    IfNode ifNode = new IfNode(nodeIdGen.genId(), insertionLocation);
    FunctionNode funcNode = new FunctionNode(DebugSoyTemplateInfoFunction.INSTANCE, insertionLocation);
    funcNode.setType(BoolType.getInstance());
    IfCondNode ifCondNode = new IfCondNode(nodeIdGen.genId(), insertionLocation, "if", funcNode);
    HtmlCommentNode htmlCommentNode = new HtmlCommentNode(nodeIdGen.genId(), insertionLocation);
    // We need to escape the input HTML comments, in cases the file location contains "-->".
    htmlCommentNode.addChild(new RawTextNode(nodeIdGen.genId(), htmlEscaper().escape(htmlComment), insertionLocation));
    ifCondNode.addChild(htmlCommentNode);
    ifNode.addChild(ifCondNode);
    return ifNode;
}
Also used : IfCondNode(com.google.template.soy.soytree.IfCondNode) FunctionNode(com.google.template.soy.exprtree.FunctionNode) IfNode(com.google.template.soy.soytree.IfNode) RawTextNode(com.google.template.soy.soytree.RawTextNode) HtmlCommentNode(com.google.template.soy.soytree.HtmlCommentNode)

Aggregations

FunctionNode (com.google.template.soy.exprtree.FunctionNode)1 HtmlCommentNode (com.google.template.soy.soytree.HtmlCommentNode)1 IfCondNode (com.google.template.soy.soytree.IfCondNode)1 IfNode (com.google.template.soy.soytree.IfNode)1 RawTextNode (com.google.template.soy.soytree.RawTextNode)1