diff --git a/mustache.js b/mustache.js index 31566ce..24899c1 100644 --- a/mustache.js +++ b/mustache.js @@ -275,6 +275,10 @@ var Mustache = function() { value = this.context[name]; } + if(name.match(/([a-z_]+)\.?/ig)){ + value = this.walk_context(name, context); + } + if(typeof value === "function") { return value.apply(context); } @@ -285,6 +289,20 @@ var Mustache = function() { return ""; }, + walk_context: function(name, context){ + var path = name.split('.') + var value_context = context; + var value = context[path.shift()]; + while(value != undefined && path.length > 0){ + value_context = value + value = value[path.shift()]; + } + if(typeof value === "function") { + return value.apply(value_context); + } + return value; + }, + // Utility methods /* includes tag */ @@ -393,4 +411,4 @@ var Mustache = function() { } } }); -}(); +}(); \ No newline at end of file