Search in sources :

Example 6 with PyFunctionExprBuilder

use of com.google.template.soy.pysrc.restricted.PyFunctionExprBuilder in project closure-templates by google.

the class AugmentMapFunction method computeForPySrc.

@Override
public PyExpr computeForPySrc(List<PyExpr> args) {
    PyFunctionExprBuilder fnBuilder = new PyFunctionExprBuilder("dict");
    fnBuilder.addArg(args.get(0)).setUnpackedKwargs(args.get(1));
    return fnBuilder.asPyExpr();
}
Also used : PyFunctionExprBuilder(com.google.template.soy.pysrc.restricted.PyFunctionExprBuilder)

Example 7 with PyFunctionExprBuilder

use of com.google.template.soy.pysrc.restricted.PyFunctionExprBuilder in project closure-templates by google.

the class TruncateDirective method applyForPySrc.

@Override
public PyExpr applyForPySrc(PyExpr value, List<PyExpr> args) {
    // Truncation always wants a string, so to potentially save an unnecessary conversion, we do
    // optional coercing at compile time.
    PyExpr input = value.toPyString();
    PyExpr maxLen = args.get(0);
    PyExpr doAddEllipsis = (args.size() == 2) ? args.get(1) : new PyExpr("True", Integer.MAX_VALUE);
    PyFunctionExprBuilder fnBuilder = new PyFunctionExprBuilder("directives.truncate");
    fnBuilder.addArg(input).addArg(maxLen).addArg(doAddEllipsis);
    return fnBuilder.asPyStringExpr();
}
Also used : PyExpr(com.google.template.soy.pysrc.restricted.PyExpr) PyFunctionExprBuilder(com.google.template.soy.pysrc.restricted.PyFunctionExprBuilder)

Aggregations

PyFunctionExprBuilder (com.google.template.soy.pysrc.restricted.PyFunctionExprBuilder)7 PyExpr (com.google.template.soy.pysrc.restricted.PyExpr)6 AbstractParentExprNode (com.google.template.soy.exprtree.AbstractParentExprNode)1 ExprNode (com.google.template.soy.exprtree.ExprNode)1 ExprRootNode (com.google.template.soy.exprtree.ExprRootNode)1 PyStringExpr (com.google.template.soy.pysrc.restricted.PyStringExpr)1 LocaleString (com.google.template.soy.shared.restricted.ApiCallScopeBindingAnnotations.LocaleString)1 LinkedHashMap (java.util.LinkedHashMap)1