Skip to content

Commit

Permalink
Update handlebars.nested.js
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusmaso committed May 10, 2014
1 parent 34beba7 commit 4e7aff4
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions lib/handlebars.nested.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,35 @@
(function(Handlebars) {

var Utils = Handlebars.Utils;
var registerHelper = Handlebars.registerHelper;

var isString = function(object) {
Handlebars.Utils.isString = function(object) {
return toString.call(object) == '[object String]';
};

Handlebars.registerHelper = function(name, fn, inverse) {
var nestedFn = function() {
var args = [];
var nestedArguments = [];

for (var index = 0; index < arguments.length; index++) {
var argument = arguments[index];

if (argument && argument.hash) {
for (key in argument.hash) {
argument.hash[key] = Handlebars.resolveNested.apply(this, [argument.hash[key]]);
}

args.push(argument);
if (argument && argument.hash) {
for (key in argument.hash) argument.hash[key] = Handlebars.resolveNested.apply(this, [argument.hash[key]]);
nestedArguments.push(argument);
} else {
args.push(Handlebars.resolveNested.apply(this, [argument]));
nestedArguments.push(Handlebars.resolveNested.apply(this, [argument]));
}
}

return fn.apply(this, args);
return fn.apply(this, nestedArguments);
};

registerHelper.apply(this, [name, nestedFn, inverse]);
};

Handlebars.resolveNested = function(value) {
if (isString(value) && value.indexOf('{{') >= 0) {
value = Handlebars.compile(value)(this);
}

if (Utils.isString(value) && value.indexOf('{{') >= 0) value = Handlebars.compile(value)(this);
return value;
};

Expand Down

0 comments on commit 4e7aff4

Please sign in to comment.