Search in sources :

Example 46 with Context

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();
}
Also used : Context(com.squarespace.template.Context) Variables(com.squarespace.template.Variables)

Example 47 with Context

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();
}
Also used : Context(com.squarespace.template.Context) Variables(com.squarespace.template.Variables) Arguments(com.squarespace.template.Arguments)

Example 48 with Context

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();
}
Also used : Context(com.squarespace.template.Context) Compiler(com.squarespace.template.Compiler)

Example 49 with Context

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();
}
Also used : Context(com.squarespace.template.Context) Variables(com.squarespace.template.Variables)

Example 50 with Context

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);
}
Also used : Context(com.squarespace.template.Context) CodeMachine(com.squarespace.template.CodeMachine) TextNode(com.fasterxml.jackson.databind.node.TextNode)

Aggregations

Context (com.squarespace.template.Context)73 Test (org.testng.annotations.Test)55 DoubleNode (com.fasterxml.jackson.databind.node.DoubleNode)21 Instruction (com.squarespace.template.Instruction)14 Variables (com.squarespace.template.Variables)11 TextNode (com.fasterxml.jackson.databind.node.TextNode)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)6 Arguments (com.squarespace.template.Arguments)5 CodeMaker (com.squarespace.template.CodeMaker)4 Compiler (com.squarespace.template.Compiler)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 CompiledTemplate (com.squarespace.template.CompiledTemplate)2 CodeBuilder (com.squarespace.template.CodeBuilder)1 CodeExecuteException (com.squarespace.template.CodeExecuteException)1 CodeMachine (com.squarespace.template.CodeMachine)1 CodeSyntaxException (com.squarespace.template.CodeSyntaxException)1 ErrorInfo (com.squarespace.template.ErrorInfo)1 Locale (java.util.Locale)1