From 13633e7896b9c104667102b3b5715fc1a6b0d613 Mon Sep 17 00:00:00 2001 From: Blake Embrey Date: Thu, 9 Jan 2014 12:45:26 +1000 Subject: [PATCH] Improve usefulness of extend util, properly use namespace property, update setup options to use a hash helper. --- lib/handlebars/base.js | 8 ++-- .../compiler/javascript-compiler.js | 45 ++++++++++++------- lib/handlebars/runtime.js | 5 +-- lib/handlebars/utils.js | 12 +++-- 4 files changed, 41 insertions(+), 29 deletions(-) diff --git a/lib/handlebars/base.js b/lib/handlebars/base.js index 059b1c3fb..ff9736ca6 100644 --- a/lib/handlebars/base.js +++ b/lib/handlebars/base.js @@ -102,8 +102,8 @@ function registerDefaultHelpers(instance) { } else { for(var key in context) { if(context.hasOwnProperty(key)) { - if(data) { - data.key = key; + if(data) { + data.key = key; data.index = i; data.first = (i === 0); } @@ -174,7 +174,5 @@ export var logger = { export function log(level, obj) { logger.log(level, obj); } export var createFrame = function(object) { - var obj = {}; - Utils.extend(obj, object); - return obj; + return Utils.extend({}, object); }; diff --git a/lib/handlebars/compiler/javascript-compiler.js b/lib/handlebars/compiler/javascript-compiler.js index abdc8053b..7898bd1f3 100644 --- a/lib/handlebars/compiler/javascript-compiler.js +++ b/lib/handlebars/compiler/javascript-compiler.js @@ -21,8 +21,7 @@ JavaScriptCompiler.prototype = { ret = parent + "[" + name + "]"; } else if (JavaScriptCompiler.isValidJavaScriptVariableName(name)) { ret = parent + "." + name; - } - else { + } else { ret = parent + "['" + name + "']"; } @@ -168,7 +167,7 @@ JavaScriptCompiler.prototype = { this.pushSource("return buffer;"); } - var params = this.isChild ? ["depth0", "data"] : ["Handlebars", "depth0", "helpers", "partials", "data"]; + var params = this.isChild ? ["depth0", "data"] : [this.namespace, "depth0", "helpers", "partials", "data"]; for(var i=0, l=this.environment.depths.list.length; i