Section behavior used to be somewhat hackily determined from nullValue and
defaultValue, but it was messy. Now it has its own configuration and things are
more explicit.
Previously missing/null sections were treated as false, but if you set
nullValue to something, then missing sections became an error, but null
sections remained false. If you set defaultValue to something, missing sections
went back to being omitted. Kooky.
Now missing sections are omitted, unless you set strictSections to true, in
which case they become an error. nullValue and defaultValue have no impact on
section behavior.
There is no way to make null sections an error, but I don't see any demand for
that, so I'm going to leave that as a TODO.
Closes#60.
This allows one to have a map with keys like "foo.bar.baz" even when not in
standards mode. If a whole key is missing, then we attempt to decompose it and
look it up piecewise.
Closes#55.
That's what collectors are for. This also avoids the needless expense of doing
Integer.parseInt on every single key (the vast majority of which will not
actually be numbers), every single time we do a context lookup.
The groups with failing tests are currently commented out (everything except
interpolation). The main reason for failures are due to the requirement that
standalone lines that contain nothing but whitespace be stripped from the
output.
Solving need to distinguish context errors from environment errors.
The exception has fields for the offending key and line number. This
is a first step towards internationalization of messages.
If Compliler.nullValue contains a substring "{{name}}", then this substring
will be replaced with the name of variable.
For example, if nullValue="?{{name}}?" and variable is resolved to null,
then string "?foo?" will be used.
Kali/Bertrand convinced me that being consistent with other Mustache
implementations is more important than whatever wacky reasons I was harboring
for keeping compound variables different than singleton sections.
a pluggable component.
This allows scaling down to the GWT environment by hiding the reflection code
via GWT's super source mechanism.
And it allows scaling up to non-Java languages (like Scala) by allowing the
library client to extend the DefaultCollector and teach it about Scala
Iterators, Iterables and Maps.
I also just realized that GWT has no facilities for Reader and Writer, which is
going to complicate making things work in GWT even further. But for now, I'll
just leave things as is.
for use when variables resolve to null, but still wishes for exceptions to be
thrown when values are not resolvable (i.e. are typos). Pre-existing behavior
is preserved if one uses defaultValue() or does not change the default
configuration.
Nota bene: there are complexities, so be sure to read the documentation.
rather than "missingVariableValue" because the value is used any time a
variable resolves to null, not necessarily just when it is missing. If you
have a context like:
new Object() {
String foo = null;
}
and reference {{foo}} in your template, foo is not missing, per se, but the
default value will still be used for it.
Call missingVariableValue(value) on a Compiler object to get a new
version that will insert "value" for missing values (rather than
throwing an exception). Useful when you have templates you would
rather generated *something* instead of erroring or for when objects may
have null values themselves.
whether we're seeing {{.}} or not. Also reinstated treatment of ".foo" as a
compound key. I'm not 100% sure that makes more sense than treating ".foo" as a
simple key, but I'd rather change less behavior than more when making the {{.}}
fix.
not search parent contexts for name bindings, nor do we support compound keys.
Also added support for {{.}} which has the same semantics as {{this}}. I must
have missed this when reading the Mustache spec.
not closed properly and another tag follows it on the same line. Added support
for -first and -last special variables. Fixed problem with resolving outermost
component of a compound key in parent contexts.
template-local variable fetching cache that avoids reresolving the source of a
variable when it remains monomorphic (e.g. it's always a field of class
Foo.class or always a method named getFoo(), etc.).