handlebars-source 1.0.12 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of handlebars-source might be problematic. Click here for more details.

@@ -1,11 +1,11 @@
1
1
  module Handlebars
2
2
  module Source
3
3
  def self.bundled_path
4
- File.expand_path("../../../dist/handlebars.js", __FILE__)
4
+ File.expand_path("../../../handlebars.js", __FILE__)
5
5
  end
6
6
 
7
7
  def self.runtime_bundled_path
8
- File.expand_path("../../../dist/handlebars.runtime.js", __FILE__)
8
+ File.expand_path("../../../handlebars.runtime.js", __FILE__)
9
9
  end
10
10
  end
11
11
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: handlebars-source
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.12
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yehuda Katz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-26 00:00:00.000000000 Z
11
+ date: 2013-11-04 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Handlebars.js source code wrapper for (pre)compilation gems.
14
14
  email:
@@ -17,8 +17,8 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
- - dist/handlebars.js
21
- - dist/handlebars.runtime.js
20
+ - handlebars.js
21
+ - handlebars.runtime.js
22
22
  - lib/handlebars/source.rb
23
23
  homepage: https://github.com/wycats/handlebars.js/
24
24
  licenses: []
@@ -29,19 +29,18 @@ require_paths:
29
29
  - lib
30
30
  required_ruby_version: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - ! '>='
32
+ - - '>='
33
33
  - !ruby/object:Gem::Version
34
34
  version: '0'
35
35
  required_rubygems_version: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - ! '>='
37
+ - - '>='
38
38
  - !ruby/object:Gem::Version
39
39
  version: '0'
40
40
  requirements: []
41
41
  rubyforge_project:
42
- rubygems_version: 2.0.3
42
+ rubygems_version: 2.1.9
43
43
  signing_key:
44
44
  specification_version: 4
45
45
  summary: Handlebars.js source code wrapper
46
46
  test_files: []
