Added strictSections configuration.
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 commit is contained in:
@@ -207,14 +207,11 @@ public class Template
|
||||
|
||||
/**
|
||||
* Returns the value of the specified variable, noting that it is intended to be used as the
|
||||
* contents for a segment. Presently this does not do anything special, but eventually this
|
||||
* will be the means by which we enact configured behavior for sections that reference null or
|
||||
* missing variables. Right now, all such variables result in a length 0 section.
|
||||
* contents for a section.
|
||||
*/
|
||||
protected Object getSectionValue (Context ctx, String name, int line) {
|
||||
// TODO: configurable behavior on missing values
|
||||
Object value = getValue(ctx, name, line, _compiler.missingIsNull);
|
||||
// TODO: configurable behavior on null values
|
||||
Object value = getValue(ctx, name, line, !_compiler.strictSections);
|
||||
// TODO: configurable behavior on null values?
|
||||
return (value == null) ? Collections.emptyList() : value;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user