Search in sources :

Example 1 with UndefinedData

use of com.google.template.soy.data.restricted.UndefinedData in project closure-templates by google.

the class EvalVisitor method visitProtoInitNode.

@Override
protected SoyValue visitProtoInitNode(ProtoInitNode node) {
    // The downcast is safe because if it was anything else, compilation would have already failed.
    SoyProtoType soyProto = (SoyProtoType) node.getType();
    ImmutableList<String> paramNames = node.getParamNames();
    SoyProtoValueImpl.Builder builder = new SoyProtoValueImpl.Builder(soyProto.getDescriptor());
    for (int i = 0; i < node.numChildren(); i++) {
        SoyValue visit = visit(node.getChild(i));
        // null means don't assign
        if (visit instanceof NullData || visit instanceof UndefinedData) {
            continue;
        }
        builder.setField(paramNames.get(i), visit);
    }
    return builder.build();
}
Also used : NullData(com.google.template.soy.data.restricted.NullData) UndefinedData(com.google.template.soy.data.restricted.UndefinedData) SoyValue(com.google.template.soy.data.SoyValue) SoyProtoType(com.google.template.soy.types.SoyProtoType) SoyProtoValueImpl(com.google.template.soy.data.SoyProtoValueImpl)

Example 2 with UndefinedData

use of com.google.template.soy.data.restricted.UndefinedData 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);
}
Also used : PrintDirectiveNode(com.google.template.soy.soytree.PrintDirectiveNode) UndefinedData(com.google.template.soy.data.restricted.UndefinedData) SoyValue(com.google.template.soy.data.SoyValue) ExprRootNode(com.google.template.soy.exprtree.ExprRootNode)

Aggregations

SoyValue (com.google.template.soy.data.SoyValue)2 UndefinedData (com.google.template.soy.data.restricted.UndefinedData)2 SoyProtoValueImpl (com.google.template.soy.data.SoyProtoValueImpl)1 NullData (com.google.template.soy.data.restricted.NullData)1 ExprRootNode (com.google.template.soy.exprtree.ExprRootNode)1 PrintDirectiveNode (com.google.template.soy.soytree.PrintDirectiveNode)1 SoyProtoType (com.google.template.soy.types.SoyProtoType)1