Search in sources :

Example 1 with DecimalFormatOptions

use of com.squarespace.cldrengine.api.DecimalFormatOptions in project template-compiler by Squarespace.

the class DecimalFormatter method apply.

@Override
public void apply(Context ctx, Arguments args, Variables variables) throws CodeExecuteException {
    Variable var = variables.first();
    Decimal number = GeneralUtils.nodeToDecimal(var.node());
    if (number == null) {
        var.setMissing();
        return;
    }
    CLDR cldr = ctx.cldr();
    DecimalFormatOptions opts = (DecimalFormatOptions) args.getOpaque();
    String result = cldr.Numbers.formatDecimal(number, opts);
    var.set(result);
}
Also used : Variable(com.squarespace.template.Variable) Decimal(com.squarespace.cldrengine.api.Decimal) CLDR(com.squarespace.cldrengine.CLDR) DecimalFormatOptions(com.squarespace.cldrengine.api.DecimalFormatOptions)

Example 2 with DecimalFormatOptions

use of com.squarespace.cldrengine.api.DecimalFormatOptions in project template-compiler by Squarespace.

the class DecimalFormatter method validateArgs.

@Override
public void validateArgs(Arguments args) throws ArgumentsException {
    DecimalFormatOptions opts = OptionParsers.decimal(args);
    args.setOpaque(opts);
}
Also used : DecimalFormatOptions(com.squarespace.cldrengine.api.DecimalFormatOptions)

Example 3 with DecimalFormatOptions

use of com.squarespace.cldrengine.api.DecimalFormatOptions in project template-compiler by Squarespace.

the class MessageFormats method decimal.

/**
 * Number / decimal message formatter.
 */
private String decimal(List<Object> args, List<String> options) {
    if (args.isEmpty()) {
        return "";
    }
    JsonNode node = (JsonNode) args.get(0);
    if (node == null) {
        return "";
    }
    Decimal value = this.converter.asDecimal(node);
    DecimalFormatOptions opts = OptionParsers.decimal(options);
    return cldr.Numbers.formatDecimal(value, opts);
}
Also used : Decimal(com.squarespace.cldrengine.api.Decimal) JsonNode(com.fasterxml.jackson.databind.JsonNode) DecimalFormatOptions(com.squarespace.cldrengine.api.DecimalFormatOptions)

Example 4 with DecimalFormatOptions

use of com.squarespace.cldrengine.api.DecimalFormatOptions in project template-compiler by Squarespace.

the class OptionParsers method decimal.

public static DecimalFormatOptions decimal(List<String> args) {
    DecimalFormatOptions options = new DecimalFormatOptions();
    parse(args, options, OptionParsers::decimalOption);
    return options;
}
Also used : DecimalFormatOptions(com.squarespace.cldrengine.api.DecimalFormatOptions)

Aggregations

DecimalFormatOptions (com.squarespace.cldrengine.api.DecimalFormatOptions)4 Decimal (com.squarespace.cldrengine.api.Decimal)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 CLDR (com.squarespace.cldrengine.CLDR)1 Variable (com.squarespace.template.Variable)1