use of com.squarespace.template.Context 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.Context 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.Context 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);
}
use of com.squarespace.template.Context in project template-compiler by Squarespace.
the class CoreFormattersTest method testDateNoTimeZone.
@Test
public void testDateNoTimeZone() throws CodeException {
Context ctx = compiler().newExecutor().template("{@|date %Y}").json("167200000").execute();
assertEquals(ctx.buffer().toString(), "1970");
}
use of com.squarespace.template.Context in project template-compiler by Squarespace.
the class InternationalFormattersTest method format.
private String format(String locale, Formatter impl, Arguments args, String json) throws CodeException {
Context ctx = new Context(JsonUtils.decode(json), Locale.forLanguageTag(locale));
impl.validateArgs(args);
Variables variables = new Variables("@", ctx.node());
impl.apply(ctx, args, variables);
return variables.first().node().asText();
}
Aggregations