diff options
author | Les Hill <leshill@gmail.com> | 2013-02-25 23:03:16 -0800 |
---|---|---|
committer | Les Hill <leshill@gmail.com> | 2013-03-19 21:41:36 -0700 |
commit | 53de75927ce3ff622901ae00b39c5e677fb6ba25 (patch) | |
tree | c18c6a7a5203313879822a18779e65edf6dc7b5e /lib/handlebars/compiler/compiler.js | |
parent | bcc15ea5e78a3368344204c805e4666681e7253e (diff) | |
download | handlebars.js-53de75927ce3ff622901ae00b39c5e677fb6ba25.zip handlebars.js-53de75927ce3ff622901ae00b39c5e677fb6ba25.tar.gz handlebars.js-53de75927ce3ff622901ae00b39c5e677fb6ba25.tar.bz2 |
Add contexts for string mode hash values
Allows for evaluating hash parameters such as ../city in string mode.
Diffstat (limited to 'lib/handlebars/compiler/compiler.js')
-rw-r--r-- | lib/handlebars/compiler/compiler.js | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/handlebars/compiler/compiler.js b/lib/handlebars/compiler/compiler.js index 196ba18..cd902fd 100644 --- a/lib/handlebars/compiler/compiler.js +++ b/lib/handlebars/compiler/compiler.js @@ -189,6 +189,10 @@ Compiler.prototype = { val = pair[1]; if (this.options.stringParams) { + if(val.depth) { + this.addDepth(val.depth); + } + this.opcode('getContext', val.depth || 0); this.opcode('pushStringParam', val.stringModeValue, val.type); } else { this.accept(val); @@ -773,16 +777,18 @@ JavaScriptCompiler.prototype = { if (this.options.stringParams) { this.register('hashTypes', '{}'); + this.register('hashContexts', '{}'); } }, pushHash: function() { - this.hash = {values: [], types: []}; + this.hash = {values: [], types: [], contexts: []}; }, popHash: function() { var hash = this.hash; this.hash = undefined; if (this.options.stringParams) { + this.register('hashContexts', '{' + hash.contexts.join(',') + '}'); this.register('hashTypes', '{' + hash.types.join(',') + '}'); } this.push('{\n ' + hash.values.join(',\n ') + '\n }'); @@ -925,14 +931,18 @@ JavaScriptCompiler.prototype = { // and pushes the hash back onto the stack. assignToHash: function(key) { var value = this.popStack(), + context, type; if (this.options.stringParams) { type = this.popStack(); - this.popStack(); + context = this.popStack(); } var hash = this.hash; + if (context) { + hash.contexts.push("'" + key + "': " + context); + } if (type) { hash.types.push("'" + key + "': " + type); } @@ -1186,6 +1196,7 @@ JavaScriptCompiler.prototype = { if (this.options.stringParams) { options.push("contexts:[" + contexts.join(",") + "]"); options.push("types:[" + types.join(",") + "]"); + options.push("hashContexts:hashContexts"); options.push("hashTypes:hashTypes"); } |