Search in sources :

Example 1 with Environment

use of com.google.template.soy.sharedpasses.render.Environment in project closure-templates by google.

the class PreevalVisitorTest method preeval.

// -----------------------------------------------------------------------------------------------
// Helpers.
/**
 * Evaluates the given expression and returns the result.
 *
 * @param expression The expression to preevaluate.
 * @return The expression result.
 */
private static SoyValue preeval(String expression, String... params) {
    String header = "";
    for (String param : params) {
        header += "{@param " + param + " : ?}\n";
    }
    PrintNode code = (PrintNode) SoyFileSetParserBuilder.forTemplateContents(header + "{" + expression + "}").parse().fileSet().getChild(0).getChild(0).getChild(0);
    ExprRootNode expr = code.getExpr();
    Environment env = TestingEnvironment.createForTest(SoyValueConverterUtility.newDict("boo", 8), ImmutableMap.<String, SoyValueProvider>of());
    return new PreevalVisitor(env).exec(expr);
}
Also used : TestingEnvironment(com.google.template.soy.sharedpasses.render.TestingEnvironment) Environment(com.google.template.soy.sharedpasses.render.Environment) PrintNode(com.google.template.soy.soytree.PrintNode) ExprRootNode(com.google.template.soy.exprtree.ExprRootNode)

Aggregations

ExprRootNode (com.google.template.soy.exprtree.ExprRootNode)1 Environment (com.google.template.soy.sharedpasses.render.Environment)1 TestingEnvironment (com.google.template.soy.sharedpasses.render.TestingEnvironment)1 PrintNode (com.google.template.soy.soytree.PrintNode)1