Search in sources :

Example 1 with HtmlCloseTagNode

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

the class HtmlRewritePass method run.

@Override
public void run(SoyFileNode file, IdGenerator nodeIdGen) {
    new Visitor(nodeIdGen, file.getFilePath(), errorReporter).exec(file);
    /*
     * Validates that the only children of close tags can be {@code phname} attributes.
     *
     * <p>Later passes validate that phnames for close tags only appear in messages.
     */
    for (HtmlCloseTagNode closeTag : SoyTreeUtils.getAllNodesOfType(file, HtmlCloseTagNode.class)) {
        List<StandaloneNode> children = closeTag.getChildren();
        HtmlAttributeNode phNameAttribute = closeTag.getDirectAttributeNamed(MessagePlaceholders.PHNAME_ATTR);
        HtmlAttributeNode phExAttribute = closeTag.getDirectAttributeNamed(MessagePlaceholders.PHEX_ATTR);
        // the child at index 0 is the tag name
        for (int i = 1; i < children.size(); i++) {
            StandaloneNode child = children.get(i);
            if (child == phNameAttribute || child == phExAttribute) {
                // the phname and phex attributes are validated later and allowed in close nodes
                continue;
            }
            errorReporter.report(child.getSourceLocation(), UNEXPECTED_CLOSE_TAG_CONTENT);
        }
    }
}
Also used : StandaloneNode(com.google.template.soy.soytree.SoyNode.StandaloneNode) AbstractSoyNodeVisitor(com.google.template.soy.soytree.AbstractSoyNodeVisitor) HtmlAttributeNode(com.google.template.soy.soytree.HtmlAttributeNode) Checkpoint(com.google.template.soy.error.ErrorReporter.Checkpoint) HtmlCloseTagNode(com.google.template.soy.soytree.HtmlCloseTagNode)

Aggregations

Checkpoint (com.google.template.soy.error.ErrorReporter.Checkpoint)1 AbstractSoyNodeVisitor (com.google.template.soy.soytree.AbstractSoyNodeVisitor)1 HtmlAttributeNode (com.google.template.soy.soytree.HtmlAttributeNode)1 HtmlCloseTagNode (com.google.template.soy.soytree.HtmlCloseTagNode)1 StandaloneNode (com.google.template.soy.soytree.SoyNode.StandaloneNode)1