use of com.squarespace.template.Frame in project template-compiler by Squarespace.
the class MessageFormatter method messageArgs.
private static MessageArgs messageArgs(Arguments args, Context ctx) {
MessageArgs res = new MessageArgs();
int count = args.count();
for (int i = 0; i < count; i++) {
String raw = args.get(i);
String name = null;
// Either ':' or '=' can delimit key/value arguments
int index = delimiter(raw);
if (index != -1) {
// Map named argument
name = raw.substring(0, index);
raw = raw.substring(index + 1);
}
Object[] ref = splitVariable(raw);
// Since the message string is the node on the current stack frame, the
// variable reference '@' will point to it, instead of the parent scope.
// Skip the current frame so we avoid trying to resolve variables against
// the message string.
Frame parent = ctx.frame().parent();
JsonNode value = ctx.resolve(ref, parent == null ? ctx.frame() : parent);
if (name != null) {
res.add(name, value);
}
// Keyword arguments are also positional
res.add(value);
}
return res;
}
use of com.squarespace.template.Frame in project template-compiler by Squarespace.
the class MsgArg method resolve.
@Override
public boolean resolve() {
if (this.node == null) {
// Since the message string is the node on the current stack frame, the
// variable reference '@' will point to it, instead of the parent scope.
// Skip the current frame so we avoid trying to resolve variables against
// the message string.
Frame parent = ctx.frame().parent();
this.node = ctx.resolve(name, parent == null ? ctx.frame() : parent);
// Peek to see if this argument is a Money
JsonNode decimal = node.path("decimalValue");
if (!decimal.isMissingNode()) {
this.node = decimal;
this.currencyNode = node.path("currencyCode");
}
}
return true;
}
Aggregations