use of com.google.template.soy.exprtree.ExprRootNode in project closure-templates by google.
the class RenderVisitor method visitCallDelegateNode.
@Override
protected void visitCallDelegateNode(CallDelegateNode node) {
ExprRootNode variantExpr = node.getDelCalleeVariantExpr();
String variant;
if (variantExpr == null) {
variant = "";
} else {
try {
SoyValue variantData = eval(variantExpr, node);
if (variantData instanceof IntegerData) {
// An integer constant is being used as variant. Use the value string representation as
// variant.
variant = String.valueOf(variantData.longValue());
} else {
// Variant is either a StringData or a SanitizedContent. Use the value as a string. If
// the value is not a string, and exception will be thrown.
variant = variantData.stringValue();
}
} catch (SoyDataException e) {
throw RenderException.createWithSource(String.format("Variant expression \"%s\" doesn't evaluate to a valid type " + "(Only string and integer are supported).", variantExpr.toSourceString()), e, node);
}
}
DelTemplateKey delegateKey = DelTemplateKey.create(node.getDelCalleeName(), variant);
TemplateDelegateNode callee;
try {
callee = templateRegistry.selectDelTemplate(delegateKey, activeDelPackageSelector);
} catch (IllegalArgumentException e) {
throw RenderException.createWithSource(e.getMessage(), e, node);
}
if (callee != null) {
visitCallNodeHelper(node, callee);
} else if (node.allowEmptyDefault()) {
// no active delegate implementation, so the call output is empty string
return;
} else {
throw RenderException.createWithSource("Found no active impl for delegate call to \"" + node.getDelCalleeName() + (variant.isEmpty() ? "" : ":" + variant) + "\" (and delcall does not set allowemptydefault=\"true\").", node);
}
}
use of com.google.template.soy.exprtree.ExprRootNode in project closure-templates by google.
the class RenderVisitor method visitVeLogNode.
@Override
protected void visitVeLogNode(VeLogNode node) {
ExprRootNode logonlyExpression = node.getLogonlyExpression();
if (logonlyExpression != null) {
if (eval(logonlyExpression, node).booleanValue()) {
throw RenderException.createWithSource("Cannot set logonly=\"true\" unless there is a logger configured, but tofu doesn't " + "support loggers", node);
}
}
visitChildren(node);
}
use of com.google.template.soy.exprtree.ExprRootNode in project closure-templates by google.
the class RenderVisitorAssistantForMsgs method visitMsgSelectNode.
@Override
protected void visitMsgSelectNode(MsgSelectNode node) {
ExprRootNode selectExpr = node.getExpr();
String selectValue;
try {
selectValue = master.evalForUseByAssistants(selectExpr, node).stringValue();
} catch (SoyDataException e) {
throw RenderException.createWithSource(String.format("Select expression \"%s\" doesn't evaluate to string.", selectExpr.toSourceString()), e, node);
}
// Check each case.
for (CaseOrDefaultNode child : node.getChildren()) {
if (child instanceof MsgSelectDefaultNode) {
// This means it didn't match any other case.
visitChildren(child);
} else {
if (((MsgSelectCaseNode) child).getCaseValue().equals(selectValue)) {
visitChildren(child);
return;
}
}
}
}
use of com.google.template.soy.exprtree.ExprRootNode in project closure-templates by google.
the class RenderVisitorAssistantForMsgs method visitMsgPluralNode.
@Override
protected void visitMsgPluralNode(MsgPluralNode node) {
ExprRootNode pluralExpr = node.getExpr();
double pluralValue;
try {
pluralValue = master.evalForUseByAssistants(pluralExpr, node).numberValue();
} catch (SoyDataException e) {
throw RenderException.createWithSource(String.format("Plural expression \"%s\" doesn't evaluate to number.", pluralExpr.toSourceString()), e, node);
}
// Check each case.
for (CaseOrDefaultNode child : node.getChildren()) {
if (child instanceof MsgPluralDefaultNode) {
// This means it didn't match any other case.
visitChildren(child);
break;
} else {
if (((MsgPluralCaseNode) child).getCaseNumber() == pluralValue) {
visitChildren(child);
break;
}
}
}
}
use of com.google.template.soy.exprtree.ExprRootNode in project closure-templates by google.
the class TemplateDelegateNodeBuilder method setCmdTextInfo.
/**
* Alternative to {@code setCmdText()} that sets command text info directly as opposed to having
* it parsed from the command text string. The cmdText field will be set to a canonical string
* generated from the given info.
*
* @param delTemplateName The delegate template name.
* @param delTemplateVariant The delegate template variant.
* @param delPriority The delegate priority.
* @param autoescapeMode The mode of autoescaping for this template.
* @param contentKind Strict mode context. Nonnull iff autoescapeMode is strict.
* @param requiredCssNamespaces CSS namespaces required to render the template.
* @return This builder.
*/
public TemplateDelegateNodeBuilder setCmdTextInfo(String delTemplateName, String delTemplateVariant, Priority delPriority, AutoescapeMode autoescapeMode, SanitizedContentKind contentKind, ImmutableList<String> requiredCssNamespaces) {
Preconditions.checkState(this.sourceLocation != null);
Preconditions.checkState(this.cmdText == null);
Preconditions.checkArgument(BaseUtils.isDottedIdentifier(delTemplateName));
Preconditions.checkArgument(delTemplateVariant.length() == 0 || BaseUtils.isIdentifier(delTemplateVariant));
Preconditions.checkArgument((contentKind != null) == (autoescapeMode == AutoescapeMode.STRICT));
this.delTemplateName = delTemplateName;
this.delTemplateVariantExpr = new ExprRootNode(new StringNode(delTemplateVariant, QuoteStyle.SINGLE, this.sourceLocation));
this.delPriority = delPriority;
setAutoescapeInfo(autoescapeMode, contentKind, sourceLocation);
setRequiredCssNamespaces(requiredCssNamespaces);
String cmdText = delTemplateName + ((delTemplateVariant.length() == 0) ? "" : " variant=\"" + delTemplateVariant + "\"") + " autoescape=\"" + autoescapeMode.getAttributeValue() + "\"";
if (contentKind != null) {
cmdText += " kind=\"" + contentKind.asAttributeValue() + '"';
}
if (!requiredCssNamespaces.isEmpty()) {
cmdText += " requirecss=\"" + Joiner.on(", ").join(requiredCssNamespaces) + "\"";
}
this.cmdText = cmdText;
genInternalTemplateNameHelper();
return this;
}
Aggregations