Search in sources :

Example 1 with CodeBuilder

use of com.squarespace.template.CodeBuilder in project template-compiler by Squarespace.

the class CoreFormattersTest method testApplyPartial.

@Test
public void testApplyPartial() throws CodeException {
    String partials = "{\"block.item\": \"this {@} value\"}";
    String input = "{\"foo\": 123}";
    CodeMaker mk = maker();
    CodeBuilder cb = builder().text("hi ");
    Arguments args = mk.args(" block.item");
    APPLY.validateArgs(args);
    cb.var("foo", mk.fmt(APPLY, args));
    Instruction root = cb.text("!").eof().build();
    Context ctx = new Context(JsonUtils.decode(input));
    ctx.setCompiler(compiler());
    ctx.setPartials(JsonUtils.decode(partials));
    ctx.execute(root);
    assertContext(ctx, "hi this 123 value!");
}
Also used : Context(com.squarespace.template.Context) Arguments(com.squarespace.template.Arguments) CodeMaker(com.squarespace.template.CodeMaker) Instruction(com.squarespace.template.Instruction) CodeBuilder(com.squarespace.template.CodeBuilder) Test(org.testng.annotations.Test)

Aggregations

Arguments (com.squarespace.template.Arguments)1 CodeBuilder (com.squarespace.template.CodeBuilder)1 CodeMaker (com.squarespace.template.CodeMaker)1 Context (com.squarespace.template.Context)1 Instruction (com.squarespace.template.Instruction)1 Test (org.testng.annotations.Test)1