47
- has_rdoc:
@@ -1,2292 +0,0 @@
1
- /*
2
-
3
- Copyright (C) 2011 by Yehuda Katz
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
22
-
23
- @license
24
- */
25
-
26
- // lib/handlebars/browser-prefix.js
27
- (function(undefined) {
28
- var Handlebars = {};
29
- ;
30
- // lib/handlebars/base.js
31
-
32
- Handlebars.VERSION = "1.0.0";
33
- Handlebars.COMPILER_REVISION = 4;
34
-
35
- Handlebars.REVISION_CHANGES = {
36
- 1: '<= 1.0.rc.2', // 1.0.rc.2 is actually rev2 but doesn't report it
37
- 2: '== 1.0.0-rc.3',
38
- 3: '== 1.0.0-rc.4',
39
- 4: '>= 1.0.0'
40
- };
41
-
42
- Handlebars.helpers = {};
43
- Handlebars.partials = {};
44
-
45
- var toString = Object.prototype.toString,
46
- functionType = '[object Function]',
47
- objectType = '[object Object]';
48
-
49
- Handlebars.registerHelper = function(name, fn, inverse) {
50
- if (toString.call(name) === objectType) {
51
- if (inverse || fn) { throw new Handlebars.Exception('Arg not supported with multiple helpers'); }
52
- Handlebars.Utils.extend(this.helpers, name);
53
- } else {
54
- if (inverse) { fn.not = inverse; }
55
- this.helpers[name] = fn;
56
- }
57
- };
58
-
59
- Handlebars.registerPartial = function(name, str) {
60
- if (toString.call(name) === objectType) {
61
- Handlebars.Utils.extend(this.partials, name);
62
- } else {
63
- this.partials[name] = str;
64
- }
65
- };
66
-
67
- Handlebars.registerHelper('helperMissing', function(arg) {
68
- if(arguments.length === 2) {
69
- return undefined;
70
- } else {
71
- throw new Error("Missing helper: '" + arg + "'");
72
- }
73
- });
74
-
75
- Handlebars.registerHelper('blockHelperMissing', function(context, options) {
76
- var inverse = options.inverse || function() {}, fn = options.fn;
77
-
78
- var type = toString.call(context);
79
-
80
- if(type === functionType) { context = context.call(this); }
81
-
82
- if(context === true) {
83
- return fn(this);
84
- } else if(context === false || context == null) {
85
- return inverse(this);
86
- } else if(type === "[object Array]") {
87
- if(context.length > 0) {
88
- return Handlebars.helpers.each(context, options);
89
- } else {
90
- return inverse(this);
91
- }
92
- } else {
93
- return fn(context);
94
- }
95
- });
96
-
97
- Handlebars.K = function() {};
98
-
99
- Handlebars.createFrame = Object.create || function(object) {
100
- Handlebars.K.prototype = object;
101
- var obj = new Handlebars.K();
102
- Handlebars.K.prototype = null;
103
- return obj;
104
- };
105
-
106
- Handlebars.logger = {
107
- DEBUG: 0, INFO: 1, WARN: 2, ERROR: 3, level: 3,
108
-
109
- methodMap: {0: 'debug', 1: 'info', 2: 'warn', 3: 'error'},
110
-
111
- // can be overridden in the host environment
112
- log: function(level, obj) {
113
- if (Handlebars.logger.level <= level) {
114
- var method = Handlebars.logger.methodMap[level];
115
- if (typeof console !== 'undefined' && console[method]) {
116
- console[method].call(console, obj);
117
- }
118
- }
119
- }
120
- };
121
-
122
- Handlebars.log = function(level, obj) { Handlebars.logger.log(level, obj); };
123
-
124
- Handlebars.registerHelper('each', function(context, options) {
125
- var fn = options.fn, inverse = options.inverse;
126
- var i = 0, ret = "", data;
127
-
128
- var type = toString.call(context);
129
- if(type === functionType) { context = context.call(this); }
130
-
131
- if (options.data) {
132
- data = Handlebars.createFrame(options.data);
133
- }
134
-
135
- if(context && typeof context === 'object') {
136
- if(context instanceof Array){
137
- for(var j = context.length; i<j; i++) {
138
- if (data) { data.index = i; }
139
- ret = ret + fn(context[i], { data: data });
140
- }
141
- } else {
142
- for(var key in context) {
143
- if(context.hasOwnProperty(key)) {
144
- if(data) { data.key = key; }
145
- ret = ret + fn(context[key], {data: data});
146
- i++;
147
- }
148
- }
149
- }
150
- }
151
-
152
- if(i === 0){
153
- ret = inverse(this);
154
- }
155
-
156
- return ret;
157
- });
158
-
159
- Handlebars.registerHelper('if', function(conditional, options) {
160
- var type = toString.call(conditional);
161
- if(type === functionType) { conditional = conditional.call(this); }
162
-
163
- if(!conditional || Handlebars.Utils.isEmpty(conditional)) {
164
- return options.inverse(this);
165
- } else {
166
- return options.fn(this);
167
- }
168
- });
169
-
170
- Handlebars.registerHelper('unless', function(conditional, options) {
171
- return Handlebars.helpers['if'].call(this, conditional, {fn: options.inverse, inverse: options.fn});
172
- });
173
-
174
- Handlebars.registerHelper('with', function(context, options) {
175
- var type = toString.call(context);
176
- if(type === functionType) { context = context.call(this); }
177
-
178
- if (!Handlebars.Utils.isEmpty(context)) return options.fn(context);
179
- });
180
-
181
- Handlebars.registerHelper('log', function(context, options) {
182
- var level = options.data && options.data.level != null ? parseInt(options.data.level, 10) : 1;
183
- Handlebars.log(level, context);
184
- });
185
- ;
186
- // lib/handlebars/compiler/parser.js
187
- /* Jison generated parser */
188
- var handlebars = (function(){
189
- var parser = {trace: function trace() { },
190
- yy: {},
191
- symbols_: {"error":2,"root":3,"program":4,"EOF":5,"simpleInverse":6,"statements":7,"statement":8,"openInverse":9,"closeBlock":10,"openBlock":11,"mustache":12,"partial":13,"CONTENT":14,"COMMENT":15,"OPEN_BLOCK":16,"inMustache":17,"CLOSE":18,"OPEN_INVERSE":19,"OPEN_ENDBLOCK":20,"path":21,"OPEN":22,"OPEN_UNESCAPED":23,"CLOSE_UNESCAPED":24,"OPEN_PARTIAL":25,"partialName":26,"params":27,"hash":28,"dataName":29,"param":30,"STRING":31,"INTEGER":32,"BOOLEAN":33,"hashSegments":34,"hashSegment":35,"ID":36,"EQUALS":37,"DATA":38,"pathSegments":39,"SEP":40,"$accept":0,"$end":1},
192
- terminals_: {2:"error",5:"EOF",14:"CONTENT",15:"COMMENT",16:"OPEN_BLOCK",18:"CLOSE",19:"OPEN_INVERSE",20:"OPEN_ENDBLOCK",22:"OPEN",23:"OPEN_UNESCAPED",24:"CLOSE_UNESCAPED",25:"OPEN_PARTIAL",31:"STRING",32:"INTEGER",33:"BOOLEAN",36:"ID",37:"EQUALS",38:"DATA",40:"SEP"},
193
- productions_: [0,[3,2],[4,2],[4,3],[4,2],[4,1],[4,1],[4,0],[7,1],[7,2],[8,3],[8,3],[8,1],[8,1],[8,1],[8,1],[11,3],[9,3],[10,3],[12,3],[12,3],[13,3],[13,4],[6,2],[17,3],[17,2],[17,2],[17,1],[17,1],[27,2],[27,1],[30,1],[30,1],[30,1],[30,1],[30,1],[28,1],[34,2],[34,1],[35,3],[35,3],[35,3],[35,3],[35,3],[26,1],[26,1],[26,1],[29,2],[21,1],[39,3],[39,1]],
194
- performAction: function anonymous(yytext,yyleng,yylineno,yy,yystate,$$,_$) {
195
-
196
- var $0 = $$.length - 1;
197
- switch (yystate) {
198
- case 1: return $$[$0-1];
199
- break;
200
- case 2: this.$ = new yy.ProgramNode([], $$[$0]);
201
- break;
202
- case 3: this.$ = new yy.ProgramNode($$[$0-2], $$[$0]);
203
- break;
204
- case 4: this.$ = new yy.ProgramNode($$[$0-1], []);
205
- break;
206
- case 5: this.$ = new yy.ProgramNode($$[$0]);
207
- break;
208
- case 6: this.$ = new yy.ProgramNode([], []);
209
- break;
210
- case 7: this.$ = new yy.ProgramNode([]);
211
- break;
212
- case 8: this.$ = [$$[$0]];
213
- break;
214
- case 9: $$[$0-1].push($$[$0]); this.$ = $$[$0-1];
215
- break;
216
- case 10: this.$ = new yy.BlockNode($$[$0-2], $$[$0-1].inverse, $$[$0-1], $$[$0]);
217
- break;
218
- case 11: this.$ = new yy.BlockNode($$[$0-2], $$[$0-1], $$[$0-1].inverse, $$[$0]);
219
- break;
220
- case 12: this.$ = $$[$0];
221
- break;
222
- case 13: this.$ = $$[$0];
223
- break;
224
- case 14: this.$ = new yy.ContentNode($$[$0]);
225
- break;
226
- case 15: this.$ = new yy.CommentNode($$[$0]);
227
- break;
228
- case 16: this.$ = new yy.MustacheNode($$[$0-1][0], $$[$0-1][1]);
229
- break;
230
- case 17: this.$ = new yy.MustacheNode($$[$0-1][0], $$[$0-1][1]);
231
- break;
232
- case 18: this.$ = $$[$0-1];
233
- break;
234
- case 19:
235
- // Parsing out the '&' escape token at this level saves ~500 bytes after min due to the removal of one parser node.
236
- this.$ = new yy.MustacheNode($$[$0-1][0], $$[$0-1][1], $$[$0-2][2] === '&');
237
-
238
- break;
239
- case 20: this.$ = new yy.MustacheNode($$[$0-1][0], $$[$0-1][1], true);
240
- break;
241
- case 21: this.$ = new yy.PartialNode($$[$0-1]);
242
- break;
243
- case 22: this.$ = new yy.PartialNode($$[$0-2], $$[$0-1]);
244
- break;
245
- case 23:
246
- break;
247
- case 24: this.$ = [[$$[$0-2]].concat($$[$0-1]), $$[$0]];
248
- break;
249
- case 25: this.$ = [[$$[$0-1]].concat($$[$0]), null];
250
- break;
251
- case 26: this.$ = [[$$[$0-1]], $$[$0]];
252
- break;
253
- case 27: this.$ = [[$$[$0]], null];
254
- break;
255
- case 28: this.$ = [[$$[$0]], null];
256
- break;
257
- case 29: $$[$0-1].push($$[$0]); this.$ = $$[$0-1];
258
- break;
259
- case 30: this.$ = [$$[$0]];
260
- break;
261
- case 31: this.$ = $$[$0];
262
- break;
263
- case 32: this.$ = new yy.StringNode($$[$0]);
264
- break;
265
- case 33: this.$ = new yy.IntegerNode($$[$0]);
266
- break;
267
- case 34: this.$ = new yy.BooleanNode($$[$0]);
268
- break;
269
- case 35: this.$ = $$[$0];
270
- break;
271
- case 36: this.$ = new yy.HashNode($$[$0]);
272
- break;
273
- case 37: $$[$0-1].push($$[$0]); this.$ = $$[$0-1];
274
- break;
275
- case 38: this.$ = [$$[$0]];
276
- break;
277
- case 39: this.$ = [$$[$0-2], $$[$0]];
278
- break;
279
- case 40: this.$ = [$$[$0-2], new yy.StringNode($$[$0])];
280
- break;
281
- case 41: this.$ = [$$[$0-2], new yy.IntegerNode($$[$0])];
282
- break;
283
- case 42: this.$ = [$$[$0-2], new yy.BooleanNode($$[$0])];
284
- break;
285
- case 43: this.$ = [$$[$0-2], $$[$0]];
286
- break;
287
- case 44: this.$ = new yy.PartialNameNode($$[$0]);
288
- break;
289
- case 45: this.$ = new yy.PartialNameNode(new yy.StringNode($$[$0]));
290
- break;
291
- case 46: this.$ = new yy.PartialNameNode(new yy.IntegerNode($$[$0]));
292
- break;
293
- case 47: this.$ = new yy.DataNode($$[$0]);
294
- break;
295
- case 48: this.$ = new yy.IdNode($$[$0]);
296
- break;
297
- case 49: $$[$0-2].push({part: $$[$0], separator: $$[$0-1]}); this.$ = $$[$0-2];
298
- break;
299
- case 50: this.$ = [{part: $$[$0]}];
300
- break;
301
- }
302
- },
303
- table: [{3:1,4:2,5:[2,7],6:3,7:4,8:6,9:7,11:8,12:9,13:10,14:[1,11],15:[1,12],16:[1,13],19:[1,5],22:[1,14],23:[1,15],25:[1,16]},{1:[3]},{5:[1,17]},{5:[2,6],7:18,8:6,9:7,11:8,12:9,13:10,14:[1,11],15:[1,12],16:[1,13],19:[1,19],20:[2,6],22:[1,14],23:[1,15],25:[1,16]},{5:[2,5],6:20,8:21,9:7,11:8,12:9,13:10,14:[1,11],15:[1,12],16:[1,13],19:[1,5],20:[2,5],22:[1,14],23:[1,15],25:[1,16]},{17:23,18:[1,22],21:24,29:25,36:[1,28],38:[1,27],39:26},{5:[2,8],14:[2,8],15:[2,8],16:[2,8],19:[2,8],20:[2,8],22:[2,8],23:[2,8],25:[2,8]},{4:29,6:3,7:4,8:6,9:7,11:8,12:9,13:10,14:[1,11],15:[1,12],16:[1,13],19:[1,5],20:[2,7],22:[1,14],23:[1,15],25:[1,16]},{4:30,6:3,7:4,8:6,9:7,11:8,12:9,13:10,14:[1,11],15:[1,12],16:[1,13],19:[1,5],20:[2,7],22:[1,14],23:[1,15],25:[1,16]},{5:[2,12],14:[2,12],15:[2,12],16:[2,12],19:[2,12],20:[2,12],22:[2,12],23:[2,12],25:[2,12]},{5:[2,13],14:[2,13],15:[2,13],16:[2,13],19:[2,13],20:[2,13],22:[2,13],23:[2,13],25:[2,13]},{5:[2,14],14:[2,14],15:[2,14],16:[2,14],19:[2,14],20:[2,14],22:[2,14],23:[2,14],25:[2,14]},{5:[2,15],14:[2,15],15:[2,15],16:[2,15],19:[2,15],20:[2,15],22:[2,15],23:[2,15],25:[2,15]},{17:31,21:24,29:25,36:[1,28],38:[1,27],39:26},{17:32,21:24,29:25,36:[1,28],38:[1,27],39:26},{17:33,21:24,29:25,36:[1,28],38:[1,27],39:26},{21:35,26:34,31:[1,36],32:[1,37],36:[1,28],39:26},{1:[2,1]},{5:[2,2],8:21,9:7,11:8,12:9,13:10,14:[1,11],15:[1,12],16:[1,13],19:[1,19],20:[2,2],22:[1,14],23:[1,15],25:[1,16]},{17:23,21:24,29:25,36:[1,28],38:[1,27],39:26},{5:[2,4],7:38,8:6,9:7,11:8,12:9,13:10,14:[1,11],15:[1,12],16:[1,13],19:[1,19],20:[2,4],22:[1,14],23:[1,15],25:[1,16]},{5:[2,9],14:[2,9],15:[2,9],16:[2,9],19:[2,9],20:[2,9],22:[2,9],23:[2,9],25:[2,9]},{5:[2,23],14:[2,23],15:[2,23],16:[2,23],19:[2,23],20:[2,23],22:[2,23],23:[2,23],25:[2,23]},{18:[1,39]},{18:[2,27],21:44,24:[2,27],27:40,28:41,29:48,30:42,31:[1,45],32:[1,46],33:[1,47],34:43,35:49,36:[1,50],38:[1,27],39:26},{18:[2,28],24:[2,28]},{18:[2,48],24:[2,48],31:[2,48],32:[2,48],33:[2,48],36:[2,48],38:[2,48],40:[1,51]},{21:52,36:[1,28],39:26},{18:[2,50],24:[2,50],31:[2,50],32:[2,50],33:[2,50],36:[2,50],38:[2,50],40:[2,50]},{10:53,20:[1,54]},{10:55,20:[1,54]},{18:[1,56]},{18:[1,57]},{24:[1,58]},{18:[1,59],21:60,36:[1,28],39:26},{18:[2,44],36:[2,44]},{18:[2,45],36:[2,45]},{18:[2,46],36:[2,46]},{5:[2,3],8:21,9:7,11:8,12:9,13:10,14:[1,11],15:[1,12],16:[1,13],19:[1,19],20:[2,3],22:[1,14],23:[1,15],25:[1,16]},{14:[2,17],15:[2,17],16:[2,17],19:[2,17],20:[2,17],22:[2,17],23:[2,17],25:[2,17]},{18:[2,25],21:44,24:[2,25],28:61,29:48,30:62,31:[1,45],32:[1,46],33:[1,47],34:43,35:49,36:[1,50],38:[1,27],39:26},{18:[2,26],24:[2,26]},{18:[2,30],24:[2,30],31:[2,30],32:[2,30],33:[2,30],36:[2,30],38:[2,30]},{18:[2,36],24:[2,36],35:63,36:[1,64]},{18:[2,31],24:[2,31],31:[2,31],32:[2,31],33:[2,31],36:[2,31],38:[2,31]},{18:[2,32],24:[2,32],31:[2,32],32:[2,32],33:[2,32],36:[2,32],38:[2,32]},{18:[2,33],24:[2,33],31:[2,33],32:[2,33],33:[2,33],36:[2,33],38:[2,33]},{18:[2,34],24:[2,34],31:[2,34],32:[2,34],33:[2,34],36:[2,34],38:[2,34]},{18:[2,35],24:[2,35],31:[2,35],32:[2,35],33:[2,35],36:[2,35],38:[2,35]},{18:[2,38],24:[2,38],36:[2,38]},{18:[2,50],24:[2,50],31:[2,50],32:[2,50],33:[2,50],36:[2,50],37:[1,65],38:[2,50],40:[2,50]},{36:[1,66]},{18:[2,47],24:[2,47],31:[2,47],32:[2,47],33:[2,47],36:[2,47],38:[2,47]},{5:[2,10],14:[2,10],15:[2,10],16:[2,10],19:[2,10],20:[2,10],22:[2,10],23:[2,10],25:[2,10]},{21:67,36:[1,28],39:26},{5:[2,11],14:[2,11],15:[2,11],16:[2,11],19:[2,11],20:[2,11],22:[2,11],23:[2,11],25:[2,11]},{14:[2,16],15:[2,16],16:[2,16],19:[2,16],20:[2,16],22:[2,16],23:[2,16],25:[2,16]},{5:[2,19],14:[2,19],15:[2,19],16:[2,19],19:[2,19],20:[2,19],22:[2,19],23:[2,19],25:[2,19]},{5:[2,20],14:[2,20],15:[2,20],16:[2,20],19:[2,20],20:[2,20],22:[2,20],23:[2,20],25:[2,20]},{5:[2,21],14:[2,21],15:[2,21],16:[2,21],19:[2,21],20:[2,21],22:[2,21],23:[2,21],25:[2,21]},{18:[1,68]},{18:[2,24],24:[2,24]},{18:[2,29],24:[2,29],31:[2,29],32:[2,29],33:[2,29],36:[2,29],38:[2,29]},{18:[2,37],24:[2,37],36:[2,37]},{37:[1,65]},{21:69,29:73,31:[1,70],32:[1,71],33:[1,72],36:[1,28],38:[1,27],39:26},{18:[2,49],24:[2,49],31:[2,49],32:[2,49],33:[2,49],36:[2,49],38:[2,49],40:[2,49]},{18:[1,74]},{5:[2,22],14:[2,22],15:[2,22],16:[2,22],19:[2,22],20:[2,22],22:[2,22],23:[2,22],25:[2,22]},{18:[2,39],24:[2,39],36:[2,39]},{18:[2,40],24:[2,40],36:[2,40]},{18:[2,41],24:[2,41],36:[2,41]},{18:[2,42],24:[2,42],36:[2,42]},{18:[2,43],24:[2,43],36:[2,43]},{5:[2,18],14:[2,18],15:[2,18],16:[2,18],19:[2,18],20:[2,18],22:[2,18],23:[2,18],25:[2,18]}],
304
- defaultActions: {17:[2,1]},
305
- parseError: function parseError(str, hash) {
306
- throw new Error(str);
307
- },
308
- parse: function parse(input) {
309
- var self = this, stack = [0], vstack = [null], lstack = [], table = this.table, yytext = "", yylineno = 0, yyleng = 0, recovering = 0, TERROR = 2, EOF = 1;
310
- this.lexer.setInput(input);
311
- this.lexer.yy = this.yy;
312
- this.yy.lexer = this.lexer;
313
- this.yy.parser = this;
314
- if (typeof this.lexer.yylloc == "undefined")
315
- this.lexer.yylloc = {};
316
- var yyloc = this.lexer.yylloc;
317
- lstack.push(yyloc);
318
- var ranges = this.lexer.options && this.lexer.options.ranges;
319
- if (typeof this.yy.parseError === "function")
320
- this.parseError = this.yy.parseError;
321
- function popStack(n) {
322
- stack.length = stack.length - 2 * n;
323
- vstack.length = vstack.length - n;
324
- lstack.length = lstack.length - n;
325
- }
326
- function lex() {
327
- var token;
328
- token = self.lexer.lex() || 1;
329
- if (typeof token !== "number") {
330
- token = self.symbols_[token] || token;
331
- }
332
- return token;
333
- }
334
- var symbol, preErrorSymbol, state, action, a, r, yyval = {}, p, len, newState, expected;
335
- while (true) {
336
- state = stack[stack.length - 1];
337
- if (this.defaultActions[state]) {
338
- action = this.defaultActions[state];
339
- } else {
340
- if (symbol === null || typeof symbol == "undefined") {
341
- symbol = lex();
342
- }
343
- action = table[state] && table[state][symbol];
344
- }
345
- if (typeof action === "undefined" || !action.length || !action[0]) {
346
- var errStr = "";
347
- if (!recovering) {
348
- expected = [];
349
- for (p in table[state])
350
- if (this.terminals_[p] && p > 2) {
351
- expected.push("'" + this.terminals_[p] + "'");
352
- }
353
- if (this.lexer.showPosition) {
354
- errStr = "Parse error on line " + (yylineno + 1) + ":\n" + this.lexer.showPosition() + "\nExpecting " + expected.join(", ") + ", got '" + (this.terminals_[symbol] || symbol) + "'";
355
- } else {
356
- errStr = "Parse error on line " + (yylineno + 1) + ": Unexpected " + (symbol == 1?"end of input":"'" + (this.terminals_[symbol] || symbol) + "'");
357
- }
358
- this.parseError(errStr, {text: this.lexer.match, token: this.terminals_[symbol] || symbol, line: this.lexer.yylineno, loc: yyloc, expected: expected});
359
- }
360
- }
361
- if (action[0] instanceof Array && action.length > 1) {
362
- throw new Error("Parse Error: multiple actions possible at state: " + state + ", token: " + symbol);
363
- }
364
- switch (action[0]) {
365
- case 1:
366
- stack.push(symbol);
367
- vstack.push(this.lexer.yytext);
368
- lstack.push(this.lexer.yylloc);
369
- stack.push(action[1]);
370
- symbol = null;
371
- if (!preErrorSymbol) {
372
- yyleng = this.lexer.yyleng;
373
- yytext = this.lexer.yytext;
374
- yylineno = this.lexer.yylineno;
375
- yyloc = this.lexer.yylloc;
376
- if (recovering > 0)
377
- recovering--;
378
- } else {
379
- symbol = preErrorSymbol;
380
- preErrorSymbol = null;
381
- }
382
- break;
383
- case 2:
384
- len = this.productions_[action[1]][1];
385
- yyval.$ = vstack[vstack.length - len];
386
- yyval._$ = {first_line: lstack[lstack.length - (len || 1)].first_line, last_line: lstack[lstack.length - 1].last_line, first_column: lstack[lstack.length - (len || 1)].first_column, last_column: lstack[lstack.length - 1].last_column};
387
- if (ranges) {
388
- yyval._$.range = [lstack[lstack.length - (len || 1)].range[0], lstack[lstack.length - 1].range[1]];
389
- }
390
- r = this.performAction.call(yyval, yytext, yyleng, yylineno, this.yy, action[1], vstack, lstack);
391
- if (typeof r !== "undefined") {
392
- return r;
393
- }
394
- if (len) {
395
- stack = stack.slice(0, -1 * len * 2);
396
- vstack = vstack.slice(0, -1 * len);
397
- lstack = lstack.slice(0, -1 * len);
398
- }
399
- stack.push(this.productions_[action[1]][0]);
400
- vstack.push(yyval.$);
401
- lstack.push(yyval._$);
402
- newState = table[stack[stack.length - 2]][stack[stack.length - 1]];
403
- stack.push(newState);
404
- break;
405
- case 3:
406
- return true;
407
- }
408
- }
409
- return true;
410
- }
411
- };
412
- /* Jison generated lexer */
413
- var lexer = (function(){
414
- var lexer = ({EOF:1,
415
- parseError:function parseError(str, hash) {
416
- if (this.yy.parser) {
417
- this.yy.parser.parseError(str, hash);
418
- } else {
419
- throw new Error(str);
420
- }
421
- },
422
- setInput:function (input) {
423
- this._input = input;
424
- this._more = this._less = this.done = false;
425
- this.yylineno = this.yyleng = 0;
426
- this.yytext = this.matched = this.match = '';
427
- this.conditionStack = ['INITIAL'];
428
- this.yylloc = {first_line:1,first_column:0,last_line:1,last_column:0};
429
- if (this.options.ranges) this.yylloc.range = [0,0];
430
- this.offset = 0;
431
- return this;
432
- },
433
- input:function () {
434
- var ch = this._input[0];
435
- this.yytext += ch;
436
- this.yyleng++;
437
- this.offset++;
438
- this.match += ch;
439
- this.matched += ch;
440
- var lines = ch.match(/(?:\r\n?|\n).*/g);
441
- if (lines) {
442
- this.yylineno++;
443
- this.yylloc.last_line++;
444
- } else {
445
- this.yylloc.last_column++;
446
- }
447
- if (this.options.ranges) this.yylloc.range[1]++;
448
-
449
- this._input = this._input.slice(1);
450
- return ch;
451
- },
452
- unput:function (ch) {
453
- var len = ch.length;
454
- var lines = ch.split(/(?:\r\n?|\n)/g);
455
-
456
- this._input = ch + this._input;
457
- this.yytext = this.yytext.substr(0, this.yytext.length-len-1);
458
- //this.yyleng -= len;
459
- this.offset -= len;
460
- var oldLines = this.match.split(/(?:\r\n?|\n)/g);
461
- this.match = this.match.substr(0, this.match.length-1);
462
- this.matched = this.matched.substr(0, this.matched.length-1);
463
-
464
- if (lines.length-1) this.yylineno -= lines.length-1;
465
- var r = this.yylloc.range;
466
-
467
- this.yylloc = {first_line: this.yylloc.first_line,
468
- last_line: this.yylineno+1,
469
- first_column: this.yylloc.first_column,
470
- last_column: lines ?
471
- (lines.length === oldLines.length ? this.yylloc.first_column : 0) + oldLines[oldLines.length - lines.length].length - lines[0].length:
472
- this.yylloc.first_column - len
473
- };
474
-
475
- if (this.options.ranges) {
476
- this.yylloc.range = [r[0], r[0] + this.yyleng - len];
477
- }
478
- return this;
479
- },
480
- more:function () {
481
- this._more = true;
482
- return this;
483
- },
484
- less:function (n) {
485
- this.unput(this.match.slice(n));
486
- },
487
- pastInput:function () {
488
- var past = this.matched.substr(0, this.matched.length - this.match.length);
489
- return (past.length > 20 ? '...':'') + past.substr(-20).replace(/\n/g, "");
490
- },
491
- upcomingInput:function () {
492
- var next = this.match;
493
- if (next.length < 20) {
494
- next += this._input.substr(0, 20-next.length);
495
- }
496
- return (next.substr(0,20)+(next.length > 20 ? '...':'')).replace(/\n/g, "");
497
- },
498
- showPosition:function () {
499
- var pre = this.pastInput();
500
- var c = new Array(pre.length + 1).join("-");
501
- return pre + this.upcomingInput() + "\n" + c+"^";
502
- },
503
- next:function () {
504
- if (this.done) {
505
- return this.EOF;
506
- }
507
- if (!this._input) this.done = true;
508
-
509
- var token,
510
- match,
511
- tempMatch,
512
- index,
513
- col,
514
- lines;
515
- if (!this._more) {
516
- this.yytext = '';
517
- this.match = '';
518
- }
519
- var rules = this._currentRules();
520
- for (var i=0;i < rules.length; i++) {
521
- tempMatch = this._input.match(this.rules[rules[i]]);
522
- if (tempMatch && (!match || tempMatch[0].length > match[0].length)) {
523
- match = tempMatch;
524
- index = i;
525
- if (!this.options.flex) break;
526
- }
527
- }
528
- if (match) {
529
- lines = match[0].match(/(?:\r\n?|\n).*/g);
530
- if (lines) this.yylineno += lines.length;
531
- this.yylloc = {first_line: this.yylloc.last_line,
532
- last_line: this.yylineno+1,
533
- first_column: this.yylloc.last_column,
534
- last_column: lines ? lines[lines.length-1].length-lines[lines.length-1].match(/\r?\n?/)[0].length : this.yylloc.last_column + match[0].length};
535
- this.yytext += match[0];
536
- this.match += match[0];
537
- this.matches = match;
538
- this.yyleng = this.yytext.length;
539
- if (this.options.ranges) {
540
- this.yylloc.range = [this.offset, this.offset += this.yyleng];
541
- }
542
- this._more = false;
543
- this._input = this._input.slice(match[0].length);
544
- this.matched += match[0];
545
- token = this.performAction.call(this, this.yy, this, rules[index],this.conditionStack[this.conditionStack.length-1]);
546
- if (this.done && this._input) this.done = false;
547
- if (token) return token;
548
- else return;
549
- }
550
- if (this._input === "") {
551
- return this.EOF;
552
- } else {
553
- return this.parseError('Lexical error on line '+(this.yylineno+1)+'. Unrecognized text.\n'+this.showPosition(),
554
- {text: "", token: null, line: this.yylineno});
555
- }
556
- },
557
- lex:function lex() {
558
- var r = this.next();
559
- if (typeof r !== 'undefined') {
560
- return r;
561
- } else {
562
- return this.lex();
563
- }
564
- },
565
- begin:function begin(condition) {
566
- this.conditionStack.push(condition);
567
- },
568
- popState:function popState() {
569
- return this.conditionStack.pop();
570
- },
571
- _currentRules:function _currentRules() {
572
- return this.conditions[this.conditionStack[this.conditionStack.length-1]].rules;
573
- },
574
- topState:function () {
575
- return this.conditionStack[this.conditionStack.length-2];
576
- },
577
- pushState:function begin(condition) {
578
- this.begin(condition);
579
- }});
580
- lexer.options = {};
581
- lexer.performAction = function anonymous(yy,yy_,$avoiding_name_collisions,YY_START) {
582
-
583
- var YYSTATE=YY_START
584
- switch($avoiding_name_collisions) {
585
- case 0: yy_.yytext = "\\"; return 14;
586
- break;
587
- case 1:
588
- if(yy_.yytext.slice(-1) !== "\\") this.begin("mu");
589
- if(yy_.yytext.slice(-1) === "\\") yy_.yytext = yy_.yytext.substr(0,yy_.yyleng-1), this.begin("emu");
590
- if(yy_.yytext) return 14;
591
-
592
- break;
593
- case 2: return 14;
594
- break;
595
- case 3:
596
- if(yy_.yytext.slice(-1) !== "\\") this.popState();
597
- if(yy_.yytext.slice(-1) === "\\") yy_.yytext = yy_.yytext.substr(0,yy_.yyleng-1);
598
- return 14;
599
-
600
- break;
601
- case 4: yy_.yytext = yy_.yytext.substr(0, yy_.yyleng-4); this.popState(); return 15;
602
- break;
603
- case 5: return 25;
604
- break;
605
- case 6: return 16;
606
- break;
607
- case 7: return 20;
608
- break;
609
- case 8: return 19;
610
- break;
611
- case 9: return 19;
612
- break;
613
- case 10: return 23;
614
- break;
615
- case 11: return 22;
616
- break;
617
- case 12: this.popState(); this.begin('com');
618
- break;
619
- case 13: yy_.yytext = yy_.yytext.substr(3,yy_.yyleng-5); this.popState(); return 15;
620
- break;
621
- case 14: return 22;
622
- break;
623
- case 15: return 37;
624
- break;
625
- case 16: return 36;
626
- break;
627
- case 17: return 36;
628
- break;
629
- case 18: return 40;
630
- break;
631
- case 19: /*ignore whitespace*/
632
- break;
633
- case 20: this.popState(); return 24;
634
- break;
635
- case 21: this.popState(); return 18;
636
- break;
637
- case 22: yy_.yytext = yy_.yytext.substr(1,yy_.yyleng-2).replace(/\\"/g,'"'); return 31;
638
- break;
639
- case 23: yy_.yytext = yy_.yytext.substr(1,yy_.yyleng-2).replace(/\\'/g,"'"); return 31;
640
- break;
641
- case 24: return 38;
642
- break;
643
- case 25: return 33;
644
- break;
645
- case 26: return 33;
646
- break;
647
- case 27: return 32;
648
- break;
649
- case 28: return 36;
650
- break;
651
- case 29: yy_.yytext = yy_.yytext.substr(1, yy_.yyleng-2); return 36;
652
- break;
653
- case 30: return 'INVALID';
654
- break;
655
- case 31: return 5;
656
- break;
657
- }
658
- };
659
- lexer.rules = [/^(?:\\\\(?=(\{\{)))/,/^(?:[^\x00]*?(?=(\{\{)))/,/^(?:[^\x00]+)/,/^(?:[^\x00]{2,}?(?=(\{\{|$)))/,/^(?:[\s\S]*?--\}\})/,/^(?:\{\{>)/,/^(?:\{\{#)/,/^(?:\{\{\/)/,/^(?:\{\{\^)/,/^(?:\{\{\s*else\b)/,/^(?:\{\{\{)/,/^(?:\{\{&)/,/^(?:\{\{!--)/,/^(?:\{\{![\s\S]*?\}\})/,/^(?:\{\{)/,/^(?:=)/,/^(?:\.(?=[}\/ ]))/,/^(?:\.\.)/,/^(?:[\/.])/,/^(?:\s+)/,/^(?:\}\}\})/,/^(?:\}\})/,/^(?:"(\\["]|[^"])*")/,/^(?:'(\\[']|[^'])*')/,/^(?:@)/,/^(?:true(?=[}\s]))/,/^(?:false(?=[}\s]))/,/^(?:-?[0-9]+(?=[}\s]))/,/^(?:[^\s!"#%-,\.\/;->@\[-\^`\{-~]+(?=[=}\s\/.]))/,/^(?:\[[^\]]*\])/,/^(?:.)/,/^(?:$)/];
660
- lexer.conditions = {"mu":{"rules":[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,31],"inclusive":false},"emu":{"rules":[3],"inclusive":false},"com":{"rules":[4],"inclusive":false},"INITIAL":{"rules":[0,1,2,31],"inclusive":true}};
661
- return lexer;})()
662
- parser.lexer = lexer;
663
- function Parser () { this.yy = {}; }Parser.prototype = parser;parser.Parser = Parser;
664
- return new Parser;
665
- })();;
666
- // lib/handlebars/compiler/base.js
667
-
668
- Handlebars.Parser = handlebars;
669
-
670
- Handlebars.parse = function(input) {
671
-
672
- // Just return if an already-compile AST was passed in.
673
- if(input.constructor === Handlebars.AST.ProgramNode) { return input; }
674
-
675
- Handlebars.Parser.yy = Handlebars.AST;
676
- return Handlebars.Parser.parse(input);
677
- };
678
- ;
679
- // lib/handlebars/compiler/ast.js
680
- Handlebars.AST = {};
681
-
682
- Handlebars.AST.ProgramNode = function(statements, inverse) {
683
- this.type = "program";
684
- this.statements = statements;
685
- if(inverse) { this.inverse = new Handlebars.AST.ProgramNode(inverse); }
686
- };
687
-
688
- Handlebars.AST.MustacheNode = function(rawParams, hash, unescaped) {
689
- this.type = "mustache";
690
- this.escaped = !unescaped;
691
- this.hash = hash;
692
-
693
- var id = this.id = rawParams[0];
694
- var params = this.params = rawParams.slice(1);
695
-
696
- // a mustache is an eligible helper if:
697
- // * its id is simple (a single part, not `this` or `..`)
698
- var eligibleHelper = this.eligibleHelper = id.isSimple;
699
-
700
- // a mustache is definitely a helper if:
701
- // * it is an eligible helper, and
702
- // * it has at least one parameter or hash segment
703
- this.isHelper = eligibleHelper && (params.length || hash);
704
-
705
- // if a mustache is an eligible helper but not a definite
706
- // helper, it is ambiguous, and will be resolved in a later
707
- // pass or at runtime.
708
- };
709
-
710
- Handlebars.AST.PartialNode = function(partialName, context) {
711
- this.type = "partial";
712
- this.partialName = partialName;
713
- this.context = context;
714
- };
715
-
716
- Handlebars.AST.BlockNode = function(mustache, program, inverse, close) {
717
- if(mustache.id.original !== close.original) {
718
- throw new Handlebars.Exception(mustache.id.original + " doesn't match " + close.original);
719
- }
720
-
721
- this.type = "block";
722
- this.mustache = mustache;
723
- this.program = program;
724
- this.inverse = inverse;
725
-
726
- if (this.inverse && !this.program) {
727
- this.isInverse = true;
728
- }
729
- };
730
-
731
- Handlebars.AST.ContentNode = function(string) {
732
- this.type = "content";
733
- this.string = string;
734
- };
735
-
736
- Handlebars.AST.HashNode = function(pairs) {
737
- this.type = "hash";
738
- this.pairs = pairs;
739
- };
740
-
741
- Handlebars.AST.IdNode = function(parts) {
742
- this.type = "ID";
743
-
744
- var original = "",
745
- dig = [],
746
- depth = 0;
747
-
748
- for(var i=0,l=parts.length; i<l; i++) {
749
- var part = parts[i].part;
750
- original += (parts[i].separator || '') + part;
751
-
752
- if (part === ".." || part === "." || part === "this") {
753
- if (dig.length > 0) { throw new Handlebars.Exception("Invalid path: " + original); }
754
- else if (part === "..") { depth++; }
755
- else { this.isScoped = true; }
756
- }
757
- else { dig.push(part); }
758
- }
759
-
760
- this.original = original;
761
- this.parts = dig;
762
- this.string = dig.join('.');
763
- this.depth = depth;
764
-
765
- // an ID is simple if it only has one part, and that part is not
766
- // `..` or `this`.
767
- this.isSimple = parts.length === 1 && !this.isScoped && depth === 0;
768
-
769
- this.stringModeValue = this.string;
770
- };
771
-
772
- Handlebars.AST.PartialNameNode = function(name) {
773
- this.type = "PARTIAL_NAME";
774
- this.name = name.original;
775
- };
776
-
777
- Handlebars.AST.DataNode = function(id) {
778
- this.type = "DATA";
779
- this.id = id;
780
- };
781
-
782
- Handlebars.AST.StringNode = function(string) {
783
- this.type = "STRING";
784
- this.original =
785
- this.string =
786
- this.stringModeValue = string;
787
- };
788
-
789
- Handlebars.AST.IntegerNode = function(integer) {
790
- this.type = "INTEGER";
791
- this.original =
792
- this.integer = integer;
793
- this.stringModeValue = Number(integer);
794
- };
795
-
796
- Handlebars.AST.BooleanNode = function(bool) {
797
- this.type = "BOOLEAN";
798
- this.bool = bool;
799
- this.stringModeValue = bool === "true";
800
- };
801
-
802
- Handlebars.AST.CommentNode = function(comment) {
803
- this.type = "comment";
804
- this.comment = comment;
805
- };
806
- ;
807
- // lib/handlebars/utils.js
808
-
809
- var errorProps = ['description', 'fileName', 'lineNumber', 'message', 'name', 'number', 'stack'];
810
-
811
- Handlebars.Exception = function(message) {
812
- var tmp = Error.prototype.constructor.apply(this, arguments);
813
-
814
- // Unfortunately errors are not enumerable in Chrome (at least), so `for prop in tmp` doesn't work.
815
- for (var idx = 0; idx < errorProps.length; idx++) {
816
- this[errorProps[idx]] = tmp[errorProps[idx]];
817
- }
818
- };
819
- Handlebars.Exception.prototype = new Error();
820
-
821
- // Build out our basic SafeString type
822
- Handlebars.SafeString = function(string) {
823
- this.string = string;
824
- };
825
- Handlebars.SafeString.prototype.toString = function() {
826
- return this.string.toString();
827
- };
828
-
829
- var escape = {
830
- "&": "&amp;",
831
- "<": "&lt;",
832
- ">": "&gt;",
833
- '"': "&quot;",
834
- "'": "&#x27;",
835
- "`": "&#x60;"
836
- };
837
-
838
- var badChars = /[&<>"'`]/g;
839
- var possible = /[&<>"'`]/;
840
-
841
- var escapeChar = function(chr) {
842
- return escape[chr] || "&amp;";
843
- };
844
-
845
- Handlebars.Utils = {
846
- extend: function(obj, value) {
847
- for(var key in value) {
848
- if(value.hasOwnProperty(key)) {
849
- obj[key] = value[key];
850
- }
851
- }
852
- },
853
-
854
- escapeExpression: function(string) {
855
- // don't escape SafeStrings, since they're already safe
856
- if (string instanceof Handlebars.SafeString) {
857
- return string.toString();
858
- } else if (string == null || string === false) {
859
- return "";
860
- }
861
-
862
- // Force a string conversion as this will be done by the append regardless and
863
- // the regex test will do this transparently behind the scenes, causing issues if
864
- // an object's to string has escaped characters in it.
865
- string = string.toString();
866
-
867
- if(!possible.test(string)) { return string; }
868
- return string.replace(badChars, escapeChar);
869
- },
870
-
871
- isEmpty: function(value) {
872
- if (!value && value !== 0) {
873
- return true;
874
- } else if(toString.call(value) === "[object Array]" && value.length === 0) {
875
- return true;
876
- } else {
877
- return false;
878
- }
879
- }
880
- };
881
- ;
882
- // lib/handlebars/compiler/compiler.js
883
-
884
- /*jshint eqnull:true*/
885
- var Compiler = Handlebars.Compiler = function() {};
886
-
887
- // the foundHelper register will disambiguate helper lookup from finding a
888
- // function in a context. This is necessary for mustache compatibility, which
889
- // requires that context functions in blocks are evaluated by blockHelperMissing,
890
- // and then proceed as if the resulting value was provided to blockHelperMissing.
891
-
892
- Compiler.prototype = {
893
- compiler: Compiler,
894
-
895
- disassemble: function() {
896
- var opcodes = this.opcodes, opcode, out = [], params, param;
897
-
898
- for (var i=0, l=opcodes.length; i<l; i++) {
899
- opcode = opcodes[i];
900
-
901
- if (opcode.opcode === 'DECLARE') {
902
- out.push("DECLARE " + opcode.name + "=" + opcode.value);
903
- } else {
904
- params = [];
905
- for (var j=0; j<opcode.args.length; j++) {
906
- param = opcode.args[j];
907
- if (typeof param === "string") {
908
- param = "\"" + param.replace("\n", "\\n") + "\"";
909
- }
910
- params.push(param);
911
- }
912
- out.push(opcode.opcode + " " + params.join(" "));
913
- }
914
- }
915
-
916
- return out.join("\n");
917
- },
918
- equals: function(other) {
919
- var len = this.opcodes.length;
920
- if (other.opcodes.length !== len) {
921
- return false;
922
- }
923
-
924
- for (var i = 0; i < len; i++) {
925
- var opcode = this.opcodes[i],
926
- otherOpcode = other.opcodes[i];
927
- if (opcode.opcode !== otherOpcode.opcode || opcode.args.length !== otherOpcode.args.length) {
928
- return false;
929
- }
930
- for (var j = 0; j < opcode.args.length; j++) {
931
- if (opcode.args[j] !== otherOpcode.args[j]) {
932
- return false;
933
- }
934
- }
935
- }
936
-
937
- len = this.children.length;
938
- if (other.children.length !== len) {
939
- return false;
940
- }
941
- for (i = 0; i < len; i++) {
942
- if (!this.children[i].equals(other.children[i])) {
943
- return false;
944
- }
945
- }
946
-
947
- return true;
948
- },
949
-
950
- guid: 0,
951
-
952
- compile: function(program, options) {
953
- this.children = [];
954
- this.depths = {list: []};
955
- this.options = options;
956
-
957
- // These changes will propagate to the other compiler components
958
- var knownHelpers = this.options.knownHelpers;
959
- this.options.knownHelpers = {
960
- 'helperMissing': true,
961
- 'blockHelperMissing': true,
962
- 'each': true,
963
- 'if': true,
964
- 'unless': true,
965
- 'with': true,
966
- 'log': true
967
- };
968
- if (knownHelpers) {
969
- for (var name in knownHelpers) {
970
- this.options.knownHelpers[name] = knownHelpers[name];
971
- }
972
- }
973
-
974
- return this.program(program);
975
- },
976
-
977
- accept: function(node) {
978
- return this[node.type](node);
979
- },
980
-
981
- program: function(program) {
982
- var statements = program.statements, statement;
983
- this.opcodes = [];
984
-
985
- for(var i=0, l=statements.length; i<l; i++) {
986
- statement = statements[i];
987
- this[statement.type](statement);
988
- }
989
- this.isSimple = l === 1;
990
-
991
- this.depths.list = this.depths.list.sort(function(a, b) {
992
- return a - b;
993
- });
994
-
995
- return this;
996
- },
997
-
998
- compileProgram: function(program) {
999
- var result = new this.compiler().compile(program, this.options);
1000
- var guid = this.guid++, depth;
1001
-
1002
- this.usePartial = this.usePartial || result.usePartial;
1003
-
1004
- this.children[guid] = result;
1005
-
1006
- for(var i=0, l=result.depths.list.length; i<l; i++) {
1007
- depth = result.depths.list[i];
1008
-
1009
- if(depth < 2) { continue; }
1010
- else { this.addDepth(depth - 1); }
1011
- }
1012
-
1013
- return guid;
1014
- },
1015
-
1016
- block: function(block) {
1017
- var mustache = block.mustache,
1018
- program = block.program,
1019
- inverse = block.inverse;
1020
-
1021
- if (program) {
1022
- program = this.compileProgram(program);
1023
- }
1024
-
1025
- if (inverse) {
1026
- inverse = this.compileProgram(inverse);
1027
- }
1028
-
1029
- var type = this.classifyMustache(mustache);
1030
-
1031
- if (type === "helper") {
1032
- this.helperMustache(mustache, program, inverse);
1033
- } else if (type === "simple") {
1034
- this.simpleMustache(mustache);
1035
-
1036
- // now that the simple mustache is resolved, we need to
1037
- // evaluate it by executing `blockHelperMissing`
1038
- this.opcode('pushProgram', program);
1039
- this.opcode('pushProgram', inverse);
1040
- this.opcode('emptyHash');
1041
- this.opcode('blockValue');
1042
- } else {
1043
- this.ambiguousMustache(mustache, program, inverse);
1044
-
1045
- // now that the simple mustache is resolved, we need to
1046
- // evaluate it by executing `blockHelperMissing`
1047
- this.opcode('pushProgram', program);
1048
- this.opcode('pushProgram', inverse);
1049
- this.opcode('emptyHash');
1050
- this.opcode('ambiguousBlockValue');
1051
- }
1052
-
1053
- this.opcode('append');
1054
- },
1055
-
1056
- hash: function(hash) {
1057
- var pairs = hash.pairs, pair, val;
1058
-
1059
- this.opcode('pushHash');
1060
-
1061
- for(var i=0, l=pairs.length; i<l; i++) {
1062
- pair = pairs[i];
1063
- val = pair[1];
1064
-
1065
- if (this.options.stringParams) {
1066
- if(val.depth) {
1067
- this.addDepth(val.depth);
1068
- }
1069
- this.opcode('getContext', val.depth || 0);
1070
- this.opcode('pushStringParam', val.stringModeValue, val.type);
1071
- } else {
1072
- this.accept(val);
1073
- }
1074
-
1075
- this.opcode('assignToHash', pair[0]);
1076
- }
1077
- this.opcode('popHash');
1078
- },
1079
-
1080
- partial: function(partial) {
1081
- var partialName = partial.partialName;
1082
- this.usePartial = true;
1083
-
1084
- if(partial.context) {
1085
- this.ID(partial.context);
1086
- } else {
1087
- this.opcode('push', 'depth0');
1088
- }
1089
-
1090
- this.opcode('invokePartial', partialName.name);
1091
- this.opcode('append');
1092
- },
1093
-
1094
- content: function(content) {
1095
- this.opcode('appendContent', content.string);
1096
- },
1097
-
1098
- mustache: function(mustache) {
1099
- var options = this.options;
1100
- var type = this.classifyMustache(mustache);
1101
-
1102
- if (type === "simple") {
1103
- this.simpleMustache(mustache);
1104
- } else if (type === "helper") {
1105
- this.helperMustache(mustache);
1106
- } else {
1107
- this.ambiguousMustache(mustache);
1108
- }
1109
-
1110
- if(mustache.escaped && !options.noEscape) {
1111
- this.opcode('appendEscaped');
1112
- } else {
1113
- this.opcode('append');
1114
- }
1115
- },
1116
-
1117
- ambiguousMustache: function(mustache, program, inverse) {
1118
- var id = mustache.id,
1119
- name = id.parts[0],
1120
- isBlock = program != null || inverse != null;
1121
-
1122
- this.opcode('getContext', id.depth);
1123
-
1124
- this.opcode('pushProgram', program);
1125
- this.opcode('pushProgram', inverse);
1126
-
1127
- this.opcode('invokeAmbiguous', name, isBlock);
1128
- },
1129
-
1130
- simpleMustache: function(mustache) {
1131
- var id = mustache.id;
1132
-
1133
- if (id.type === 'DATA') {
1134
- this.DATA(id);
1135
- } else if (id.parts.length) {
1136
- this.ID(id);
1137
- } else {
1138
- // Simplified ID for `this`
1139
- this.addDepth(id.depth);
1140
- this.opcode('getContext', id.depth);
1141
- this.opcode('pushContext');
1142
- }
1143
-
1144
- this.opcode('resolvePossibleLambda');
1145
- },
1146
-
1147
- helperMustache: function(mustache, program, inverse) {
1148
- var params = this.setupFullMustacheParams(mustache, program, inverse),
1149
- name = mustache.id.parts[0];
1150
-
1151
- if (this.options.knownHelpers[name]) {
1152
- this.opcode('invokeKnownHelper', params.length, name);
1153
- } else if (this.options.knownHelpersOnly) {
1154
- throw new Error("You specified knownHelpersOnly, but used the unknown helper " + name);
1155
- } else {
1156
- this.opcode('invokeHelper', params.length, name);
1157
- }
1158
- },
1159
-
1160
- ID: function(id) {
1161
- this.addDepth(id.depth);
1162
- this.opcode('getContext', id.depth);
1163
-
1164
- var name = id.parts[0];
1165
- if (!name) {
1166
- this.opcode('pushContext');
1167
- } else {
1168
- this.opcode('lookupOnContext', id.parts[0]);
1169
- }
1170
-
1171
- for(var i=1, l=id.parts.length; i<l; i++) {
1172
- this.opcode('lookup', id.parts[i]);
1173
- }
1174
- },
1175
-
1176
- DATA: function(data) {
1177
- this.options.data = true;
1178
- if (data.id.isScoped || data.id.depth) {
1179
- throw new Handlebars.Exception('Scoped data references are not supported: ' + data.original);
1180
- }
1181
-
1182
- this.opcode('lookupData');
1183
- var parts = data.id.parts;
1184
- for(var i=0, l=parts.length; i<l; i++) {
1185
- this.opcode('lookup', parts[i]);
1186
- }
1187
- },
1188
-
1189
- STRING: function(string) {
1190
- this.opcode('pushString', string.string);
1191
- },
1192
-
1193
- INTEGER: function(integer) {
1194
- this.opcode('pushLiteral', integer.integer);
1195
- },
1196
-
1197
- BOOLEAN: function(bool) {
1198
- this.opcode('pushLiteral', bool.bool);
1199
- },
1200
-
1201
- comment: function() {},
1202
-
1203
- // HELPERS
1204
- opcode: function(name) {
1205
- this.opcodes.push({ opcode: name, args: [].slice.call(arguments, 1) });
1206
- },
1207
-
1208
- declare: function(name, value) {
1209
- this.opcodes.push({ opcode: 'DECLARE', name: name, value: value });
1210
- },
1211
-
1212
- addDepth: function(depth) {
1213
- if(isNaN(depth)) { throw new Error("EWOT"); }
1214
- if(depth === 0) { return; }
1215
-
1216
- if(!this.depths[depth]) {
1217
- this.depths[depth] = true;
1218
- this.depths.list.push(depth);
1219
- }
1220
- },
1221
-
1222
- classifyMustache: function(mustache) {
1223
- var isHelper = mustache.isHelper;
1224
- var isEligible = mustache.eligibleHelper;
1225
- var options = this.options;
1226
-
1227
- // if ambiguous, we can possibly resolve the ambiguity now
1228
- if (isEligible && !isHelper) {
1229
- var name = mustache.id.parts[0];
1230
-
1231
- if (options.knownHelpers[name]) {
1232
- isHelper = true;
1233
- } else if (options.knownHelpersOnly) {
1234
- isEligible = false;
1235
- }
1236
- }
1237
-
1238
- if (isHelper) { return "helper"; }
1239
- else if (isEligible) { return "ambiguous"; }
1240
- else { return "simple"; }
1241
- },
1242
-
1243
- pushParams: function(params) {
1244
- var i = params.length, param;
1245
-
1246
- while(i--) {
1247
- param = params[i];
1248
-
1249
- if(this.options.stringParams) {
1250
- if(param.depth) {
1251
- this.addDepth(param.depth);
1252
- }
1253
-
1254
- this.opcode('getContext', param.depth || 0);
1255
- this.opcode('pushStringParam', param.stringModeValue, param.type);
1256
- } else {
1257
- this[param.type](param);
1258
- }
1259
- }
1260
- },
1261
-
1262
- setupMustacheParams: function(mustache) {
1263
- var params = mustache.params;
1264
- this.pushParams(params);
1265
-
1266
- if(mustache.hash) {
1267
- this.hash(mustache.hash);
1268
- } else {
1269
- this.opcode('emptyHash');
1270
- }
1271
-
1272
- return params;
1273
- },
1274
-
1275
- // this will replace setupMustacheParams when we're done
1276
- setupFullMustacheParams: function(mustache, program, inverse) {
1277
- var params = mustache.params;
1278
- this.pushParams(params);
1279
-
1280
- this.opcode('pushProgram', program);
1281
- this.opcode('pushProgram', inverse);
1282
-
1283
- if(mustache.hash) {
1284
- this.hash(mustache.hash);
1285
- } else {
1286
- this.opcode('emptyHash');
1287
- }
1288
-
1289
- return params;
1290
- }
1291
- };
1292
-
1293
- Handlebars.precompile = function(input, options) {
1294
- if (input == null || (typeof input !== 'string' && input.constructor !== Handlebars.AST.ProgramNode)) {
1295
- throw new Handlebars.Exception("You must pass a string or Handlebars AST to Handlebars.precompile. You passed " + input);
1296
- }
1297
-
1298
- options = options || {};
1299
- if (!('data' in options)) {
1300
- options.data = true;
1301
- }
1302
- var ast = Handlebars.parse(input);
1303
- var environment = new Compiler().compile(ast, options);
1304
- return new Handlebars.JavaScriptCompiler().compile(environment, options);
1305
- };
1306
-
1307
- Handlebars.compile = function(input, options) {
1308
- if (input == null || (typeof input !== 'string' && input.constructor !== Handlebars.AST.ProgramNode)) {
1309
- throw new Handlebars.Exception("You must pass a string or Handlebars AST to Handlebars.compile. You passed " + input);
1310
- }
1311
-
1312
- options = options || {};
1313
- if (!('data' in options)) {
1314
- options.data = true;
1315
- }
1316
- var compiled;
1317
- function compile() {
1318
- var ast = Handlebars.parse(input);
1319
- var environment = new Compiler().compile(ast, options);
1320
- var templateSpec = new Handlebars.JavaScriptCompiler().compile(environment, options, undefined, true);
1321
- return Handlebars.template(templateSpec);
1322
- }
1323
-
1324
- // Template is only compiled on first use and cached after that point.
1325
- return function(context, options) {
1326
- if (!compiled) {
1327
- compiled = compile();
1328
- }
1329
- return compiled.call(this, context, options);
1330
- };
1331
- };
1332
-
1333
- ;
1334
- // lib/handlebars/compiler/javascript-compiler.js
1335
- /*jshint eqnull:true*/
1336
-
1337
- var Literal = function(value) {
1338
- this.value = value;
1339
- };
1340
-
1341
-
1342
- var JavaScriptCompiler = Handlebars.JavaScriptCompiler = function() {};
1343
-
1344
- JavaScriptCompiler.prototype = {
1345
- // PUBLIC API: You can override these methods in a subclass to provide
1346
- // alternative compiled forms for name lookup and buffering semantics
1347
- nameLookup: function(parent, name /* , type*/) {
1348
- if (/^[0-9]+$/.test(name)) {
1349
- return parent + "[" + name + "]";
1350
- } else if (JavaScriptCompiler.isValidJavaScriptVariableName(name)) {
1351
- return parent + "." + name;
1352
- }
1353
- else {
1354
- return parent + "['" + name + "']";
1355
- }
1356
- },
1357
-
1358
- appendToBuffer: function(string) {
1359
- if (this.environment.isSimple) {
1360
- return "return " + string + ";";
1361
- } else {
1362
- return {
1363
- appendToBuffer: true,
1364
- content: string,
1365
- toString: function() { return "buffer += " + string + ";"; }
1366
- };
1367
- }
1368
- },
1369
-
1370
- initializeBuffer: function() {
1371
- return this.quotedString("");
1372
- },
1373
-
1374
- namespace: "Handlebars",
1375
- // END PUBLIC API
1376
-
1377
- compile: function(environment, options, context, asObject) {
1378
- this.environment = environment;
1379
- this.options = options || {};
1380
-
1381
- Handlebars.log(Handlebars.logger.DEBUG, this.environment.disassemble() + "\n\n");
1382
-
1383
- this.name = this.environment.name;
1384
- this.isChild = !!context;
1385
- this.context = context || {
1386
- programs: [],
1387
- environments: [],
1388
- aliases: { }
1389
- };
1390
-
1391
- this.preamble();
1392
-
1393
- this.stackSlot = 0;
1394
- this.stackVars = [];
1395
- this.registers = { list: [] };
1396
- this.compileStack = [];
1397
- this.inlineStack = [];
1398
-
1399
- this.compileChildren(environment, options);
1400
-
1401
- var opcodes = environment.opcodes, opcode;
1402
-
1403
- this.i = 0;
1404
-
1405
- for(var l=opcodes.length; this.i<l; this.i++) {
1406
- opcode = opcodes[this.i];
1407
-
1408
- if(opcode.opcode === 'DECLARE') {
1409
- this[opcode.name] = opcode.value;
1410
- } else {
1411
- this[opcode.opcode].apply(this, opcode.args);
1412
- }
1413
- }
1414
-
1415
- return this.createFunctionContext(asObject);
1416
- },
1417
-
1418
- nextOpcode: function() {
1419
- var opcodes = this.environment.opcodes;
1420
- return opcodes[this.i + 1];
1421
- },
1422
-
1423
- eat: function() {
1424
- this.i = this.i + 1;
1425
- },
1426
-
1427
- preamble: function() {
1428
- var out = [];
1429
-
1430
- if (!this.isChild) {
1431
- var namespace = this.namespace;
1432
-
1433
- var copies = "helpers = this.merge(helpers, " + namespace + ".helpers);";
1434
- if (this.environment.usePartial) { copies = copies + " partials = this.merge(partials, " + namespace + ".partials);"; }
1435
- if (this.options.data) { copies = copies + " data = data || {};"; }
1436
- out.push(copies);
1437
- } else {
1438
- out.push('');
1439
- }
1440
-
1441
- if (!this.environment.isSimple) {
1442
- out.push(", buffer = " + this.initializeBuffer());
1443
- } else {
1444
- out.push("");
1445
- }
1446
-
1447
- // track the last context pushed into place to allow skipping the
1448
- // getContext opcode when it would be a noop
1449
- this.lastContext = 0;
1450
- this.source = out;
1451
- },
1452
-
1453
- createFunctionContext: function(asObject) {
1454
- var locals = this.stackVars.concat(this.registers.list);
1455
-
1456
- if(locals.length > 0) {
1457
- this.source[1] = this.source[1] + ", " + locals.join(", ");
1458
- }
1459
-
1460
- // Generate minimizer alias mappings
1461
- if (!this.isChild) {
1462
- for (var alias in this.context.aliases) {
1463
- if (this.context.aliases.hasOwnProperty(alias)) {
1464
- this.source[1] = this.source[1] + ', ' + alias + '=' + this.context.aliases[alias];
1465
- }
1466
- }
1467
- }
1468
-
1469
- if (this.source[1]) {
1470
- this.source[1] = "var " + this.source[1].substring(2) + ";";
1471
- }
1472
-
1473
- // Merge children
1474
- if (!this.isChild) {
1475
- this.source[1] += '\n' + this.context.programs.join('\n') + '\n';
1476
- }
1477
-
1478
- if (!this.environment.isSimple) {
1479
- this.source.push("return buffer;");
1480
- }
1481
-
1482
- var params = this.isChild ? ["depth0", "data"] : ["Handlebars", "depth0", "helpers", "partials", "data"];
1483
-
1484
- for(var i=0, l=this.environment.depths.list.length; i<l; i++) {
1485
- params.push("depth" + this.environment.depths.list[i]);
1486
- }
1487
-
1488
- // Perform a second pass over the output to merge content when possible
1489
- var source = this.mergeSource();
1490
-
1491
- if (!this.isChild) {
1492
- var revision = Handlebars.COMPILER_REVISION,
1493
- versions = Handlebars.REVISION_CHANGES[revision];
1494
- source = "this.compilerInfo = ["+revision+",'"+versions+"'];\n"+source;
1495
- }
1496
-
1497
- if (asObject) {
1498
- params.push(source);
1499
-
1500
- return Function.apply(this, params);
1501
- } else {
1502
- var functionSource = 'function ' + (this.name || '') + '(' + params.join(',') + ') {\n ' + source + '}';
1503
- Handlebars.log(Handlebars.logger.DEBUG, functionSource + "\n\n");
1504
- return functionSource;
1505
- }
1506
- },
1507
- mergeSource: function() {
1508
- // WARN: We are not handling the case where buffer is still populated as the source should
1509
- // not have buffer append operations as their final action.
1510
- var source = '',
1511
- buffer;
1512
- for (var i = 0, len = this.source.length; i < len; i++) {
1513
- var line = this.source[i];
1514
- if (line.appendToBuffer) {
1515
- if (buffer) {
1516
- buffer = buffer + '\n + ' + line.content;
1517
- } else {
1518
- buffer = line.content;
1519
- }
1520
- } else {
1521
- if (buffer) {
1522
- source += 'buffer += ' + buffer + ';\n ';
1523
- buffer = undefined;
1524
- }
1525
- source += line + '\n ';
1526
- }
1527
- }
1528
- return source;
1529
- },
1530
-
1531
- // [blockValue]
1532
- //
1533
- // On stack, before: hash, inverse, program, value
1534
- // On stack, after: return value of blockHelperMissing
1535
- //
1536
- // The purpose of this opcode is to take a block of the form
1537
- // `{{#foo}}...{{/foo}}`, resolve the value of `foo`, and
1538
- // replace it on the stack with the result of properly
1539
- // invoking blockHelperMissing.
1540
- blockValue: function() {
1541
- this.context.aliases.blockHelperMissing = 'helpers.blockHelperMissing';
1542
-
1543
- var params = ["depth0"];
1544
- this.setupParams(0, params);
1545
-
1546
- this.replaceStack(function(current) {
1547
- params.splice(1, 0, current);
1548
- return "blockHelperMissing.call(" + params.join(", ") + ")";
1549
- });
1550
- },
1551
-
1552
- // [ambiguousBlockValue]
1553
- //
1554
- // On stack, before: hash, inverse, program, value
1555
- // Compiler value, before: lastHelper=value of last found helper, if any
1556
- // On stack, after, if no lastHelper: same as [blockValue]
1557
- // On stack, after, if lastHelper: value
1558
- ambiguousBlockValue: function() {
1559
- this.context.aliases.blockHelperMissing = 'helpers.blockHelperMissing';
1560
-
1561
- var params = ["depth0"];
1562
- this.setupParams(0, params);
1563
-
1564
- var current = this.topStack();
1565
- params.splice(1, 0, current);
1566
-
1567
- // Use the options value generated from the invocation
1568
- params[params.length-1] = 'options';
1569
-
1570
- this.source.push("if (!" + this.lastHelper + ") { " + current + " = blockHelperMissing.call(" + params.join(", ") + "); }");
1571
- },
1572
-
1573
- // [appendContent]
1574
- //
1575
- // On stack, before: ...
1576
- // On stack, after: ...
1577
- //
1578
- // Appends the string value of `content` to the current buffer
1579
- appendContent: function(content) {
1580
- this.source.push(this.appendToBuffer(this.quotedString(content)));
1581
- },
1582
-
1583
- // [append]
1584
- //
1585
- // On stack, before: value, ...
1586
- // On stack, after: ...
1587
- //
1588
- // Coerces `value` to a String and appends it to the current buffer.
1589
- //
1590
- // If `value` is truthy, or 0, it is coerced into a string and appended
1591
- // Otherwise, the empty string is appended
1592
- append: function() {
1593
- // Force anything that is inlined onto the stack so we don't have duplication
1594
- // when we examine local
1595
- this.flushInline();
1596
- var local = this.popStack();
1597
- this.source.push("if(" + local + " || " + local + " === 0) { " + this.appendToBuffer(local) + " }");
1598
- if (this.environment.isSimple) {
1599
- this.source.push("else { " + this.appendToBuffer("''") + " }");
1600
- }
1601
- },
1602
-
1603
- // [appendEscaped]
1604
- //
1605
- // On stack, before: value, ...
1606
- // On stack, after: ...
1607
- //
1608
- // Escape `value` and append it to the buffer
1609
- appendEscaped: function() {
1610
- this.context.aliases.escapeExpression = 'this.escapeExpression';
1611
-
1612
- this.source.push(this.appendToBuffer("escapeExpression(" + this.popStack() + ")"));
1613
- },
1614
-
1615
- // [getContext]
1616
- //
1617
- // On stack, before: ...
1618
- // On stack, after: ...
1619
- // Compiler value, after: lastContext=depth
1620
- //
1621
- // Set the value of the `lastContext` compiler value to the depth
1622
- getContext: function(depth) {
1623
- if(this.lastContext !== depth) {
1624
- this.lastContext = depth;
1625
- }
1626
- },
1627
-
1628
- // [lookupOnContext]
1629
- //
1630
- // On stack, before: ...
1631
- // On stack, after: currentContext[name], ...
1632
- //
1633
- // Looks up the value of `name` on the current context and pushes
1634
- // it onto the stack.
1635
- lookupOnContext: function(name) {
1636
- this.push(this.nameLookup('depth' + this.lastContext, name, 'context'));
1637
- },
1638
-
1639
- // [pushContext]
1640
- //
1641
- // On stack, before: ...
1642
- // On stack, after: currentContext, ...
1643
- //
1644
- // Pushes the value of the current context onto the stack.
1645
- pushContext: function() {
1646
- this.pushStackLiteral('depth' + this.lastContext);
1647
- },
1648
-
1649
- // [resolvePossibleLambda]
1650
- //
1651
- // On stack, before: value, ...
1652
- // On stack, after: resolved value, ...
1653
- //
1654
- // If the `value` is a lambda, replace it on the stack by
1655
- // the return value of the lambda
1656
- resolvePossibleLambda: function() {
1657
- this.context.aliases.functionType = '"function"';
1658
-
1659
- this.replaceStack(function(current) {
1660
- return "typeof " + current + " === functionType ? " + current + ".apply(depth0) : " + current;
1661
- });
1662
- },
1663
-
1664
- // [lookup]
1665
- //
1666
- // On stack, before: value, ...
1667
- // On stack, after: value[name], ...
1668
- //
1669
- // Replace the value on the stack with the result of looking
1670
- // up `name` on `value`
1671
- lookup: function(name) {
1672
- this.replaceStack(function(current) {
1673
- return current + " == null || " + current + " === false ? " + current + " : " + this.nameLookup(current, name, 'context');
1674
- });
1675
- },
1676
-
1677
- // [lookupData]
1678
- //
1679
- // On stack, before: ...
1680
- // On stack, after: data[id], ...
1681
- //
1682
- // Push the result of looking up `id` on the current data
1683
- lookupData: function(id) {
1684
- this.push('data');
1685
- },
1686
-
1687
- // [pushStringParam]
1688
- //
1689
- // On stack, before: ...
1690
- // On stack, after: string, currentContext, ...
1691
- //
1692
- // This opcode is designed for use in string mode, which
1693
- // provides the string value of a parameter along with its
1694
- // depth rather than resolving it immediately.
1695
- pushStringParam: function(string, type) {
1696
- this.pushStackLiteral('depth' + this.lastContext);
1697
-
1698
- this.pushString(type);
1699
-
1700
- if (typeof string === 'string') {
1701
- this.pushString(string);
1702
- } else {
1703
- this.pushStackLiteral(string);
1704
- }
1705
- },
1706
-
1707
- emptyHash: function() {
1708
- this.pushStackLiteral('{}');
1709
-
1710
- if (this.options.stringParams) {
1711
- this.register('hashTypes', '{}');
1712
- this.register('hashContexts', '{}');
1713
- }
1714
- },
1715
- pushHash: function() {
1716
- this.hash = {values: [], types: [], contexts: []};
1717
- },
1718
- popHash: function() {
1719
- var hash = this.hash;
1720
- this.hash = undefined;
1721
-
1722
- if (this.options.stringParams) {
1723
- this.register('hashContexts', '{' + hash.contexts.join(',') + '}');
1724
- this.register('hashTypes', '{' + hash.types.join(',') + '}');
1725
- }
1726
- this.push('{\n ' + hash.values.join(',\n ') + '\n }');
1727
- },
1728
-
1729
- // [pushString]
1730
- //
1731
- // On stack, before: ...
1732
- // On stack, after: quotedString(string), ...
1733
- //
1734
- // Push a quoted version of `string` onto the stack
1735
- pushString: function(string) {
1736
- this.pushStackLiteral(this.quotedString(string));
1737
- },
1738
-
1739
- // [push]
1740
- //
1741
- // On stack, before: ...
1742
- // On stack, after: expr, ...
1743
- //
1744
- // Push an expression onto the stack
1745
- push: function(expr) {
1746
- this.inlineStack.push(expr);
1747
- return expr;
1748
- },
1749
-
1750
- // [pushLiteral]
1751
- //
1752
- // On stack, before: ...
1753
- // On stack, after: value, ...
1754
- //
1755
- // Pushes a value onto the stack. This operation prevents
1756
- // the compiler from creating a temporary variable to hold
1757
- // it.
1758
- pushLiteral: function(value) {
1759
- this.pushStackLiteral(value);
1760
- },
1761
-
1762
- // [pushProgram]
1763
- //
1764
- // On stack, before: ...
1765
- // On stack, after: program(guid), ...
1766
- //
1767
- // Push a program expression onto the stack. This takes
1768
- // a compile-time guid and converts it into a runtime-accessible
1769
- // expression.
1770
- pushProgram: function(guid) {
1771
- if (guid != null) {
1772
- this.pushStackLiteral(this.programExpression(guid));
1773
- } else {
1774
- this.pushStackLiteral(null);
1775
- }
1776
- },
1777
-
1778
- // [invokeHelper]
1779
- //
1780
- // On stack, before: hash, inverse, program, params..., ...
1781
- // On stack, after: result of helper invocation
1782
- //
1783
- // Pops off the helper's parameters, invokes the helper,
1784
- // and pushes the helper's return value onto the stack.
1785
- //
1786
- // If the helper is not found, `helperMissing` is called.
1787
- invokeHelper: function(paramSize, name) {
1788
- this.context.aliases.helperMissing = 'helpers.helperMissing';
1789
-
1790
- var helper = this.lastHelper = this.setupHelper(paramSize, name, true);
1791
- var nonHelper = this.nameLookup('depth' + this.lastContext, name, 'context');
1792
-
1793
- this.push(helper.name + ' || ' + nonHelper);
1794
- this.replaceStack(function(name) {
1795
- return name + ' ? ' + name + '.call(' +
1796
- helper.callParams + ") " + ": helperMissing.call(" +
1797
- helper.helperMissingParams + ")";
1798
- });
1799
- },
1800
-
1801
- // [invokeKnownHelper]
1802
- //
1803
- // On stack, before: hash, inverse, program, params..., ...
1804
- // On stack, after: result of helper invocation
1805
- //
1806
- // This operation is used when the helper is known to exist,
1807
- // so a `helperMissing` fallback is not required.
1808
- invokeKnownHelper: function(paramSize, name) {
1809
- var helper = this.setupHelper(paramSize, name);
1810
- this.push(helper.name + ".call(" + helper.callParams + ")");
1811
- },
1812
-
1813
- // [invokeAmbiguous]
1814
- //
1815
- // On stack, before: hash, inverse, program, params..., ...
1816
- // On stack, after: result of disambiguation
1817
- //
1818
- // This operation is used when an expression like `{{foo}}`
1819
- // is provided, but we don't know at compile-time whether it
1820
- // is a helper or a path.
1821
- //
1822
- // This operation emits more code than the other options,
1823
- // and can be avoided by passing the `knownHelpers` and
1824
- // `knownHelpersOnly` flags at compile-time.
1825
- invokeAmbiguous: function(name, helperCall) {
1826
- this.context.aliases.functionType = '"function"';
1827
-
1828
- this.pushStackLiteral('{}'); // Hash value
1829
- var helper = this.setupHelper(0, name, helperCall);
1830
-
1831
- var helperName = this.lastHelper = this.nameLookup('helpers', name, 'helper');
1832
-
1833
- var nonHelper = this.nameLookup('depth' + this.lastContext, name, 'context');
1834
- var nextStack = this.nextStack();
1835
-
1836
- this.source.push('if (' + nextStack + ' = ' + helperName + ') { ' + nextStack + ' = ' + nextStack + '.call(' + helper.callParams + '); }');
1837
- this.source.push('else { ' + nextStack + ' = ' + nonHelper + '; ' + nextStack + ' = typeof ' + nextStack + ' === functionType ? ' + nextStack + '.apply(depth0) : ' + nextStack + '; }');
1838
- },
1839
-
1840
- // [invokePartial]
1841
- //
1842
- // On stack, before: context, ...
1843
- // On stack after: result of partial invocation
1844
- //
1845
- // This operation pops off a context, invokes a partial with that context,
1846
- // and pushes the result of the invocation back.
1847
- invokePartial: function(name) {
1848
- var params = [this.nameLookup('partials', name, 'partial'), "'" + name + "'", this.popStack(), "helpers", "partials"];
1849
-
1850
- if (this.options.data) {
1851
- params.push("data");
1852
- }
1853
-
1854
- this.context.aliases.self = "this";
1855
- this.push("self.invokePartial(" + params.join(", ") + ")");
1856
- },
1857
-
1858
- // [assignToHash]
1859
- //
1860
- // On stack, before: value, hash, ...
1861
- // On stack, after: hash, ...
1862
- //
1863
- // Pops a value and hash off the stack, assigns `hash[key] = value`
1864
- // and pushes the hash back onto the stack.
1865
- assignToHash: function(key) {
1866
- var value = this.popStack(),
1867
- context,
1868
- type;
1869
-
1870
- if (this.options.stringParams) {
1871
- type = this.popStack();
1872
- context = this.popStack();
1873
- }
1874
-
1875
- var hash = this.hash;
1876
- if (context) {
1877
- hash.contexts.push("'" + key + "': " + context);
1878
- }
1879
- if (type) {
1880
- hash.types.push("'" + key + "': " + type);
1881
- }
1882
- hash.values.push("'" + key + "': (" + value + ")");
1883
- },
1884
-
1885
- // HELPERS
1886
-
1887
- compiler: JavaScriptCompiler,
1888
-
1889
- compileChildren: function(environment, options) {
1890
- var children = environment.children, child, compiler;
1891
-
1892
- for(var i=0, l=children.length; i<l; i++) {
1893
- child = children[i];
1894
- compiler = new this.compiler();
1895
-
1896
- var index = this.matchExistingProgram(child);
1897
-
1898
- if (index == null) {
1899
- this.context.programs.push(''); // Placeholder to prevent name conflicts for nested children
1900
- index = this.context.programs.length;
1901
- child.index = index;
1902
- child.name = 'program' + index;
1903
- this.context.programs[index] = compiler.compile(child, options, this.context);
1904
- this.context.environments[index] = child;
1905
- } else {
1906
- child.index = index;
1907
- child.name = 'program' + index;
1908
- }
1909
- }
1910
- },
1911
- matchExistingProgram: function(child) {
1912
- for (var i = 0, len = this.context.environments.length; i < len; i++) {
1913
- var environment = this.context.environments[i];
1914
- if (environment && environment.equals(child)) {
1915
- return i;
1916
- }
1917
- }
1918
- },
1919
-
1920
- programExpression: function(guid) {
1921
- this.context.aliases.self = "this";
1922
-
1923
- if(guid == null) {
1924
- return "self.noop";
1925
- }
1926
-
1927
- var child = this.environment.children[guid],
1928
- depths = child.depths.list, depth;
1929
-
1930
- var programParams = [child.index, child.name, "data"];
1931
-
1932
- for(var i=0, l = depths.length; i<l; i++) {
1933
- depth = depths[i];
1934
-
1935
- if(depth === 1) { programParams.push("depth0"); }
1936
- else { programParams.push("depth" + (depth - 1)); }
1937
- }
1938
-
1939
- return (depths.length === 0 ? "self.program(" : "self.programWithDepth(") + programParams.join(", ") + ")";
1940
- },
1941
-
1942
- register: function(name, val) {
1943
- this.useRegister(name);
1944
- this.source.push(name + " = " + val + ";");
1945
- },
1946
-
1947
- useRegister: function(name) {
1948
- if(!this.registers[name]) {
1949
- this.registers[name] = true;
1950
- this.registers.list.push(name);
1951
- }
1952
- },
1953
-
1954
- pushStackLiteral: function(item) {
1955
- return this.push(new Literal(item));
1956
- },
1957
-
1958
- pushStack: function(item) {
1959
- this.flushInline();
1960
-
1961
- var stack = this.incrStack();
1962
- if (item) {
1963
- this.source.push(stack + " = " + item + ";");
1964
- }
1965
- this.compileStack.push(stack);
1966
- return stack;
1967
- },
1968
-
1969
- replaceStack: function(callback) {
1970
- var prefix = '',
1971
- inline = this.isInline(),
1972
- stack;
1973
-
1974
- // If we are currently inline then we want to merge the inline statement into the
1975
- // replacement statement via ','
1976
- if (inline) {
1977
- var top = this.popStack(true);
1978
-
1979
- if (top instanceof Literal) {
1980
- // Literals do not need to be inlined
1981
- stack = top.value;
1982
- } else {
1983
- // Get or create the current stack name for use by the inline
1984
- var name = this.stackSlot ? this.topStackName() : this.incrStack();
1985
-
1986
- prefix = '(' + this.push(name) + ' = ' + top + '),';
1987
- stack = this.topStack();
1988
- }
1989
- } else {
1990
- stack = this.topStack();
1991
- }
1992
-
1993
- var item = callback.call(this, stack);
1994
-
1995
- if (inline) {
1996
- if (this.inlineStack.length || this.compileStack.length) {
1997
- this.popStack();
1998
- }
1999
- this.push('(' + prefix + item + ')');
2000
- } else {
2001
- // Prevent modification of the context depth variable. Through replaceStack
2002
- if (!/^stack/.test(stack)) {
2003
- stack = this.nextStack();
2004
- }
2005
-
2006
- this.source.push(stack + " = (" + prefix + item + ");");
2007
- }
2008
- return stack;
2009
- },
2010
-
2011
- nextStack: function() {
2012
- return this.pushStack();
2013
- },
2014
-
2015
- incrStack: function() {
2016
- this.stackSlot++;
2017
- if(this.stackSlot > this.stackVars.length) { this.stackVars.push("stack" + this.stackSlot); }
2018
- return this.topStackName();
2019
- },
2020
- topStackName: function() {
2021
- return "stack" + this.stackSlot;
2022
- },
2023
- flushInline: function() {
2024
- var inlineStack = this.inlineStack;
2025
- if (inlineStack.length) {
2026
- this.inlineStack = [];
2027
- for (var i = 0, len = inlineStack.length; i < len; i++) {
2028
- var entry = inlineStack[i];
2029
- if (entry instanceof Literal) {
2030
- this.compileStack.push(entry);
2031
- } else {
2032
- this.pushStack(entry);
2033
- }
2034
- }
2035
- }
2036
- },
2037
- isInline: function() {
2038
- return this.inlineStack.length;
2039
- },
2040
-
2041
- popStack: function(wrapped) {
2042
- var inline = this.isInline(),
2043
- item = (inline ? this.inlineStack : this.compileStack).pop();
2044
-
2045
- if (!wrapped && (item instanceof Literal)) {
2046
- return item.value;
2047
- } else {
2048
- if (!inline) {
2049
- this.stackSlot--;
2050
- }
2051
- return item;
2052
- }
2053
- },
2054
-
2055
- topStack: function(wrapped) {
2056
- var stack = (this.isInline() ? this.inlineStack : this.compileStack),
2057
- item = stack[stack.length - 1];
2058
-
2059
- if (!wrapped && (item instanceof Literal)) {
2060
- return item.value;
2061
- } else {
2062
- return item;
2063
- }
2064
- },
2065
-
2066
- quotedString: function(str) {
2067
- return '"' + str
2068
- .replace(/\\/g, '\\\\')
2069
- .replace(/"/g, '\\"')
2070
- .replace(/\n/g, '\\n')
2071
- .replace(/\r/g, '\\r')
2072
- .replace(/\u2028/g, '\\u2028') // Per Ecma-262 7.3 + 7.8.4
2073
- .replace(/\u2029/g, '\\u2029') + '"';
2074
- },
2075
-
2076
- setupHelper: function(paramSize, name, missingParams) {
2077
- var params = [];
2078
- this.setupParams(paramSize, params, missingParams);
2079
- var foundHelper = this.nameLookup('helpers', name, 'helper');
2080
-
2081
- return {
2082
- params: params,
2083
- name: foundHelper,
2084
- callParams: ["depth0"].concat(params).join(", "),
2085
- helperMissingParams: missingParams && ["depth0", this.quotedString(name)].concat(params).join(", ")
2086
- };
2087
- },
2088
-
2089
- // the params and contexts arguments are passed in arrays
2090
- // to fill in
2091
- setupParams: function(paramSize, params, useRegister) {
2092
- var options = [], contexts = [], types = [], param, inverse, program;
2093
-
2094
- options.push("hash:" + this.popStack());
2095
-
2096
- inverse = this.popStack();
2097
- program = this.popStack();
2098
-
2099
- // Avoid setting fn and inverse if neither are set. This allows
2100
- // helpers to do a check for `if (options.fn)`
2101
- if (program || inverse) {
2102
- if (!program) {
2103
- this.context.aliases.self = "this";
2104
- program = "self.noop";
2105
- }
2106
-
2107
- if (!inverse) {
2108
- this.context.aliases.self = "this";
2109
- inverse = "self.noop";
2110
- }
2111
-
2112
- options.push("inverse:" + inverse);
2113
- options.push("fn:" + program);
2114
- }
2115
-
2116
- for(var i=0; i<paramSize; i++) {
2117
- param = this.popStack();
2118
- params.push(param);
2119
-
2120
- if(this.options.stringParams) {
2121
- types.push(this.popStack());
2122
- contexts.push(this.popStack());
2123
- }
2124
- }
2125
-
2126
- if (this.options.stringParams) {
2127
- options.push("contexts:[" + contexts.join(",") + "]");
2128
- options.push("types:[" + types.join(",") + "]");
2129
- options.push("hashContexts:hashContexts");
2130
- options.push("hashTypes:hashTypes");
2131
- }
2132
-
2133
- if(this.options.data) {
2134
- options.push("data:data");
2135
- }
2136
-
2137
- options = "{" + options.join(",") + "}";
2138
- if (useRegister) {
2139
- this.register('options', options);
2140
- params.push('options');
2141
- } else {
2142
- params.push(options);
2143
- }
2144
- return params.join(", ");
2145
- }
2146
- };
2147
-
2148
- var reservedWords = (
2149
- "break else new var" +
2150
- " case finally return void" +
2151
- " catch for switch while" +
2152
- " continue function this with" +
2153
- " default if throw" +
2154
- " delete in try" +
2155
- " do instanceof typeof" +
2156
- " abstract enum int short" +
2157
- " boolean export interface static" +
2158
- " byte extends long super" +
2159
- " char final native synchronized" +
2160
- " class float package throws" +
2161
- " const goto private transient" +
2162
- " debugger implements protected volatile" +
2163
- " double import public let yield"
2164
- ).split(" ");
2165
-
2166
- var compilerWords = JavaScriptCompiler.RESERVED_WORDS = {};
2167
-
2168
- for(var i=0, l=reservedWords.length; i<l; i++) {
2169
- compilerWords[reservedWords[i]] = true;
2170
- }
2171
-
2172
- JavaScriptCompiler.isValidJavaScriptVariableName = function(name) {
2173
- if(!JavaScriptCompiler.RESERVED_WORDS[name] && /^[a-zA-Z_$][0-9a-zA-Z_$]+$/.test(name)) {
2174
- return true;
2175
- }
2176
- return false;
2177
- };
2178
- ;
2179
- // lib/handlebars/runtime.js
2180
-
2181
- Handlebars.VM = {
2182
- template: function(templateSpec) {
2183
- // Just add water
2184
- var container = {
2185
- escapeExpression: Handlebars.Utils.escapeExpression,
2186
- invokePartial: Handlebars.VM.invokePartial,
2187
- programs: [],
2188
- program: function(i, fn, data) {
2189
- var programWrapper = this.programs[i];
2190
- if(data) {
2191
- programWrapper = Handlebars.VM.program(i, fn, data);
2192
- } else if (!programWrapper) {
2193
- programWrapper = this.programs[i] = Handlebars.VM.program(i, fn);
2194
- }
2195
- return programWrapper;
2196
- },
2197
- merge: function(param, common) {
2198
- var ret = param || common;
2199
-
2200
- if (param && common) {
2201
- ret = {};
2202
- Handlebars.Utils.extend(ret, common);
2203
- Handlebars.Utils.extend(ret, param);
2204
- }
2205
- return ret;
2206
- },
2207
- programWithDepth: Handlebars.VM.programWithDepth,
2208
- noop: Handlebars.VM.noop,
2209
- compilerInfo: null
2210
- };
2211
-
2212
- return function(context, options) {
2213
- options = options || {};
2214
- var result = templateSpec.call(container, Handlebars, context, options.helpers, options.partials, options.data);
2215
-
2216
- var compilerInfo = container.compilerInfo || [],
2217
- compilerRevision = compilerInfo[0] || 1,
2218
- currentRevision = Handlebars.COMPILER_REVISION;
2219
-
2220
- if (compilerRevision !== currentRevision) {
2221
- if (compilerRevision < currentRevision) {
2222
- var runtimeVersions = Handlebars.REVISION_CHANGES[currentRevision],
2223
- compilerVersions = Handlebars.REVISION_CHANGES[compilerRevision];
2224
- throw "Template was precompiled with an older version of Handlebars than the current runtime. "+
2225
- "Please update your precompiler to a newer version ("+runtimeVersions+") or downgrade your runtime to an older version ("+compilerVersions+").";
2226
- } else {
2227
- // Use the embedded version info since the runtime doesn't know about this revision yet
2228
- throw "Template was precompiled with a newer version of Handlebars than the current runtime. "+
2229
- "Please update your runtime to a newer version ("+compilerInfo[1]+").";
2230
- }
2231
- }
2232
-
2233
- return result;
2234
- };
2235
- },
2236
-
2237
- programWithDepth: function(i, fn, data /*, $depth */) {
2238
- var args = Array.prototype.slice.call(arguments, 3);
2239
-
2240
- var program = function(context, options) {
2241
- options = options || {};
2242
-
2243
- return fn.apply(this, [context, options.data || data].concat(args));
2244
- };
2245
- program.program = i;
2246
- program.depth = args.length;
2247
- return program;
2248
- },
2249
- program: function(i, fn, data) {
2250
- var program = function(context, options) {
2251
- options = options || {};
2252
-
2253
- return fn(context, options.data || data);
2254
- };
2255
- program.program = i;
2256
- program.depth = 0;
2257
- return program;
2258
- },
2259
- noop: function() { return ""; },
2260
- invokePartial: function(partial, name, context, helpers, partials, data) {
2261
- var options = { helpers: helpers, partials: partials, data: data };
2262
-
2263
- if(partial === undefined) {
2264
- throw new Handlebars.Exception("The partial " + name + " could not be found");
2265
- } else if(partial instanceof Function) {
2266
- return partial(context, options);
2267
- } else if (!Handlebars.compile) {
2268
- throw new Handlebars.Exception("The partial " + name + " could not be compiled when running in runtime-only mode");
2269
- } else {
2270
- partials[name] = Handlebars.compile(partial, {data: data !== undefined});
2271
- return partials[name](context, options);
2272
- }
2273
- }
2274
- };
2275
-
2276
- Handlebars.template = Handlebars.VM.template;
2277
- ;
2278
- // lib/handlebars/browser-suffix.js
2279
- if (typeof module === 'object' && module.exports) {
2280
- // CommonJS
2281
- module.exports = Handlebars;
2282
-
2283
- } else if (typeof define === "function" && define.amd) {
2284
- // AMD modules
2285
- define(function() { return Handlebars; });
2286
-
2287
- } else {
2288
- // other, i.e. browser
2289
- this.Handlebars = Handlebars;
2290
- }
2291
- }).call(this);
2292
- ;