use of com.squarespace.template.CodeException in project template-compiler by Squarespace.
the class DecimalFormatterTest method run.
private void run(CLDR.Locale locale, String number, String args, String expected) {
try {
String json = new DecimalNode(new BigDecimal(number)).toString();
String actual = format(locale, mk.args(args), json);
Assert.assertEquals(actual, expected);
} catch (CodeException e) {
fail("formatter raised an error", e);
}
}
use of com.squarespace.template.CodeException in project template-compiler by Squarespace.
the class DecimalFormatterTest method run.
private void run(String locale, String number, String args, String expected) {
try {
String json = new DecimalNode(new BigDecimal(number)).toString();
String actual = format(locale, mk.args(args), json);
Assert.assertEquals(actual, expected);
} catch (CodeException e) {
fail("formatter raised an error", e);
}
}
use of com.squarespace.template.CodeException in project template-compiler by Squarespace.
the class TemplateC method execute.
protected void execute(String[] args) {
String version = buildVersion();
ArgumentParser parser = ArgumentParsers.newArgumentParser(PROGRAM_NAME).description("Compile template files").version(version);
parser.addArgument("--dump-plugins").action(Arguments.storeTrue()).help("Dump the list of registered plugins");
parser.addArgument("--version", "-v").action(Arguments.version()).help("Show the version and exit");
parser.addArgument("--stats", "-s").action(Arguments.storeTrue()).help("Dump stats for the template");
parser.addArgument("--tree", "-t").action(Arguments.storeTrue()).help("Dump the syntax tree for the template");
parser.addArgument("--json", "-j").type(String.class).help("JSON tree");
parser.addArgument("--partials", "-p").type(String.class).help("JSON partials");
parser.addArgument("--locale", "-l").type(String.class).help("Language tag for a locale");
parser.addArgument("--preprocess", "-P").action(Arguments.storeTrue()).help("Preprocess the template");
parser.addArgument("template").type(String.class).nargs("?").help("Template source");
int exitCode = 1;
try {
Namespace res = parser.parseArgs(args);
if (res.getBoolean("dump_plugins")) {
dumpPlugins();
System.exit(0);
}
if (res.getString("template") == null) {
parser.printUsage();
System.err.println("error: too few arguments");
System.exit(exitCode);
}
boolean preprocess = res.getBoolean("preprocess");
if (res.getBoolean("stats")) {
exitCode = stats(res.getString("template"), preprocess);
} else if (res.getBoolean("tree")) {
exitCode = tree(res.getString("template"), preprocess);
} else {
exitCode = compile(res.getString("template"), res.getString("json"), res.getString("partials"), res.getString("locale"), preprocess);
}
} catch (CodeException | IOException e) {
System.err.println(e.getMessage());
} catch (ArgumentParserException e) {
parser.handleError(e);
System.exit(1);
} finally {
System.exit(exitCode);
}
}
Aggregations