use of com.squarespace.template.Context in project template-compiler by Squarespace.
the class ContentPredicatesTest method testSameDay.
@Test
public void testSameDay() throws CodeException {
long date1 = KnownDates.NOV_15_2013_123030_UTC - (3600L * 1000);
String json = getDateTestJson(date1, "America/New_York");
ObjectNode node = (ObjectNode) JsonUtils.decode(json);
ObjectNode dates = JsonUtils.createObjectNode();
dates.put("startDate", date1);
dates.put("endDate", KnownDates.NOV_15_2013_123030_UTC);
node.set("dates", dates);
String[] key = new String[] { "dates" };
Context ctx = new Context(node);
ctx.pushSection(key);
assertTrue(ContentPredicates.SAME_DAY, ctx);
// 2 days prior, shouldn't match
dates.put("endDate", KnownDates.NOV_15_2013_123030_UTC - (86400L * 1000 * 2));
ctx = new Context(node);
ctx.pushSection(key);
assertFalse(ContentPredicates.SAME_DAY, ctx);
}
use of com.squarespace.template.Context in project template-compiler by Squarespace.
the class LegacyMoneyFormatFactoryTest method cldr.
private String cldr(String tag, String currency, String number, boolean narrow) throws CodeException {
Arguments args = mk.args(narrow ? " symbol:narrow" : " ");
CLDR_MONEY.validateArgs(args);
Locale locale = Locale.forLanguageTag(tag);
Context ctx = new Context(moneyJson(number, currency), new StringBuilder(), 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 MoneyFormatterLegacyTest 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));
MONEY.validateArgs(args);
Variables variables = new Variables("@", ctx.node());
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 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));
MONEY.validateArgs(args);
Variables variables = new Variables("@", ctx.node());
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, String locale) throws CodeException {
Compiler compiler = compiler();
Context ctx = compiler.newExecutor().json(json).template(template).locale(Locale.forLanguageTag(locale)).execute();
return ctx.buffer().toString();
}
Aggregations