use of com.google.template.soy.soytree.PrintDirectiveNode in project closure-templates by google.
the class PerformDeprecatedNonContextualAutoescapeVisitor method visitPrintNode.
@Override
protected void visitPrintNode(PrintNode node) {
if (autoescapeMode != AutoescapeMode.NONCONTEXTUAL) {
// that this pass is never used without first running the contextual autoescaper.
if (node.getChildren().isEmpty()) {
throw new IllegalStateException(String.format("Internal error: A contextual or strict template has a print node that was never " + "assigned any escape directives: %s at %s", node.toSourceString(), node.getSourceLocation()));
}
return;
}
// Traverse the list to (a) record whether we saw any directive that cancels autoescape
// (including 'noAutoescape' of course) and (b) remove 'noAutoescape' directives.
boolean shouldCancelAutoescape = false;
for (PrintDirectiveNode directiveNode : ImmutableList.copyOf(node.getChildren())) {
SoyPrintDirective directive = directiveNode.getPrintDirective();
if (directive != null && directive.shouldCancelAutoescape()) {
shouldCancelAutoescape = true;
break;
}
}
// ideally should migrate off of deprecated-noncontextual autoescape.
if (autoescapeMode == AutoescapeMode.NONCONTEXTUAL && !shouldCancelAutoescape) {
PrintDirectiveNode newEscapeHtmlDirectiveNode = new PrintDirectiveNode(nodeIdGen.genId(), node.getSourceLocation(), ImmutableList.<ExprNode>of(), new EscapeHtmlDirective(), /* isSynthetic= */
true);
node.addChild(0, newEscapeHtmlDirectiveNode);
}
}
use of com.google.template.soy.soytree.PrintDirectiveNode in project closure-templates by google.
the class RenderVisitor method visitPrintNode.
@Override
protected void visitPrintNode(PrintNode node) {
SoyValue result = eval(node.getExpr(), node);
if (result instanceof UndefinedData) {
throw RenderException.createWithSource("In 'print' tag, expression \"" + node.getExpr().toSourceString() + "\" evaluates to undefined.", node);
}
// Process directives.
for (PrintDirectiveNode directiveNode : node.getChildren()) {
// Evaluate directive args.
List<ExprRootNode> argsExprs = directiveNode.getArgs();
List<SoyValue> argsSoyDatas = Lists.newArrayListWithCapacity(argsExprs.size());
for (ExprRootNode argExpr : argsExprs) {
argsSoyDatas.add(eval(argExpr, directiveNode));
}
// Apply directive.
result = applyDirective(directiveNode.getPrintDirective(), result, argsSoyDatas, node);
}
append(currOutputBuf, result, node);
}
Aggregations