(This is the continuation of an offline conversation, but posting it
here since it includes some generally relevant information.)
Formatters are functions from JSON nodes -> JSON nodes. Strings are
special cases of JSON nodes. In a {value|formatter1|formatter2}
chain, the last thing should be a string.
Predicates are functions from JSON nodes -> booleans. It was pointed
out that if you define *truth* on JSON nodes, which we've already
done, then formatters can serve as predicates.
But it doesn't work, because in the "false" case you may still need
substitutions:
{.section group|plural?}
There are {num} people in group {name}.
{.or}
There is one person in group {name}.
{.end}
So the plural? predicate can't just return "null", since we still need {name}.
Also, predicates and formatters do different things, so we shouldn't
make them the same concept. Formatters are concerned with
substitution of values, and apply only to substitutions. Predicates
are concerned with *whether* to show a section. You can combine the
two on the same section (they are *orthogonal*):
{.section group|plural?}
{@|fancy-formatter-for-plural-groups}
{.or}
There is one person in group {name}. {# No fancy formatter}
{.end}
Or use a totally different file for plurals:
{.section group|plural?}
{@|template-file plural-group.jsont} {# the "include" feature}
{.or}
There is one person in group {name}.
{.end}
Andy
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "JSON
Template" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/json-template?hl=en
-~----------~----~----~----~------~----~------~--~---