diff --git a/mustache.js b/mustache.js index e5f80a3..04e9b00 100644 --- a/mustache.js +++ b/mustache.js @@ -319,6 +319,7 @@ var Mustache = (function(undefined) { } var value; + if (is_kinda_truthy(context[name])) { value = context[name]; } @@ -364,9 +365,32 @@ var Mustache = (function(undefined) { escape = prefix = true; } - var variable = get_variable_name(state, token, prefix, postfix); + var variable = get_variable_name(state, token, prefix, postfix), + implicit_iterator = (state.pragmas['IMPLICIT-ITERATOR'] || {iterator: '.'}).iterator; + state.send_code_func((function(variable, escape) { return function(context, send_func) { - var value = find_in_stack(variable, context); + var variable_components, + i, n, value; + + if ( variable === implicit_iterator ) { // special case for implicit iterator (usually '.') + value = {}; value[implicit_iterator] = context[context.length-1]; + value = find(variable, value); + } else { + variable_components = variable.split('.'); + i = 1; + n = variable_components.length; + + value = find_in_stack(variable_components[0], context); + while (value && i