use of com.squarespace.template.Context in project template-compiler by Squarespace.
the class InternationalFormattersTest method format.
private String format(CLDR.Locale locale, Formatter impl, Arguments args, String json) throws CodeException {
Context ctx = new Context(JsonUtils.decode(json));
ctx.cldrLocale(locale);
impl.validateArgs(args);
Variables variables = new Variables("@", ctx.node());
impl.apply(ctx, args, variables);
return variables.first().node().asText();
}
use of com.squarespace.template.Context in project template-compiler by Squarespace.
the class LegacyMoneyFormatFactoryTest method cldr.
private String cldr(CLDR.Locale locale, String currency, String number, boolean narrow) throws CodeException {
Arguments args = mk.args(narrow ? " symbol:narrow" : " ");
CLDR_MONEY.validateArgs(args);
Context ctx = new Context(moneyJson(number, currency));
ctx.cldrLocale(locale);
Variables variables = new Variables("@", ctx.node());
CLDR_MONEY.apply(ctx, args, variables);
return variables.first().node().asText();
}
use of com.squarespace.template.Context in project template-compiler by Squarespace.
the class MoneyFormatterTest method executeLocale.
private String executeLocale(String template, String json, CLDR.Locale locale) throws CodeException {
Compiler compiler = compiler();
Context ctx = compiler.newExecutor().json(json).template(template).cldrLocale(locale).execute();
return ctx.buffer().toString();
}
use of com.squarespace.template.Context in project template-compiler by Squarespace.
the class UnitFormattersTest method format.
private static String format(CLDR.Locale locale, Formatter formatter, Arguments args, String json) throws CodeException {
Context ctx = new Context(JsonUtils.decode(json));
ctx.cldrLocale(locale);
formatter.validateArgs(args);
Variables variables = new Variables("@", ctx.node());
formatter.apply(ctx, args, variables);
return variables.first().node().asText();
}
use of com.squarespace.template.Context in project template-compiler by Squarespace.
the class UnitsMetricPredicateTest method run.
private void run(CLDR.Locale locale, String template, String expected) throws CodeException {
Context ctx = new Context(new TextNode(""));
ctx.cldrLocale(locale);
CodeMachine sink = machine();
tokenizer(template, sink).consume();
ctx.execute(sink.getCode());
Assert.assertEquals(ctx.buffer().toString(), expected);
}
Aggregations