diff options
author | kpdecker <kpdecker@gmail.com> | 2014-08-13 20:46:07 -0500 |
---|---|---|
committer | kpdecker <kpdecker@gmail.com> | 2014-08-13 20:46:42 -0500 |
commit | c98613b711a70a82a960c20c00d8d92d5eed1024 (patch) | |
tree | 364862d90bc601284d35f5c19e8fed1abad7e4f4 /spec | |
parent | 625b00e1dafccc8653bf4cb4dc3dac55f6b3b020 (diff) | |
download | handlebars.js-c98613b711a70a82a960c20c00d8d92d5eed1024.zip handlebars.js-c98613b711a70a82a960c20c00d8d92d5eed1024.tar.gz handlebars.js-c98613b711a70a82a960c20c00d8d92d5eed1024.tar.bz2 |
Implement recursive field lookup in compat mode
Provides the mustache behavior of recursive lookup without the use of depthed paths.
Note that this does incur a fairly dramatic performance penalty for depthed queries.
Diffstat (limited to 'spec')
-rw-r--r-- | spec/blocks.js | 21 | ||||
-rw-r--r-- | spec/env/common.js | 2 |
2 files changed, 22 insertions, 1 deletions
diff --git a/spec/blocks.js b/spec/blocks.js index c57a67e..a13cce2 100644 --- a/spec/blocks.js +++ b/spec/blocks.js @@ -94,4 +94,25 @@ describe('blocks', function() { 'No people\n'); }); }); + + describe('compat mode', function() { + it("block with deep recursive lookup lookup", function() { + var string = "{{#outer}}Goodbye {{#inner}}cruel {{omg}}{{/inner}}{{/outer}}"; + var hash = {omg: "OMG!", outer: [{ inner: [{ text: "goodbye" }] }] }; + + shouldCompileTo(string, [hash, undefined, undefined, true], "Goodbye cruel OMG!"); + }); + it("block with deep recursive pathed lookup", function() { + var string = "{{#outer}}Goodbye {{#inner}}cruel {{omg.yes}}{{/inner}}{{/outer}}"; + var hash = {omg: {yes: "OMG!"}, outer: [{ inner: [{ yes: 'no', text: "goodbye" }] }] }; + + shouldCompileTo(string, [hash, undefined, undefined, true], "Goodbye cruel OMG!"); + }); + it("block with missed recursive lookup", function() { + var string = "{{#outer}}Goodbye {{#inner}}cruel {{omg.yes}}{{/inner}}{{/outer}}"; + var hash = {omg: {no: "OMG!"}, outer: [{ inner: [{ yes: 'no', text: "goodbye" }] }] }; + + shouldCompileTo(string, [hash, undefined, undefined, true], "Goodbye cruel "); + }); + }); }); diff --git a/spec/env/common.js b/spec/env/common.js index 03eef93..a603fc0 100644 --- a/spec/env/common.js +++ b/spec/env/common.js @@ -17,7 +17,7 @@ global.compileWithPartials = function(string, hashOrArray, partials) { if(Object.prototype.toString.call(hashOrArray) === "[object Array]") { ary = []; ary.push(hashOrArray[0]); - ary.push({ helpers: hashOrArray[1], partials: hashOrArray[2], compat: hashOrArray[3] }); + ary.push({ helpers: hashOrArray[1], partials: hashOrArray[2] }); options = {compat: hashOrArray[3]}; } else { ary = [hashOrArray]; |