barber-emblem 0.0.4 → 0.1.0

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