use of com.squarespace.template.Instruction in project template-compiler by Squarespace.
the class CoreFormattersTest method testApplyPartialErrorSyntax.
@Test
public void testApplyPartialErrorSyntax() throws CodeException {
String template = "{@|apply block}";
String input = "{}";
String partials = "{\"block\": \"{.section foo}{@}\"}";
Instruction inst = compiler().compile(template).code();
Context ctx = compiler().newExecutor().json(input).code(inst).partialsMap(partials).safeExecution(true).execute();
assertContext(ctx, "");
assertEquals(ctx.getErrors().size(), 1);
assertEquals(ctx.getErrors().get(0).getType(), COMPILE_PARTIAL_SYNTAX);
}
use of com.squarespace.template.Instruction in project template-compiler by Squarespace.
the class CoreFormattersTest method testApplyPartialPrivate.
@Test
public void testApplyPartialPrivate() throws CodeException {
// The "private" argument hides the entire parent context from the partial
String template = "{child|apply block private}{child|apply block}";
String partials = "{\"block\": \"hello {name}\"}";
String input = "{\"name\": \"bob\", \"child\": {}}";
Instruction inst = compiler().compile(template).code();
Context ctx = compiler().newExecutor().json(input).code(inst).partialsMap(partials).safeExecution(true).execute();
assertContext(ctx, "hello hello bob");
}
use of com.squarespace.template.Instruction in project template-compiler by Squarespace.
the class CoreFormattersTest method testApplyPartialNested.
@Test
public void testApplyPartialNested() throws CodeException {
String template = "{@|apply one}";
String partials = "{\"one\": \"1{@|apply two}\", \"two\": \"2{@|apply three}\", " + "\"three\": \"3{@|apply four}\", \"four\": \"4\"}";
String input = "{}";
Instruction inst = compiler().compile(template).code();
Context ctx = compiler().newExecutor().json(input).code(inst).partialsMap(partials).safeExecution(true).execute();
assertContext(ctx, "1234");
}
use of com.squarespace.template.Instruction in project template-compiler by Squarespace.
the class CoreFormattersTest method formatDate.
private String formatDate(String format, long timestamp, String tzId, Locale locale) throws CodeException {
String template = "{time|date " + format + "}";
String json = getDateTestJson(timestamp, tzId);
Instruction code = compiler().compile(template).code();
Context ctx = compiler().newExecutor().code(code).json(json).locale(locale).execute();
return eval(ctx);
}
Aggregations