Skip to content

Commit 070220e

Browse files
author
Mateus Maso
committed
merge
2 parents 3936ea1 + 4e7aff4 commit 070220e

4 files changed

Lines changed: 23 additions & 30 deletions

File tree

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
handlebars.nested [![Build Status](https://travis-ci.org/mateusmaso/handlebars.nested.svg?branch=master)](https://travis-ci.org/mateusmaso/handlebars.nested)
22
=================
33

4-
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.
4+
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.
55

66
## Features
77

8-
* Nesting helpers in one level deep.
9-
* Nesting expressions with helpers in one level deep.
8+
* Nesting helpers and expressions in one level deep.
9+
10+
## Dependencies
11+
12+
* handlebars.js (>= 1.0)
1013

1114
## Examples
1215

dist/handlebars.nested.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,41 +19,36 @@
1919

2020
}(this, function(Handlebars) {
2121

22+
var Utils = Handlebars.Utils;
2223
var registerHelper = Handlebars.registerHelper;
2324

24-
var isString = function(object) {
25+
Handlebars.Utils.isString = function(object) {
2526
return toString.call(object) == '[object String]';
2627
};
2728

2829
Handlebars.registerHelper = function(name, fn, inverse) {
2930
var nestedFn = function() {
30-
var args = [];
31+
var nestedArguments = [];
3132

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

3536
if (argument && argument.hash) {
36-
for (key in argument.hash) {
37-
argument.hash[key] = Handlebars.resolveNested.apply(this, [argument.hash[key]]);
38-
}
39-
40-
args.push(argument);
37+
for (key in argument.hash) argument.hash[key] = Handlebars.resolveNested.apply(this, [argument.hash[key]]);
38+
nestedArguments.push(argument);
4139
} else {
42-
args.push(Handlebars.resolveNested.apply(this, [argument]));
40+
nestedArguments.push(Handlebars.resolveNested.apply(this, [argument]));
4341
}
4442
}
4543

46-
return fn.apply(this, args);
44+
return fn.apply(this, nestedArguments);
4745
};
4846

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

5250
Handlebars.resolveNested = function(value) {
53-
if (isString(value) && value.indexOf('{{') >= 0) {
54-
value = Handlebars.compile(value)(this);
55-
}
56-
51+
if (Utils.isString(value) && value.indexOf('{{') >= 0) value = Handlebars.compile(value)(this);
5752
return value;
5853
};
5954

dist/handlebars.nested.min.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
//
88
// http://github.com/mateusmaso/handlebars.nested
99

10-
!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}});
10+
!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}});

src/handlebars.nested.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,41 +10,36 @@
1010

1111
}(this, function(Handlebars) {
1212

13+
var Utils = Handlebars.Utils;
1314
var registerHelper = Handlebars.registerHelper;
1415

15-
var isString = function(object) {
16+
Handlebars.Utils.isString = function(object) {
1617
return toString.call(object) == '[object String]';
1718
};
1819

1920
Handlebars.registerHelper = function(name, fn, inverse) {
2021
var nestedFn = function() {
21-
var args = [];
22+
var nestedArguments = [];
2223

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

2627
if (argument && argument.hash) {
27-
for (key in argument.hash) {
28-
argument.hash[key] = Handlebars.resolveNested.apply(this, [argument.hash[key]]);
29-
}
30-
31-
args.push(argument);
28+
for (key in argument.hash) argument.hash[key] = Handlebars.resolveNested.apply(this, [argument.hash[key]]);
29+
nestedArguments.push(argument);
3230
} else {
33-
args.push(Handlebars.resolveNested.apply(this, [argument]));
31+
nestedArguments.push(Handlebars.resolveNested.apply(this, [argument]));
3432
}
3533
}
3634

37-
return fn.apply(this, args);
35+
return fn.apply(this, nestedArguments);
3836
};
3937

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

4341
Handlebars.resolveNested = function(value) {
44-
if (isString(value) && value.indexOf('{{') >= 0) {
45-
value = Handlebars.compile(value)(this);
46-
}
47-
42+
if (Utils.isString(value) && value.indexOf('{{') >= 0) value = Handlebars.compile(value)(this);
4843
return value;
4944
};
5045

0 commit comments

Comments
 (0)