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.
This commit is contained in:
@@ -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 ");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Vendored
+1
-1
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user