handlebars_assets 0.7.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +3 -3
- data/README.md +17 -5
- data/lib/handlebars_assets/version.rb +1 -1
- data/vendor/assets/javascripts/handlebars.js +57 -38
- data/vendor/assets/javascripts/handlebars.runtime.js +25 -10
- metadata +2 -2
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
## 0.7.1 (2012-12-4)
|
|
2
|
+
|
|
3
|
+
* Use edge version of `handlebars.js` ([this commit](https://github.com/wycats/handlebars.js/commit/bd0490145438e8f9df05abd2f4c25687bac81326)) to fix regression with context functions
|
|
4
|
+
|
|
1
5
|
## 0.7.0 (2012-11-16)
|
|
2
6
|
|
|
3
7
|
* Support `.hamlbars` extension and Haml
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
handlebars_assets (0.7.
|
|
4
|
+
handlebars_assets (0.7.1)
|
|
5
5
|
execjs (>= 1.2.9)
|
|
6
6
|
sprockets (>= 2.0.3)
|
|
7
7
|
tilt
|
|
@@ -13,10 +13,10 @@ GEM
|
|
|
13
13
|
multi_json (~> 1.0)
|
|
14
14
|
haml (3.1.7)
|
|
15
15
|
hike (1.2.1)
|
|
16
|
-
multi_json (1.
|
|
16
|
+
multi_json (1.4.0)
|
|
17
17
|
rack (1.4.1)
|
|
18
18
|
rake (0.9.2.2)
|
|
19
|
-
sprockets (2.
|
|
19
|
+
sprockets (2.8.1)
|
|
20
20
|
hike (~> 1.2)
|
|
21
21
|
multi_json (~> 1.0)
|
|
22
22
|
rack (~> 1.0)
|
data/README.md
CHANGED
|
@@ -8,7 +8,9 @@ Using `sprockets` with Sinatra or another framework? **handlebars_assets** works
|
|
|
8
8
|
|
|
9
9
|
## handlebars.js
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
**Please read**
|
|
12
|
+
|
|
13
|
+
Because of a serious regression introduced in RC1, `handlebars_assets` is packaged with an edge build of `handlebars.js` (this [commit](https://github.com/wycats/handlebars.js/commit/bd0490145438e8f9df05abd2f4c25687bac81326). See the section on using another version if that does not work for you.
|
|
12
14
|
|
|
13
15
|
## Installation with Rails 3.1+
|
|
14
16
|
|
|
@@ -48,10 +50,22 @@ If you need to compile your JavaScript templates in the browser as well, you sho
|
|
|
48
50
|
|
|
49
51
|
## Precompiling
|
|
50
52
|
|
|
51
|
-
`handlebars_assets` also works when you are precompiling your assets.
|
|
53
|
+
`handlebars_assets` also works when you are precompiling your assets.
|
|
54
|
+
|
|
55
|
+
### Heroku
|
|
56
|
+
|
|
57
|
+
If you are deploying to Heroku, be sure to read the [Rails guide](http://guides.rubyonrails.org/asset_pipeline.html#precompiling-assets) and in your `config/application.rb` set:
|
|
52
58
|
|
|
53
59
|
config.assets.initialize_on_precompile = false
|
|
54
60
|
|
|
61
|
+
This avoids running your initializers when compiling assets (see the [guide](http://guides.rubyonrails.org/asset_pipeline.html#precompiling-assets) for why you would want that).
|
|
62
|
+
|
|
63
|
+
However, that does mean that you cannot set your configuration in an initializer. This [issue](https://github.com/leshill/handlebars_assets/issues/34) has a workaround, or you can set:
|
|
64
|
+
|
|
65
|
+
config.assets.initialize_on_precompile = true
|
|
66
|
+
|
|
67
|
+
This will run all your initializers before precompiling assets.
|
|
68
|
+
|
|
55
69
|
## Templates directory
|
|
56
70
|
|
|
57
71
|
You should locate your templates with your other assets, for example `app/assets/javascripts/templates`. In your JavaScript manifest file, use `require_tree` to pull in the templates
|
|
@@ -98,13 +112,11 @@ For example, if you have a file `widget.hamlbars` that looks like this:
|
|
|
98
112
|
%h1 {{title}}
|
|
99
113
|
%p {{body}}
|
|
100
114
|
|
|
101
|
-
Haml will
|
|
115
|
+
The Haml will be pre-processed so that the Handlebars template is basically this:
|
|
102
116
|
|
|
103
117
|
<h1> {{title}} </h1>
|
|
104
118
|
<p> {{body}} </p>
|
|
105
119
|
|
|
106
|
-
And the Handlebars will turn it into a JavaScript template.
|
|
107
|
-
|
|
108
120
|
## Partials
|
|
109
121
|
|
|
110
122
|
If you begin the name of the template with an underscore, it will be recognized as a partial. You can invoke partials inside a template using the Handlebars partial syntax:
|
|
@@ -64,20 +64,33 @@ Handlebars.createFrame = Object.create || function(object) {
|
|
|
64
64
|
|
|
65
65
|
Handlebars.registerHelper('each', function(context, options) {
|
|
66
66
|
var fn = options.fn, inverse = options.inverse;
|
|
67
|
-
var ret = "", data;
|
|
67
|
+
var i = 0, ret = "", data;
|
|
68
68
|
|
|
69
69
|
if (options.data) {
|
|
70
70
|
data = Handlebars.createFrame(options.data);
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
if(context && context
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
73
|
+
if(context && typeof context === 'object') {
|
|
74
|
+
if(context instanceof Array){
|
|
75
|
+
for(var j = context.length; i<j; i++) {
|
|
76
|
+
if (data) { data.index = i; }
|
|
77
|
+
ret = ret + fn(context[i], { data: data });
|
|
78
|
+
}
|
|
79
|
+
} else {
|
|
80
|
+
for(var key in context) {
|
|
81
|
+
if(context.hasOwnProperty(key)) {
|
|
82
|
+
if(data) { data.key = key; }
|
|
83
|
+
ret = ret + fn(context[key], {data: data});
|
|
84
|
+
i++;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
77
87
|
}
|
|
78
|
-
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if(i === 0){
|
|
79
91
|
ret = inverse(this);
|
|
80
92
|
}
|
|
93
|
+
|
|
81
94
|
return ret;
|
|
82
95
|
});
|
|
83
96
|
|
|
@@ -506,62 +519,66 @@ case 2:
|
|
|
506
519
|
return 14;
|
|
507
520
|
|
|
508
521
|
break;
|
|
509
|
-
case 3: return
|
|
522
|
+
case 3: yy_.yytext = yy_.yytext.substr(0, yy_.yyleng-4); this.popState(); return 15;
|
|
510
523
|
break;
|
|
511
|
-
case 4: return
|
|
524
|
+
case 4: return 24;
|
|
512
525
|
break;
|
|
513
|
-
case 5: return
|
|
526
|
+
case 5: return 16;
|
|
514
527
|
break;
|
|
515
|
-
case 6: return
|
|
528
|
+
case 6: return 20;
|
|
516
529
|
break;
|
|
517
530
|
case 7: return 19;
|
|
518
531
|
break;
|
|
519
|
-
case 8: return
|
|
532
|
+
case 8: return 19;
|
|
520
533
|
break;
|
|
521
534
|
case 9: return 23;
|
|
522
535
|
break;
|
|
523
|
-
case 10:
|
|
536
|
+
case 10: return 23;
|
|
537
|
+
break;
|
|
538
|
+
case 11: this.popState(); this.begin('com');
|
|
539
|
+
break;
|
|
540
|
+
case 12: yy_.yytext = yy_.yytext.substr(3,yy_.yyleng-5); this.popState(); return 15;
|
|
524
541
|
break;
|
|
525
|
-
case
|
|
542
|
+
case 13: return 22;
|
|
526
543
|
break;
|
|
527
|
-
case
|
|
544
|
+
case 14: return 35;
|
|
528
545
|
break;
|
|
529
|
-
case
|
|
546
|
+
case 15: return 34;
|
|
530
547
|
break;
|
|
531
|
-
case
|
|
548
|
+
case 16: return 34;
|
|
532
549
|
break;
|
|
533
|
-
case
|
|
550
|
+
case 17: return 37;
|
|
534
551
|
break;
|
|
535
|
-
case
|
|
552
|
+
case 18: /*ignore whitespace*/
|
|
536
553
|
break;
|
|
537
|
-
case
|
|
554
|
+
case 19: this.popState(); return 18;
|
|
538
555
|
break;
|
|
539
|
-
case
|
|
556
|
+
case 20: this.popState(); return 18;
|
|
540
557
|
break;
|
|
541
|
-
case
|
|
558
|
+
case 21: yy_.yytext = yy_.yytext.substr(1,yy_.yyleng-2).replace(/\\"/g,'"'); return 29;
|
|
542
559
|
break;
|
|
543
|
-
case
|
|
560
|
+
case 22: yy_.yytext = yy_.yytext.substr(1,yy_.yyleng-2).replace(/\\'/g,"'"); return 29;
|
|
544
561
|
break;
|
|
545
|
-
case
|
|
562
|
+
case 23: yy_.yytext = yy_.yytext.substr(1); return 27;
|
|
546
563
|
break;
|
|
547
|
-
case
|
|
564
|
+
case 24: return 31;
|
|
548
565
|
break;
|
|
549
|
-
case
|
|
566
|
+
case 25: return 31;
|
|
550
567
|
break;
|
|
551
|
-
case
|
|
568
|
+
case 26: return 30;
|
|
552
569
|
break;
|
|
553
|
-
case
|
|
570
|
+
case 27: return 34;
|
|
554
571
|
break;
|
|
555
|
-
case
|
|
572
|
+
case 28: yy_.yytext = yy_.yytext.substr(1, yy_.yyleng-2); return 34;
|
|
556
573
|
break;
|
|
557
|
-
case
|
|
574
|
+
case 29: return 'INVALID';
|
|
558
575
|
break;
|
|
559
|
-
case
|
|
576
|
+
case 30: return 5;
|
|
560
577
|
break;
|
|
561
578
|
}
|
|
562
579
|
};
|
|
563
|
-
lexer.rules = [/^(?:[^\x00]*?(?=(\{\{)))/,/^(?:[^\x00]+)/,/^(?:[^\x00]{2,}?(?=(\{\{|$)))/,/^(?:\{\{>)/,/^(?:\{\{#)/,/^(?:\{\{\/)/,/^(?:\{\{\^)/,/^(?:\{\{\s*else\b)/,/^(?:\{\{\{)/,/^(?:\{\{&)/,/^(?:\{\{![\s\S]*?\}\})/,/^(?:\{\{)/,/^(?:=)/,/^(?:\.(?=[} ]))/,/^(?:\.\.)/,/^(?:[\/.])/,/^(?:\s+)/,/^(?:\}\}\})/,/^(?:\}\})/,/^(?:"(\\["]|[^"])*")/,/^(?:'(\\[']|[^'])*')/,/^(?:@[a-zA-Z]+)/,/^(?:true(?=[}\s]))/,/^(?:false(?=[}\s]))/,/^(?:[0-9]+(?=[}\s]))/,/^(?:[a-zA-Z0-9_$-]+(?=[=}\s\/.]))/,/^(?:\[[^\]]*\])/,/^(?:.)/,/^(?:$)/];
|
|
564
|
-
lexer.conditions = {"mu":{"rules":[
|
|
580
|
+
lexer.rules = [/^(?:[^\x00]*?(?=(\{\{)))/,/^(?:[^\x00]+)/,/^(?:[^\x00]{2,}?(?=(\{\{|$)))/,/^(?:[\s\S]*?--\}\})/,/^(?:\{\{>)/,/^(?:\{\{#)/,/^(?:\{\{\/)/,/^(?:\{\{\^)/,/^(?:\{\{\s*else\b)/,/^(?:\{\{\{)/,/^(?:\{\{&)/,/^(?:\{\{!--)/,/^(?:\{\{![\s\S]*?\}\})/,/^(?:\{\{)/,/^(?:=)/,/^(?:\.(?=[} ]))/,/^(?:\.\.)/,/^(?:[\/.])/,/^(?:\s+)/,/^(?:\}\}\})/,/^(?:\}\})/,/^(?:"(\\["]|[^"])*")/,/^(?:'(\\[']|[^'])*')/,/^(?:@[a-zA-Z]+)/,/^(?:true(?=[}\s]))/,/^(?:false(?=[}\s]))/,/^(?:[0-9]+(?=[}\s]))/,/^(?:[a-zA-Z0-9_$-]+(?=[=}\s\/.]))/,/^(?:\[[^\]]*\])/,/^(?:.)/,/^(?:$)/];
|
|
581
|
+
lexer.conditions = {"mu":{"rules":[4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30],"inclusive":false},"emu":{"rules":[2],"inclusive":false},"com":{"rules":[3],"inclusive":false},"INITIAL":{"rules":[0,1,30],"inclusive":true}};
|
|
565
582
|
return lexer;})()
|
|
566
583
|
parser.lexer = lexer;
|
|
567
584
|
function Parser () { this.yy = {}; }Parser.prototype = parser;parser.Parser = Parser;
|
|
@@ -728,14 +745,16 @@ Handlebars.log = function(level, str) { Handlebars.logger.log(level, str); };
|
|
|
728
745
|
|
|
729
746
|
})();;
|
|
730
747
|
// lib/handlebars/utils.js
|
|
748
|
+
|
|
749
|
+
var errorProps = ['description', 'fileName', 'lineNumber', 'message', 'name', 'number', 'stack'];
|
|
750
|
+
|
|
731
751
|
Handlebars.Exception = function(message) {
|
|
732
752
|
var tmp = Error.prototype.constructor.apply(this, arguments);
|
|
733
753
|
|
|
734
|
-
|
|
735
|
-
|
|
754
|
+
// Unfortunately errors are not enumerable in Chrome (at least), so `for prop in tmp` doesn't work.
|
|
755
|
+
for (var idx = 0; idx < errorProps.length; idx++) {
|
|
756
|
+
this[errorProps[idx]] = tmp[errorProps[idx]];
|
|
736
757
|
}
|
|
737
|
-
|
|
738
|
-
this.message = tmp.message;
|
|
739
758
|
};
|
|
740
759
|
Handlebars.Exception.prototype = new Error();
|
|
741
760
|
|
|
@@ -1434,7 +1453,7 @@ Handlebars.JavaScriptCompiler = function() {};
|
|
|
1434
1453
|
this.context.aliases.functionType = '"function"';
|
|
1435
1454
|
|
|
1436
1455
|
this.replaceStack(function(current) {
|
|
1437
|
-
return "typeof " + current + " === functionType ? " + current + "() : " + current;
|
|
1456
|
+
return "typeof " + current + " === functionType ? " + current + ".apply(depth0) : " + current;
|
|
1438
1457
|
});
|
|
1439
1458
|
},
|
|
1440
1459
|
|
|
@@ -1579,7 +1598,7 @@ Handlebars.JavaScriptCompiler = function() {};
|
|
|
1579
1598
|
var nextStack = this.nextStack();
|
|
1580
1599
|
|
|
1581
1600
|
this.source.push('if (foundHelper) { ' + nextStack + ' = foundHelper.call(' + helper.callParams + '); }');
|
|
1582
|
-
this.source.push('else { ' + nextStack + ' = ' + nonHelper + '; ' + nextStack + ' = typeof ' + nextStack + ' === functionType ? ' + nextStack + '() : ' + nextStack + '; }');
|
|
1601
|
+
this.source.push('else { ' + nextStack + ' = ' + nonHelper + '; ' + nextStack + ' = typeof ' + nextStack + ' === functionType ? ' + nextStack + '.apply(depth0) : ' + nextStack + '; }');
|
|
1583
1602
|
},
|
|
1584
1603
|
|
|
1585
1604
|
// [invokePartial]
|
|
@@ -64,20 +64,33 @@ Handlebars.createFrame = Object.create || function(object) {
|
|
|
64
64
|
|
|
65
65
|
Handlebars.registerHelper('each', function(context, options) {
|
|
66
66
|
var fn = options.fn, inverse = options.inverse;
|
|
67
|
-
var ret = "", data;
|
|
67
|
+
var i = 0, ret = "", data;
|
|
68
68
|
|
|
69
69
|
if (options.data) {
|
|
70
70
|
data = Handlebars.createFrame(options.data);
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
if(context && context
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
73
|
+
if(context && typeof context === 'object') {
|
|
74
|
+
if(context instanceof Array){
|
|
75
|
+
for(var j = context.length; i<j; i++) {
|
|
76
|
+
if (data) { data.index = i; }
|
|
77
|
+
ret = ret + fn(context[i], { data: data });
|
|
78
|
+
}
|
|
79
|
+
} else {
|
|
80
|
+
for(var key in context) {
|
|
81
|
+
if(context.hasOwnProperty(key)) {
|
|
82
|
+
if(data) { data.key = key; }
|
|
83
|
+
ret = ret + fn(context[key], {data: data});
|
|
84
|
+
i++;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
77
87
|
}
|
|
78
|
-
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if(i === 0){
|
|
79
91
|
ret = inverse(this);
|
|
80
92
|
}
|
|
93
|
+
|
|
81
94
|
return ret;
|
|
82
95
|
});
|
|
83
96
|
|
|
@@ -111,14 +124,16 @@ Handlebars.registerHelper('log', function(context) {
|
|
|
111
124
|
}(this.Handlebars));
|
|
112
125
|
;
|
|
113
126
|
// lib/handlebars/utils.js
|
|
127
|
+
|
|
128
|
+
var errorProps = ['description', 'fileName', 'lineNumber', 'message', 'name', 'number', 'stack'];
|
|
129
|
+
|
|
114
130
|
Handlebars.Exception = function(message) {
|
|
115
131
|
var tmp = Error.prototype.constructor.apply(this, arguments);
|
|
116
132
|
|
|
117
|
-
|
|
118
|
-
|
|
133
|
+
// Unfortunately errors are not enumerable in Chrome (at least), so `for prop in tmp` doesn't work.
|
|
134
|
+
for (var idx = 0; idx < errorProps.length; idx++) {
|
|
135
|
+
this[errorProps[idx]] = tmp[errorProps[idx]];
|
|
119
136
|
}
|
|
120
|
-
|
|
121
|
-
this.message = tmp.message;
|
|
122
137
|
};
|
|
123
138
|
Handlebars.Exception.prototype = new Error();
|
|
124
139
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: handlebars_assets
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.7.
|
|
4
|
+
version: 0.7.1
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2012-
|
|
12
|
+
date: 2012-12-05 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: execjs
|