Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusmaso committed Nov 18, 2014
2 parents 3936ea1 + 4e7aff4 commit 070220e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 30 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
handlebars.nested [![Build Status](https://travis-ci.org/mateusmaso/handlebars.nested.svg?branch=master)](https://travis-ci.org/mateusmaso/handlebars.nested)
=================

This library is an extension for Handlebars which allows nesting helpers or expressions within other helpers in one level deep. It was first created as a workaround to older versions, but after more issues came across it turned out to be an effective solution for those problems.
This library is an extension for Handlebars which allows nesting helpers or expressions within other helpers in one level deep. It was first created as a workaround to older versions, but after more issues it turned out to be an effective solution for many problems.

## Features

* Nesting helpers in one level deep.
* Nesting expressions with helpers in one level deep.
* Nesting helpers and expressions in one level deep.

## Dependencies

* handlebars.js (>= 1.0)

## Examples

Expand Down
21 changes: 8 additions & 13 deletions dist/handlebars.nested.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,41 +19,36 @@

}(this, 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);
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
2 changes: 1 addition & 1 deletion dist/handlebars.nested.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
//
// http://github.com/mateusmaso/handlebars.nested

!function(a,b){"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(module.exports=b(global.Handlebars)),exports=b(global.Handlebars)):b(a.Handlebars)}(this,function(a){var b=a.registerHelper,c=function(a){return"[object String]"==toString.call(a)};a.registerHelper=function(c,d,e){var f=function(){for(var b=[],c=0;c<arguments.length;c++){var e=arguments[c];if(e&&e.hash){for(key in e.hash)e.hash[key]=a.resolveNested.apply(this,[e.hash[key]]);b.push(e)}else b.push(a.resolveNested.apply(this,[e]))}return d.apply(this,b)};b.apply(this,[c,f,e])},a.resolveNested=function(b){return c(b)&&b.indexOf("{{")>=0&&(b=a.compile(b)(this)),b}});
!function(a,b){"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(module.exports=b(global.Handlebars)),exports=b(global.Handlebars)):b(a.Handlebars)}(this,function(a){var b=a.Utils,c=a.registerHelper;a.Utils.isString=function(a){return"[object String]"==toString.call(a)},a.registerHelper=function(b,d,e){var f=function(){for(var b=[],c=0;c<arguments.length;c++){var e=arguments[c];if(e&&e.hash){for(key in e.hash)e.hash[key]=a.resolveNested.apply(this,[e.hash[key]]);b.push(e)}else b.push(a.resolveNested.apply(this,[e]))}return d.apply(this,b)};c.apply(this,[b,f,e])},a.resolveNested=function(c){return b.isString(c)&&c.indexOf("{{")>=0&&(c=a.compile(c)(this)),c}});
21 changes: 8 additions & 13 deletions src/handlebars.nested.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,36 @@

}(this, 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);
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 070220e

Please sign in to comment.