Search in sources :

Example 6 with Variables

use of com.squarespace.template.Variables 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 7 with Variables

use of com.squarespace.template.Variables 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 8 with Variables

use of com.squarespace.template.Variables 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 9 with Variables

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

the class DecimalFormatterTest method format.

private static String format(String locale, Arguments args, String json) throws CodeException {
    Context ctx = new Context(JsonUtils.decode(json));
    ctx.javaLocale(Locale.forLanguageTag(locale));
    DECIMAL.validateArgs(args);
    Variables variables = new Variables("@", ctx.node());
    DECIMAL.apply(ctx, args, variables);
    return variables.first().node().asText();
}
Also used : Context(com.squarespace.template.Context) Variables(com.squarespace.template.Variables)

Example 10 with Variables

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

the class LegacyMoneyFormatFactoryTest method legacy.

private String legacy(String locale, String currency, String number) throws CodeException {
    Arguments args = mk.args(" " + locale);
    LEGACY_MONEY.validateArgs(args);
    Context ctx = new Context(moneyJson(number, currency));
    Variables variables = new Variables("@", ctx.node());
    LEGACY_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)

Aggregations

Context (com.squarespace.template.Context)11 Variables (com.squarespace.template.Variables)11 Arguments (com.squarespace.template.Arguments)3 Locale (java.util.Locale)1