From f1e6acf62837fe9b45bb15895a3f95085ef064c2 Mon Sep 17 00:00:00 2001 From: wycats Date: Fri, 19 Nov 2010 11:59:44 -0800 Subject: [PATCH] Revert "Make it possible for helpers to let downstream helpers know what the path to the current object is" This reverts commit 71dffd95c73909f04f139ecc3486165a2b246cd4. --- lib/handlebars.js | 23 ++++++++--------------- test/handlebars.js | 28 +--------------------------- 2 files changed, 9 insertions(+), 42 deletions(-) diff --git a/lib/handlebars.js b/lib/handlebars.js index 32fac29b..d85336d9 100644 --- a/lib/handlebars.js +++ b/lib/handlebars.js @@ -183,7 +183,7 @@ var Handlebars = { } }, - handleBlock: function(lookup, context, arg, fn, notFn, name) { + handleBlock: function(lookup, context, arg, fn, notFn) { var out = "", args; originalArgs = arg.length ? arg : [null] @@ -199,11 +199,11 @@ var Handlebars = { else { if (!Handlebars.isEmpty(lookup)) { // TODO: which case is this, and what does it mean for multiple args - out = out + Handlebars.helperMissing.call(arg[0], lookup, fn, name); + out = out + Handlebars.helperMissing.call(arg[0], lookup, fn); } if (notFn != null) { - out = out + Handlebars.helperMissing.not.call(arg[0], lookup, notFn, name); + out = out + Handlebars.helperMissing.not.call(arg[0], lookup, notFn); } } @@ -260,7 +260,7 @@ Handlebars.SafeString.prototype.toString = function() { return this.string.toString(); } -Handlebars.helperMissing = function(object, fn, name) { +Handlebars.helperMissing = function(object, fn) { var ret = ""; if(object === true) { @@ -273,17 +273,10 @@ Handlebars.helperMissing = function(object, fn, name) { } return ret; } else { - var ContextWrapper = function(parent) { - this.__path__ = parent.__path__ ? parent.__path__.concat(name) : [name]; - }; - - ContextWrapper.prototype = object; - var proxy = new ContextWrapper(this); - - return fn(proxy); + return fn(object); } }; -Handlebars.helperMissing.not = function(context, fn, name) { +Handlebars.helperMissing.not = function(context, fn) { return fn(context); } @@ -411,7 +404,7 @@ Handlebars.Compiler.prototype = { this.fn += "var " + fnId + " = function(context) {" + result + "}; "; this.fn += "lookup = " + this.lookupFor(mustache) + "; "; this.fn += "arg = [" + params.join(", ") + "] ;"; - this.fn += "stack.push(context); "; + this.fn += "stack.push(context);"; if (compiler.continueInverted) { var invertedCompiler = this.compileToEndOfBlock(mustache); @@ -420,7 +413,7 @@ Handlebars.Compiler.prototype = { else { this.fn += " var " + fnId + "Not = null;"; } - this.fn += "out = out + Handlebars.handleBlock(lookup, wrappedContext, arg, " + fnId + ", " + fnId + "Not, '" + mustache + "');" + this.fn += "out = out + Handlebars.handleBlock(lookup, wrappedContext, arg, " + fnId + ", " + fnId + "Not);" this.fn += "stack.pop();"; this.openBlock = false; diff --git a/test/handlebars.js b/test/handlebars.js index 3bb3a711..c772f1e5 100644 --- a/test/handlebars.js +++ b/test/handlebars.js @@ -89,32 +89,6 @@ test("functions with context argument", function() { "Frank", "functions are called with context arguments"); }); -test("functions receive the current path as part of the 'this'", function() { - template = "Hello {{#person}}{{show name}}{{/person}}" - object = { person: { name: "Alan" } }; - fallback = { - show: function(context) { - return context + " (from " + this.__path__.join("/") + ")"; - } - } - shouldCompileTo(template, [object, fallback], "Hello Alan (from person)") -}); - -test("block helpers don't mess with the path receive the current path as part of the 'this'", function() { - template = "Hello {{#block}}{{#person}}{{#info}}{{show name}}{{/info}}{{/person}}{{/block}}. {{show other/name}}" - object = { person: { info: { name: "Alan" } }, other: { name: "Yehuda" } }; - fallback = { - show: function(context) { - var ret = context; - if(this.__path__) ret += " (from " + this.__path__.join("/") + ")"; - return ret; - }, block: function(context, fn) { - return fn(this); - } - } - shouldCompileTo(template, [object, fallback], "Hello Alan (from person/info). Yehuda") -}); - test("nested paths", function() { shouldCompileTo("Goodbye {{alan/expression}} world!", {alan: {expression: "beautiful"}}, "Goodbye beautiful world!", "Nested paths access nested objects"); @@ -458,7 +432,7 @@ test("block multi-params work", function() { return fn({greeting: "Goodbye", adj: "cruel", noun: "world"}); }} shouldCompileTo(string, [hash, fallback], "Message: Goodbye cruel world", "block helpers with multiple params"); -}); +}) module("safestring");