Show the name of variable that is null or missing

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.
This commit is contained in:
pmenhart
2013-01-23 15:59:52 -05:00
parent 6e71dad5f2
commit 8b0d063ffd
3 changed files with 29 additions and 2 deletions
@@ -170,7 +170,16 @@ public class Template
// getValue will raise MustacheException if a variable cannot be resolved and missingIsNull
// is not configured; so we're safe to assume that any null that makes it up to this point
// can be converted to nullValue
return (value == null) ? _compiler.nullValue : value;
return (value == null) ? substituteNullValue(name) : value;
}
private String substituteNullValue(String name) {
String SUBST = "\\{\\{name\\}\\}"; // escaping needed for regex
String result = _compiler.nullValue;
if (result != null) {
result = result.replaceAll(SUBST, name);
}
return result;
}
protected Object getValueIn (Object data, String name, int line)