Got accessing data in nested objects working using parent/child syntax.
This commit is contained in:
+7
-4
@@ -2,7 +2,6 @@ Handlebars = {
|
||||
compile: function(string) {
|
||||
var compiler = new Handlebars.Compiler(string);
|
||||
var result = compiler.compile();
|
||||
console.log(compiler.fn);
|
||||
return new Function("context", "fallback", "fallback = fallback || {}; var stack = [];" + result);
|
||||
},
|
||||
|
||||
@@ -34,7 +33,6 @@ Handlebars.helperMissing = function(object, fn) {
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
console.log("HERE");
|
||||
};
|
||||
|
||||
Handlebars.Compiler.prototype = {
|
||||
@@ -93,11 +91,16 @@ Handlebars.Compiler.prototype = {
|
||||
var parts = param.split("../");
|
||||
param = parts[parts.length - 1];
|
||||
depth = parts.length - 1;
|
||||
parts = param.split("/");
|
||||
var paramExpr = "";
|
||||
for (var i = 0; i < parts.length; i++) {
|
||||
paramExpr += "['" + parts[i] + "']";
|
||||
}
|
||||
|
||||
if (depth > 0) {
|
||||
return "( stack[stack.length - " + depth + "]['" + param + "'] )";
|
||||
return "( stack[stack.length - " + depth + "]" + paramExpr + ")";
|
||||
} else {
|
||||
return "( context['" + param + "'] || fallback['" + param + "'] )";
|
||||
return "( context" + paramExpr + " || fallback " + paramExpr + " )";
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -26,6 +26,11 @@ test("boolean", function() {
|
||||
"booleans do not show the contents when false");
|
||||
});
|
||||
|
||||
test("nested paths", function() {
|
||||
shouldCompileTo("Goodbye {{alan/expression}} world!", {alan: {expression: "beautiful"}},
|
||||
"Goodbye beautiful world!", "Nested paths access nested objects");
|
||||
});
|
||||
|
||||
module("blocks");
|
||||
|
||||
test("array", function() {
|
||||
|
||||
Reference in New Issue
Block a user