rasputin 0.11.3 → 0.12.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,1673 +0,0 @@
1
-
2
- var Handlebars = {};
3
- this.Handlebars = Handlebars;
4
-
5
- Handlebars.VERSION = "1.0.beta.2";
6
-
7
- Handlebars.helpers = {};
8
- Handlebars.partials = {};
9
-
10
- Handlebars.registerHelper = function(name, fn, inverse) {
11
- if(inverse) { fn.not = inverse; }
12
- this.helpers[name] = fn;
13
- };
14
-
15
- Handlebars.registerPartial = function(name, str) {
16
- this.partials[name] = str;
17
- };
18
-
19
- Handlebars.registerHelper('helperMissing', function(arg) {
20
- if(arguments.length === 2) {
21
- return undefined;
22
- } else {
23
- throw new Error("Could not find property '" + arg + "'");
24
- }
25
- });
26
-
27
- Handlebars.registerHelper('blockHelperMissing', function(context, options) {
28
- var inverse = options.inverse || function() {}, fn = options.fn;
29
-
30
-
31
- var ret = "";
32
- var type = Object.prototype.toString.call(context);
33
-
34
- if(type === "[object Function]") {
35
- context = context();
36
- }
37
-
38
- if(context === true) {
39
- return fn(this);
40
- } else if(context === false || context == null) {
41
- return inverse(this);
42
- } else if(type === "[object Array]") {
43
- if(context.length > 0) {
44
- for(var i=0, j=context.length; i<j; i++) {
45
- ret = ret + fn(context[i]);
46
- }
47
- } else {
48
- ret = inverse(this);
49
- }
50
- return ret;
51
- } else {
52
- return fn(context);
53
- }
54
- });
55
-
56
- Handlebars.registerHelper('each', function(context, options) {
57
- var fn = options.fn, inverse = options.inverse;
58
- var ret = "";
59
-
60
- if(context && context.length > 0) {
61
- for(var i=0, j=context.length; i<j; i++) {
62
- ret = ret + fn(context[i]);
63
- }
64
- } else {
65
- ret = inverse(this);
66
- }
67
- return ret;
68
- });
69
-
70
- Handlebars.registerHelper('if', function(context, options) {
71
- if(!context || Handlebars.Utils.isEmpty(context)) {
72
- return options.inverse(this);
73
- } else {
74
- return options.fn(this);
75
- }
76
- });
77
-
78
- Handlebars.registerHelper('unless', function(context, options) {
79
- var fn = options.fn, inverse = options.inverse;
80
- options.fn = inverse;
81
- options.inverse = fn;
82
-
83
- return Handlebars.helpers['if'].call(this, context, options);
84
- });
85
-
86
- Handlebars.registerHelper('with', function(context, options) {
87
- return options.fn(context);
88
- });
89
-
90
- Handlebars.registerHelper('log', function(context) {
91
- Handlebars.log(context);
92
- });
93
- ;
94
- // lib/handlebars/compiler/parser.js
95
- /* Jison generated parser */
96
- var handlebars = (function(){
97
-
98
- var parser = {trace: function trace() { },
99
- yy: {},
100
- symbols_: {"error":2,"root":3,"program":4,"EOF":5,"statements":6,"simpleInverse":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_UNEEmberAPED":23,"OPEN_PARTIAL":24,"params":25,"hash":26,"param":27,"STRING":28,"INTEGER":29,"BOOLEAN":30,"hashSegments":31,"hashSegment":32,"ID":33,"EQUALS":34,"pathSegments":35,"SEP":36,"$accept":0,"$end":1},
101
- terminals_: {2:"error",5:"EOF",14:"CONTENT",15:"COMMENT",16:"OPEN_BLOCK",18:"CLOSE",19:"OPEN_INVERSE",20:"OPEN_ENDBLOCK",22:"OPEN",23:"OPEN_UNEEmberAPED",24:"OPEN_PARTIAL",28:"STRING",29:"INTEGER",30:"BOOLEAN",33:"ID",34:"EQUALS",36:"SEP"},
102
- productions_: [0,[3,2],[4,3],[4,1],[4,0],[6,1],[6,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],[7,2],[17,3],[17,2],[17,2],[17,1],[25,2],[25,1],[27,1],[27,1],[27,1],[27,1],[26,1],[31,2],[31,1],[32,3],[32,3],[32,3],[32,3],[21,1],[35,3],[35,1]],
103
- performAction: function anonymous(yytext,yyleng,yylineno,yy,yystate,$$,_$) {
104
-
105
- var $0 = $$.length - 1;
106
- switch (yystate) {
107
- case 1: return $$[$0-1]
108
- break;
109
- case 2: this.$ = new yy.ProgramNode($$[$0-2], $$[$0])
110
- break;
111
- case 3: this.$ = new yy.ProgramNode($$[$0])
112
- break;
113
- case 4: this.$ = new yy.ProgramNode([])
114
- break;
115
- case 5: this.$ = [$$[$0]]
116
- break;
117
- case 6: $$[$0-1].push($$[$0]); this.$ = $$[$0-1]
118
- break;
119
- case 7: this.$ = new yy.InverseNode($$[$0-2], $$[$0-1], $$[$0])
120
- break;
121
- case 8: this.$ = new yy.BlockNode($$[$0-2], $$[$0-1], $$[$0])
122
- break;
123
- case 9: this.$ = $$[$0]
124
- break;
125
- case 10: this.$ = $$[$0]
126
- break;
127
- case 11: this.$ = new yy.ContentNode($$[$0])
128
- break;
129
- case 12: this.$ = new yy.CommentNode($$[$0])
130
- break;
131
- case 13: this.$ = new yy.MustacheNode($$[$0-1][0], $$[$0-1][1])
132
- break;
133
- case 14: this.$ = new yy.MustacheNode($$[$0-1][0], $$[$0-1][1])
134
- break;
135
- case 15: this.$ = $$[$0-1]
136
- break;
137
- case 16: this.$ = new yy.MustacheNode($$[$0-1][0], $$[$0-1][1])
138
- break;
139
- case 17: this.$ = new yy.MustacheNode($$[$0-1][0], $$[$0-1][1], true)
140
- break;
141
- case 18: this.$ = new yy.PartialNode($$[$0-1])
142
- break;
143
- case 19: this.$ = new yy.PartialNode($$[$0-2], $$[$0-1])
144
- break;
145
- case 20:
146
- break;
147
- case 21: this.$ = [[$$[$0-2]].concat($$[$0-1]), $$[$0]]
148
- break;
149
- case 22: this.$ = [[$$[$0-1]].concat($$[$0]), null]
150
- break;
151
- case 23: this.$ = [[$$[$0-1]], $$[$0]]
152
- break;
153
- case 24: this.$ = [[$$[$0]], null]
154
- break;
155
- case 25: $$[$0-1].push($$[$0]); this.$ = $$[$0-1];
156
- break;
157
- case 26: this.$ = [$$[$0]]
158
- break;
159
- case 27: this.$ = $$[$0]
160
- break;
161
- case 28: this.$ = new yy.StringNode($$[$0])
162
- break;
163
- case 29: this.$ = new yy.IntegerNode($$[$0])
164
- break;
165
- case 30: this.$ = new yy.BooleanNode($$[$0])
166
- break;
167
- case 31: this.$ = new yy.HashNode($$[$0])
168
- break;
169
- case 32: $$[$0-1].push($$[$0]); this.$ = $$[$0-1]
170
- break;
171
- case 33: this.$ = [$$[$0]]
172
- break;
173
- case 34: this.$ = [$$[$0-2], $$[$0]]
174
- break;
175
- case 35: this.$ = [$$[$0-2], new yy.StringNode($$[$0])]
176
- break;
177
- case 36: this.$ = [$$[$0-2], new yy.IntegerNode($$[$0])]
178
- break;
179
- case 37: this.$ = [$$[$0-2], new yy.BooleanNode($$[$0])]
180
- break;
181
- case 38: this.$ = new yy.IdNode($$[$0])
182
- break;
183
- case 39: $$[$0-2].push($$[$0]); this.$ = $$[$0-2];
184
- break;
185
- case 40: this.$ = [$$[$0]]
186
- break;
187
- }
188
- },
189
- table: [{3:1,4:2,5:[2,4],6:3,8:4,9:5,11:6,12:7,13:8,14:[1,9],15:[1,10],16:[1,12],19:[1,11],22:[1,13],23:[1,14],24:[1,15]},{1:[3]},{5:[1,16]},{5:[2,3],7:17,8:18,9:5,11:6,12:7,13:8,14:[1,9],15:[1,10],16:[1,12],19:[1,19],20:[2,3],22:[1,13],23:[1,14],24:[1,15]},{5:[2,5],14:[2,5],15:[2,5],16:[2,5],19:[2,5],20:[2,5],22:[2,5],23:[2,5],24:[2,5]},{4:20,6:3,8:4,9:5,11:6,12:7,13:8,14:[1,9],15:[1,10],16:[1,12],19:[1,11],20:[2,4],22:[1,13],23:[1,14],24:[1,15]},{4:21,6:3,8:4,9:5,11:6,12:7,13:8,14:[1,9],15:[1,10],16:[1,12],19:[1,11],20:[2,4],22:[1,13],23:[1,14],24:[1,15]},{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,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]},{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]},{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]},{17:22,21:23,33:[1,25],35:24},{17:26,21:23,33:[1,25],35:24},{17:27,21:23,33:[1,25],35:24},{17:28,21:23,33:[1,25],35:24},{21:29,33:[1,25],35:24},{1:[2,1]},{6:30,8:4,9:5,11:6,12:7,13:8,14:[1,9],15:[1,10],16:[1,12],19:[1,11],22:[1,13],23:[1,14],24:[1,15]},{5:[2,6],14:[2,6],15:[2,6],16:[2,6],19:[2,6],20:[2,6],22:[2,6],23:[2,6],24:[2,6]},{17:22,18:[1,31],21:23,33:[1,25],35:24},{10:32,20:[1,33]},{10:34,20:[1,33]},{18:[1,35]},{18:[2,24],21:40,25:36,26:37,27:38,28:[1,41],29:[1,42],30:[1,43],31:39,32:44,33:[1,45],35:24},{18:[2,38],28:[2,38],29:[2,38],30:[2,38],33:[2,38],36:[1,46]},{18:[2,40],28:[2,40],29:[2,40],30:[2,40],33:[2,40],36:[2,40]},{18:[1,47]},{18:[1,48]},{18:[1,49]},{18:[1,50],21:51,33:[1,25],35:24},{5:[2,2],8:18,9:5,11:6,12:7,13:8,14:[1,9],15:[1,10],16:[1,12],19:[1,11],20:[2,2],22:[1,13],23:[1,14],24:[1,15]},{14:[2,20],15:[2,20],16:[2,20],19:[2,20],22:[2,20],23:[2,20],24:[2,20]},{5:[2,7],14:[2,7],15:[2,7],16:[2,7],19:[2,7],20:[2,7],22:[2,7],23:[2,7],24:[2,7]},{21:52,33:[1,25],35:24},{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]},{14:[2,14],15:[2,14],16:[2,14],19:[2,14],20:[2,14],22:[2,14],23:[2,14],24:[2,14]},{18:[2,22],21:40,26:53,27:54,28:[1,41],29:[1,42],30:[1,43],31:39,32:44,33:[1,45],35:24},{18:[2,23]},{18:[2,26],28:[2,26],29:[2,26],30:[2,26],33:[2,26]},{18:[2,31],32:55,33:[1,56]},{18:[2,27],28:[2,27],29:[2,27],30:[2,27],33:[2,27]},{18:[2,28],28:[2,28],29:[2,28],30:[2,28],33:[2,28]},{18:[2,29],28:[2,29],29:[2,29],30:[2,29],33:[2,29]},{18:[2,30],28:[2,30],29:[2,30],30:[2,30],33:[2,30]},{18:[2,33],33:[2,33]},{18:[2,40],28:[2,40],29:[2,40],30:[2,40],33:[2,40],34:[1,57],36:[2,40]},{33:[1,58]},{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,16],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,17],14:[2,17],15:[2,17],16:[2,17],19:[2,17],20:[2,17],22:[2,17],23:[2,17],24:[2,17]},{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]},{18:[1,59]},{18:[1,60]},{18:[2,21]},{18:[2,25],28:[2,25],29:[2,25],30:[2,25],33:[2,25]},{18:[2,32],33:[2,32]},{34:[1,57]},{21:61,28:[1,62],29:[1,63],30:[1,64],33:[1,25],35:24},{18:[2,39],28:[2,39],29:[2,39],30:[2,39],33:[2,39],36:[2,39]},{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,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]},{18:[2,34],33:[2,34]},{18:[2,35],33:[2,35]},{18:[2,36],33:[2,36]},{18:[2,37],33:[2,37]}],
190
- defaultActions: {16:[2,1],37:[2,23],53:[2,21]},
191
- parseError: function parseError(str, hash) {
192
- throw new Error(str);
193
- },
194
- parse: function parse(input) {
195
- var self = this,
196
- stack = [0],
197
- vstack = [null], // semantic value stack
198
- lstack = [], // location stack
199
- table = this.table,
200
- yytext = '',
201
- yylineno = 0,
202
- yyleng = 0,
203
- recovering = 0,
204
- TERROR = 2,
205
- EOF = 1;
206
-
207
- //this.reductionCount = this.shiftCount = 0;
208
-
209
- this.lexer.setInput(input);
210
- this.lexer.yy = this.yy;
211
- this.yy.lexer = this.lexer;
212
- if (typeof this.lexer.yylloc == 'undefined')
213
- this.lexer.yylloc = {};
214
- var yyloc = this.lexer.yylloc;
215
- lstack.push(yyloc);
216
-
217
- if (typeof this.yy.parseError === 'function')
218
- this.parseError = this.yy.parseError;
219
-
220
- function popStack (n) {
221
- stack.length = stack.length - 2*n;
222
- vstack.length = vstack.length - n;
223
- lstack.length = lstack.length - n;
224
- }
225
-
226
- function lex() {
227
- var token;
228
- token = self.lexer.lex() || 1; // $end = 1
229
- // if token isn't its numeric value, convert
230
- if (typeof token !== 'number') {
231
- token = self.symbols_[token] || token;
232
- }
233
- return token;
234
- };
235
-
236
- var symbol, preErrorSymbol, state, action, a, r, yyval={},p,len,newState, expected;
237
- while (true) {
238
- // retreive state number from top of stack
239
- state = stack[stack.length-1];
240
-
241
- // use default actions if available
242
- if (this.defaultActions[state]) {
243
- action = this.defaultActions[state];
244
- } else {
245
- if (symbol == null)
246
- symbol = lex();
247
- // read action for current state and first input
248
- action = table[state] && table[state][symbol];
249
- }
250
-
251
- // handle parse error
252
- if (typeof action === 'undefined' || !action.length || !action[0]) {
253
-
254
- if (!recovering) {
255
- // Report error
256
- expected = [];
257
- for (p in table[state]) if (this.terminals_[p] && p > 2) {
258
- expected.push("'"+this.terminals_[p]+"'");
259
- }
260
- var errStr = '';
261
- if (this.lexer.showPosition) {
262
- errStr = 'Parse error on line '+(yylineno+1)+":\n"+this.lexer.showPosition()+'\nExpecting '+expected.join(', ');
263
- } else {
264
- errStr = 'Parse error on line '+(yylineno+1)+": Unexpected " +
265
- (symbol == 1 /*EOF*/ ? "end of input" :
266
- ("'"+(this.terminals_[symbol] || symbol)+"'"));
267
- }
268
- this.parseError(errStr,
269
- {text: this.lexer.match, token: this.terminals_[symbol] || symbol, line: this.lexer.yylineno, loc: yyloc, expected: expected});
270
- }
271
-
272
- // just recovered from another error
273
- if (recovering == 3) {
274
- if (symbol == EOF) {
275
- throw new Error(errStr || 'Parsing halted.');
276
- }
277
-
278
- // discard current lookahead and grab another
279
- yyleng = this.lexer.yyleng;
280
- yytext = this.lexer.yytext;
281
- yylineno = this.lexer.yylineno;
282
- yyloc = this.lexer.yylloc;
283
- symbol = lex();
284
- }
285
-
286
- // try to recover from error
287
- while (1) {
288
- // check for error recovery rule in this state
289
- if ((TERROR.toString()) in table[state]) {
290
- break;
291
- }
292
- if (state == 0) {
293
- throw new Error(errStr || 'Parsing halted.');
294
- }
295
- popStack(1);
296
- state = stack[stack.length-1];
297
- }
298
-
299
- preErrorSymbol = symbol; // save the lookahead token
300
- symbol = TERROR; // insert generic error symbol as new lookahead
301
- state = stack[stack.length-1];
302
- action = table[state] && table[state][TERROR];
303
- recovering = 3; // allow 3 real symbols to be shifted before reporting a new error
304
- }
305
-
306
- // this shouldn't happen, unless resolve defaults are off
307
- if (action[0] instanceof Array && action.length > 1) {
308
- throw new Error('Parse Error: multiple actions possible at state: '+state+', token: '+symbol);
309
- }
310
-
311
- switch (action[0]) {
312
-
313
- case 1: // shift
314
- //this.shiftCount++;
315
-
316
- stack.push(symbol);
317
- vstack.push(this.lexer.yytext);
318
- lstack.push(this.lexer.yylloc);
319
- stack.push(action[1]); // push state
320
- symbol = null;
321
- if (!preErrorSymbol) { // normal execution/no error
322
- yyleng = this.lexer.yyleng;
323
- yytext = this.lexer.yytext;
324
- yylineno = this.lexer.yylineno;
325
- yyloc = this.lexer.yylloc;
326
- if (recovering > 0)
327
- recovering--;
328
- } else { // error just occurred, resume old lookahead f/ before error
329
- symbol = preErrorSymbol;
330
- preErrorSymbol = null;
331
- }
332
- break;
333
-
334
- case 2: // reduce
335
- //this.reductionCount++;
336
-
337
- len = this.productions_[action[1]][1];
338
-
339
- // perform semantic action
340
- yyval.$ = vstack[vstack.length-len]; // default to $$ = $1
341
- // default location, uses first token for firsts, last for lasts
342
- yyval._$ = {
343
- first_line: lstack[lstack.length-(len||1)].first_line,
344
- last_line: lstack[lstack.length-1].last_line,
345
- first_column: lstack[lstack.length-(len||1)].first_column,
346
- last_column: lstack[lstack.length-1].last_column
347
- };
348
- r = this.performAction.call(yyval, yytext, yyleng, yylineno, this.yy, action[1], vstack, lstack);
349
-
350
- if (typeof r !== 'undefined') {
351
- return r;
352
- }
353
-
354
- // pop off stack
355
- if (len) {
356
- stack = stack.slice(0,-1*len*2);
357
- vstack = vstack.slice(0, -1*len);
358
- lstack = lstack.slice(0, -1*len);
359
- }
360
-
361
- stack.push(this.productions_[action[1]][0]); // push nonterminal (reduce)
362
- vstack.push(yyval.$);
363
- lstack.push(yyval._$);
364
- // goto new state = table[STATE][NONTERMINAL]
365
- newState = table[stack[stack.length-2]][stack[stack.length-1]];
366
- stack.push(newState);
367
- break;
368
-
369
- case 3: // accept
370
- return true;
371
- }
372
-
373
- }
374
-
375
- return true;
376
- }};/* Jison generated lexer */
377
- var lexer = (function(){
378
-
379
- var lexer = ({EOF:1,
380
- parseError:function parseError(str, hash) {
381
- if (this.yy.parseError) {
382
- this.yy.parseError(str, hash);
383
- } else {
384
- throw new Error(str);
385
- }
386
- },
387
- setInput:function (input) {
388
- this._input = input;
389
- this._more = this._less = this.done = false;
390
- this.yylineno = this.yyleng = 0;
391
- this.yytext = this.matched = this.match = '';
392
- this.conditionStack = ['INITIAL'];
393
- this.yylloc = {first_line:1,first_column:0,last_line:1,last_column:0};
394
- return this;
395
- },
396
- input:function () {
397
- var ch = this._input[0];
398
- this.yytext+=ch;
399
- this.yyleng++;
400
- this.match+=ch;
401
- this.matched+=ch;
402
- var lines = ch.match(/\n/);
403
- if (lines) this.yylineno++;
404
- this._input = this._input.slice(1);
405
- return ch;
406
- },
407
- unput:function (ch) {
408
- this._input = ch + this._input;
409
- return this;
410
- },
411
- more:function () {
412
- this._more = true;
413
- return this;
414
- },
415
- pastInput:function () {
416
- var past = this.matched.substr(0, this.matched.length - this.match.length);
417
- return (past.length > 20 ? '...':'') + past.substr(-20).replace(/\n/g, "");
418
- },
419
- upcomingInput:function () {
420
- var next = this.match;
421
- if (next.length < 20) {
422
- next += this._input.substr(0, 20-next.length);
423
- }
424
- return (next.substr(0,20)+(next.length > 20 ? '...':'')).replace(/\n/g, "");
425
- },
426
- showPosition:function () {
427
- var pre = this.pastInput();
428
- var c = new Array(pre.length + 1).join("-");
429
- return pre + this.upcomingInput() + "\n" + c+"^";
430
- },
431
- next:function () {
432
- if (this.done) {
433
- return this.EOF;
434
- }
435
- if (!this._input) this.done = true;
436
-
437
- var token,
438
- match,
439
- col,
440
- lines;
441
- if (!this._more) {
442
- this.yytext = '';
443
- this.match = '';
444
- }
445
- var rules = this._currentRules();
446
- for (var i=0;i < rules.length; i++) {
447
- match = this._input.match(this.rules[rules[i]]);
448
- if (match) {
449
- lines = match[0].match(/\n.*/g);
450
- if (lines) this.yylineno += lines.length;
451
- this.yylloc = {first_line: this.yylloc.last_line,
452
- last_line: this.yylineno+1,
453
- first_column: this.yylloc.last_column,
454
- last_column: lines ? lines[lines.length-1].length-1 : this.yylloc.last_column + match[0].length}
455
- this.yytext += match[0];
456
- this.match += match[0];
457
- this.matches = match;
458
- this.yyleng = this.yytext.length;
459
- this._more = false;
460
- this._input = this._input.slice(match[0].length);
461
- this.matched += match[0];
462
- token = this.performAction.call(this, this.yy, this, rules[i],this.conditionStack[this.conditionStack.length-1]);
463
- if (token) return token;
464
- else return;
465
- }
466
- }
467
- if (this._input === "") {
468
- return this.EOF;
469
- } else {
470
- this.parseError('Lexical error on line '+(this.yylineno+1)+'. Unrecognized text.\n'+this.showPosition(),
471
- {text: "", token: null, line: this.yylineno});
472
- }
473
- },
474
- lex:function lex() {
475
- var r = this.next();
476
- if (typeof r !== 'undefined') {
477
- return r;
478
- } else {
479
- return this.lex();
480
- }
481
- },
482
- begin:function begin(condition) {
483
- this.conditionStack.push(condition);
484
- },
485
- popState:function popState() {
486
- return this.conditionStack.pop();
487
- },
488
- _currentRules:function _currentRules() {
489
- return this.conditions[this.conditionStack[this.conditionStack.length-1]].rules;
490
- }});
491
- lexer.performAction = function anonymous(yy,yy_,$avoiding_name_collisions,YY_START) {
492
-
493
- var YYSTATE=YY_START
494
- switch($avoiding_name_collisions) {
495
- case 0: this.begin("mu"); if (yy_.yytext) return 14;
496
- break;
497
- case 1: return 14;
498
- break;
499
- case 2: return 24;
500
- break;
501
- case 3: return 16;
502
- break;
503
- case 4: return 20;
504
- break;
505
- case 5: return 19;
506
- break;
507
- case 6: return 19;
508
- break;
509
- case 7: return 23;
510
- break;
511
- case 8: return 23;
512
- break;
513
- case 9: yy_.yytext = yy_.yytext.substr(3,yy_.yyleng-5); this.begin("INITIAL"); return 15;
514
- break;
515
- case 10: return 22;
516
- break;
517
- case 11: return 34;
518
- break;
519
- case 12: return 33;
520
- break;
521
- case 13: return 33;
522
- break;
523
- case 14: return 36;
524
- break;
525
- case 15: /*ignore whitespace*/
526
- break;
527
- case 16: this.begin("INITIAL"); return 18;
528
- break;
529
- case 17: this.begin("INITIAL"); return 18;
530
- break;
531
- case 18: yy_.yytext = yy_.yytext.substr(1,yy_.yyleng-2).replace(/\\"/g,'"'); return 28;
532
- break;
533
- case 19: return 30;
534
- break;
535
- case 20: return 30;
536
- break;
537
- case 21: return 29;
538
- break;
539
- case 22: return 33;
540
- break;
541
- case 23: yy_.yytext = yy_.yytext.substr(1, yy_.yyleng-2); return 33;
542
- break;
543
- case 24: return 'INVALID';
544
- break;
545
- case 25: return 5;
546
- break;
547
- }
548
- };
549
- lexer.rules = [/^[^\x00]*?(?=(\{\{))/,/^[^\x00]+/,/^\{\{>/,/^\{\{#/,/^\{\{\//,/^\{\{\^/,/^\{\{\s*else\b/,/^\{\{\{/,/^\{\{&/,/^\{\{![\s\S]*?\}\}/,/^\{\{/,/^=/,/^\.(?=[} ])/,/^\.\./,/^[/.]/,/^\s+/,/^\}\}\}/,/^\}\}/,/^"(\\["]|[^"])*"/,/^true(?=[}\s])/,/^false(?=[}\s])/,/^[0-9]+(?=[}\s])/,/^[a-zA-Z0-9_$-]+(?=[=}\s/.])/,/^\[.*\]/,/^./,/^$/];
550
- lexer.conditions = {"mu":{"rules":[2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25],"inclusive":false},"INITIAL":{"rules":[0,1,25],"inclusive":true}};return lexer;})()
551
- parser.lexer = lexer;
552
- return parser;
553
- })();
554
- if (typeof require !== 'undefined' && typeof exports !== 'undefined') {
555
- exports.parser = handlebars;
556
- exports.parse = function () { return handlebars.parse.apply(handlebars, arguments); }
557
- exports.main = function commonjsMain(args) {
558
- if (!args[1])
559
- throw new Error('Usage: '+args[0]+' FILE');
560
- if (typeof process !== 'undefined') {
561
- var source = require('fs').readFileSync(require('path').join(process.cwd(), args[1]), "utf8");
562
- } else {
563
- var cwd = require("file").path(require("file").cwd());
564
- var source = cwd.join(args[1]).read({charset: "utf-8"});
565
- }
566
- return exports.parser.parse(source);
567
- }
568
- if (typeof module !== 'undefined' && require.main === module) {
569
- exports.main(typeof process !== 'undefined' ? process.argv.slice(1) : require("system").args);
570
- }
571
- };
572
- ;
573
- // lib/handlebars/compiler/base.js
574
- Handlebars.Parser = handlebars;
575
-
576
- Handlebars.parse = function(string) {
577
- Handlebars.Parser.yy = Handlebars.AST;
578
- return Handlebars.Parser.parse(string);
579
- };
580
-
581
- Handlebars.print = function(ast) {
582
- return new Handlebars.PrintVisitor().accept(ast);
583
- };
584
-
585
- Handlebars.logger = {
586
- DEBUG: 0, INFO: 1, WARN: 2, ERROR: 3, level: 3,
587
-
588
- // override in the host environment
589
- log: function(level, str) {}
590
- };
591
-
592
- Handlebars.log = function(level, str) { Handlebars.logger.log(level, str); };
593
- ;
594
- // lib/handlebars/compiler/ast.js
595
- (function() {
596
-
597
- Handlebars.AST = {};
598
-
599
- Handlebars.AST.ProgramNode = function(statements, inverse) {
600
- this.type = "program";
601
- this.statements = statements;
602
- if(inverse) { this.inverse = new Handlebars.AST.ProgramNode(inverse); }
603
- };
604
-
605
- Handlebars.AST.MustacheNode = function(params, hash, unescaped) {
606
- this.type = "mustache";
607
- this.id = params[0];
608
- this.params = params.slice(1);
609
- this.hash = hash;
610
- this.escaped = !unescaped;
611
- };
612
-
613
- Handlebars.AST.PartialNode = function(id, context) {
614
- this.type = "partial";
615
-
616
- // TODO: disallow complex IDs
617
-
618
- this.id = id;
619
- this.context = context;
620
- };
621
-
622
- var verifyMatch = function(open, close) {
623
- if(open.original !== close.original) {
624
- throw new Handlebars.Exception(open.original + " doesn't match " + close.original);
625
- }
626
- };
627
-
628
- Handlebars.AST.BlockNode = function(mustache, program, close) {
629
- verifyMatch(mustache.id, close);
630
- this.type = "block";
631
- this.mustache = mustache;
632
- this.program = program;
633
- };
634
-
635
- Handlebars.AST.InverseNode = function(mustache, program, close) {
636
- verifyMatch(mustache.id, close);
637
- this.type = "inverse";
638
- this.mustache = mustache;
639
- this.program = program;
640
- };
641
-
642
- Handlebars.AST.ContentNode = function(string) {
643
- this.type = "content";
644
- this.string = string;
645
- };
646
-
647
- Handlebars.AST.HashNode = function(pairs) {
648
- this.type = "hash";
649
- this.pairs = pairs;
650
- };
651
-
652
- Handlebars.AST.IdNode = function(parts) {
653
- this.type = "ID";
654
- this.original = parts.join(".");
655
-
656
- var dig = [], depth = 0;
657
-
658
- for(var i=0,l=parts.length; i<l; i++) {
659
- var part = parts[i];
660
-
661
- if(part === "..") { depth++; }
662
- else if(part === "." || part === "this") { this.isScoped = true; }
663
- else { dig.push(part); }
664
- }
665
-
666
- this.parts = dig;
667
- this.string = dig.join('.');
668
- this.depth = depth;
669
- this.isSimple = (dig.length === 1) && (depth === 0);
670
- };
671
-
672
- Handlebars.AST.StringNode = function(string) {
673
- this.type = "STRING";
674
- this.string = string;
675
- };
676
-
677
- Handlebars.AST.IntegerNode = function(integer) {
678
- this.type = "INTEGER";
679
- this.integer = integer;
680
- };
681
-
682
- Handlebars.AST.BooleanNode = function(bool) {
683
- this.type = "BOOLEAN";
684
- this.bool = bool;
685
- };
686
-
687
- Handlebars.AST.CommentNode = function(comment) {
688
- this.type = "comment";
689
- this.comment = comment;
690
- };
691
-
692
- })();;
693
- // lib/handlebars/utils.js
694
- Handlebars.Exception = function(message) {
695
- var tmp = Error.prototype.constructor.apply(this, arguments);
696
-
697
- for (var p in tmp) {
698
- if (tmp.hasOwnProperty(p)) { this[p] = tmp[p]; }
699
- }
700
- };
701
- Handlebars.Exception.prototype = new Error;
702
-
703
- // Build out our basic SafeString type
704
- Handlebars.SafeString = function(string) {
705
- this.string = string;
706
- };
707
- Handlebars.SafeString.prototype.toString = function() {
708
- return this.string.toString();
709
- };
710
-
711
- (function() {
712
- var escape = {
713
- "<": "&lt;",
714
- ">": "&gt;",
715
- '"': "&quot;",
716
- "'": "&#x27;",
717
- "`": "&#x60;"
718
- };
719
-
720
- var badChars = /&(?!\w+;)|[<>"'`]/g;
721
- var possible = /[&<>"'`]/;
722
-
723
- var escapeChar = function(chr) {
724
- return escape[chr] || "&amp;";
725
- };
726
-
727
- Handlebars.Utils = {
728
- escapeExpression: function(string) {
729
- // don't escape SafeStrings, since they're already safe
730
- if (string instanceof Handlebars.SafeString) {
731
- return string.toString();
732
- } else if (string == null || string === false) {
733
- return "";
734
- }
735
-
736
- if(!possible.test(string)) { return string; }
737
- return string.replace(badChars, escapeChar);
738
- },
739
-
740
- isEmpty: function(value) {
741
- if (typeof value === "undefined") {
742
- return true;
743
- } else if (value === null) {
744
- return true;
745
- } else if (value === false) {
746
- return true;
747
- } else if(Object.prototype.toString.call(value) === "[object Array]" && value.length === 0) {
748
- return true;
749
- } else {
750
- return false;
751
- }
752
- }
753
- };
754
- })();;
755
- // lib/handlebars/compiler/compiler.js
756
- Handlebars.Compiler = function() {};
757
- Handlebars.JavaScriptCompiler = function() {};
758
-
759
- (function(Compiler, JavaScriptCompiler) {
760
- Compiler.OPCODE_MAP = {
761
- appendContent: 1,
762
- getContext: 2,
763
- lookupWithHelpers: 3,
764
- lookup: 4,
765
- append: 5,
766
- invokeMustache: 6,
767
- appendEscaped: 7,
768
- pushString: 8,
769
- truthyOrFallback: 9,
770
- functionOrFallback: 10,
771
- invokeProgram: 11,
772
- invokePartial: 12,
773
- push: 13,
774
- assignToHash: 15,
775
- pushStringParam: 16
776
- };
777
-
778
- Compiler.MULTI_PARAM_OPCODES = {
779
- appendContent: 1,
780
- getContext: 1,
781
- lookupWithHelpers: 2,
782
- lookup: 1,
783
- invokeMustache: 3,
784
- pushString: 1,
785
- truthyOrFallback: 1,
786
- functionOrFallback: 1,
787
- invokeProgram: 3,
788
- invokePartial: 1,
789
- push: 1,
790
- assignToHash: 1,
791
- pushStringParam: 1
792
- };
793
-
794
- Compiler.DISASSEMBLE_MAP = {};
795
-
796
- for(var prop in Compiler.OPCODE_MAP) {
797
- var value = Compiler.OPCODE_MAP[prop];
798
- Compiler.DISASSEMBLE_MAP[value] = prop;
799
- }
800
-
801
- Compiler.multiParamSize = function(code) {
802
- return Compiler.MULTI_PARAM_OPCODES[Compiler.DISASSEMBLE_MAP[code]];
803
- };
804
-
805
- Compiler.prototype = {
806
- compiler: Compiler,
807
-
808
- disassemble: function() {
809
- var opcodes = this.opcodes, opcode, nextCode;
810
- var out = [], str, name, value;
811
-
812
- for(var i=0, l=opcodes.length; i<l; i++) {
813
- opcode = opcodes[i];
814
-
815
- if(opcode === 'DECLARE') {
816
- name = opcodes[++i];
817
- value = opcodes[++i];
818
- out.push("DECLARE " + name + " = " + value);
819
- } else {
820
- str = Compiler.DISASSEMBLE_MAP[opcode];
821
-
822
- var extraParams = Compiler.multiParamSize(opcode);
823
- var codes = [];
824
-
825
- for(var j=0; j<extraParams; j++) {
826
- nextCode = opcodes[++i];
827
-
828
- if(typeof nextCode === "string") {
829
- nextCode = "\"" + nextCode.replace("\n", "\\n") + "\"";
830
- }
831
-
832
- codes.push(nextCode);
833
- }
834
-
835
- str = str + " " + codes.join(" ");
836
-
837
- out.push(str);
838
- }
839
- }
840
-
841
- return out.join("\n");
842
- },
843
-
844
- guid: 0,
845
-
846
- compile: function(program, options) {
847
- this.children = [];
848
- this.depths = {list: []};
849
- this.options = options;
850
-
851
- // These changes will propagate to the other compiler components
852
- var knownHelpers = this.options.knownHelpers;
853
- this.options.knownHelpers = {
854
- 'helperMissing': true,
855
- 'blockHelperMissing': true,
856
- 'each': true,
857
- 'if': true,
858
- 'unless': true,
859
- 'with': true,
860
- 'log': true
861
- };
862
- if (knownHelpers) {
863
- for (var name in knownHelpers) {
864
- this.options.knownHelpers[name] = knownHelpers[name];
865
- }
866
- }
867
-
868
- return this.program(program);
869
- },
870
-
871
- accept: function(node) {
872
- return this[node.type](node);
873
- },
874
-
875
- program: function(program) {
876
- var statements = program.statements, statement;
877
- this.opcodes = [];
878
-
879
- for(var i=0, l=statements.length; i<l; i++) {
880
- statement = statements[i];
881
- this[statement.type](statement);
882
- }
883
- this.isSimple = l === 1;
884
-
885
- this.depths.list = this.depths.list.sort(function(a, b) {
886
- return a - b;
887
- });
888
-
889
- return this;
890
- },
891
-
892
- compileProgram: function(program) {
893
- var result = new this.compiler().compile(program, this.options);
894
- var guid = this.guid++;
895
-
896
- this.usePartial = this.usePartial || result.usePartial;
897
-
898
- this.children[guid] = result;
899
-
900
- for(var i=0, l=result.depths.list.length; i<l; i++) {
901
- depth = result.depths.list[i];
902
-
903
- if(depth < 2) { continue; }
904
- else { this.addDepth(depth - 1); }
905
- }
906
-
907
- return guid;
908
- },
909
-
910
- block: function(block) {
911
- var mustache = block.mustache;
912
- var depth, child, inverse, inverseGuid;
913
-
914
- var params = this.setupStackForMustache(mustache);
915
-
916
- var programGuid = this.compileProgram(block.program);
917
-
918
- if(block.program.inverse) {
919
- inverseGuid = this.compileProgram(block.program.inverse);
920
- this.declare('inverse', inverseGuid);
921
- }
922
-
923
- this.opcode('invokeProgram', programGuid, params.length, !!mustache.hash);
924
- this.declare('inverse', null);
925
- this.opcode('append');
926
- },
927
-
928
- inverse: function(block) {
929
- var params = this.setupStackForMustache(block.mustache);
930
-
931
- var programGuid = this.compileProgram(block.program);
932
-
933
- this.declare('inverse', programGuid);
934
-
935
- this.opcode('invokeProgram', null, params.length, !!block.mustache.hash);
936
- this.opcode('append');
937
- },
938
-
939
- hash: function(hash) {
940
- var pairs = hash.pairs, pair, val;
941
-
942
- this.opcode('push', '{}');
943
-
944
- for(var i=0, l=pairs.length; i<l; i++) {
945
- pair = pairs[i];
946
- val = pair[1];
947
-
948
- this.accept(val);
949
- this.opcode('assignToHash', pair[0]);
950
- }
951
- },
952
-
953
- partial: function(partial) {
954
- var id = partial.id;
955
- this.usePartial = true;
956
-
957
- if(partial.context) {
958
- this.ID(partial.context);
959
- } else {
960
- this.opcode('push', 'depth0');
961
- }
962
-
963
- this.opcode('invokePartial', id.original);
964
- this.opcode('append');
965
- },
966
-
967
- content: function(content) {
968
- this.opcode('appendContent', content.string);
969
- },
970
-
971
- mustache: function(mustache) {
972
- var params = this.setupStackForMustache(mustache);
973
-
974
- this.opcode('invokeMustache', params.length, mustache.id.original, !!mustache.hash);
975
-
976
- if(mustache.escaped) {
977
- this.opcode('appendEscaped');
978
- } else {
979
- this.opcode('append');
980
- }
981
- },
982
-
983
- ID: function(id) {
984
- this.addDepth(id.depth);
985
-
986
- this.opcode('getContext', id.depth);
987
-
988
- this.opcode('lookupWithHelpers', id.parts[0] || null, id.isScoped || false);
989
-
990
- for(var i=1, l=id.parts.length; i<l; i++) {
991
- this.opcode('lookup', id.parts[i]);
992
- }
993
- },
994
-
995
- STRING: function(string) {
996
- this.opcode('pushString', string.string);
997
- },
998
-
999
- INTEGER: function(integer) {
1000
- this.opcode('push', integer.integer);
1001
- },
1002
-
1003
- BOOLEAN: function(bool) {
1004
- this.opcode('push', bool.bool);
1005
- },
1006
-
1007
- comment: function() {},
1008
-
1009
- // HELPERS
1010
- pushParams: function(params) {
1011
- var i = params.length, param;
1012
-
1013
- while(i--) {
1014
- param = params[i];
1015
-
1016
- if(this.options.stringParams) {
1017
- if(param.depth) {
1018
- this.addDepth(param.depth);
1019
- }
1020
-
1021
- this.opcode('getContext', param.depth || 0);
1022
- this.opcode('pushStringParam', param.string);
1023
- } else {
1024
- this[param.type](param);
1025
- }
1026
- }
1027
- },
1028
-
1029
- opcode: function(name, val1, val2, val3) {
1030
- this.opcodes.push(Compiler.OPCODE_MAP[name]);
1031
- if(val1 !== undefined) { this.opcodes.push(val1); }
1032
- if(val2 !== undefined) { this.opcodes.push(val2); }
1033
- if(val3 !== undefined) { this.opcodes.push(val3); }
1034
- },
1035
-
1036
- declare: function(name, value) {
1037
- this.opcodes.push('DECLARE');
1038
- this.opcodes.push(name);
1039
- this.opcodes.push(value);
1040
- },
1041
-
1042
- addDepth: function(depth) {
1043
- if(depth === 0) { return; }
1044
-
1045
- if(!this.depths[depth]) {
1046
- this.depths[depth] = true;
1047
- this.depths.list.push(depth);
1048
- }
1049
- },
1050
-
1051
- setupStackForMustache: function(mustache) {
1052
- var params = mustache.params;
1053
-
1054
- this.pushParams(params);
1055
-
1056
- if(mustache.hash) {
1057
- this.hash(mustache.hash);
1058
- }
1059
-
1060
- this.ID(mustache.id);
1061
-
1062
- return params;
1063
- }
1064
- };
1065
-
1066
- JavaScriptCompiler.prototype = {
1067
- // PUBLIC API: You can override these methods in a subclass to provide
1068
- // alternative compiled forms for name lookup and buffering semantics
1069
- nameLookup: function(parent, name, type) {
1070
- if (/^[0-9]+$/.test(name)) {
1071
- return parent + "[" + name + "]";
1072
- } else if (JavaScriptCompiler.isValidJavaScriptVariableName(name)) {
1073
- return parent + "." + name;
1074
- }
1075
- else {
1076
- return parent + "['" + name + "']";
1077
- }
1078
- },
1079
-
1080
- appendToBuffer: function(string) {
1081
- if (this.environment.isSimple) {
1082
- return "return " + string + ";";
1083
- } else {
1084
- return "buffer += " + string + ";";
1085
- }
1086
- },
1087
-
1088
- initializeBuffer: function() {
1089
- return this.quotedString("");
1090
- },
1091
-
1092
- namespace: "Handlebars",
1093
- // END PUBLIC API
1094
-
1095
- compile: function(environment, options, context, asObject) {
1096
- this.environment = environment;
1097
- this.options = options || {};
1098
-
1099
- this.name = this.environment.name;
1100
- this.isChild = !!context;
1101
- this.context = context || {
1102
- programs: [],
1103
- aliases: { self: 'this' },
1104
- registers: {list: []}
1105
- };
1106
-
1107
- this.preamble();
1108
-
1109
- this.stackSlot = 0;
1110
- this.stackVars = [];
1111
-
1112
- this.compileChildren(environment, options);
1113
-
1114
- var opcodes = environment.opcodes, opcode;
1115
-
1116
- this.i = 0;
1117
-
1118
- for(l=opcodes.length; this.i<l; this.i++) {
1119
- opcode = this.nextOpcode(0);
1120
-
1121
- if(opcode[0] === 'DECLARE') {
1122
- this.i = this.i + 2;
1123
- this[opcode[1]] = opcode[2];
1124
- } else {
1125
- this.i = this.i + opcode[1].length;
1126
- this[opcode[0]].apply(this, opcode[1]);
1127
- }
1128
- }
1129
-
1130
- return this.createFunctionContext(asObject);
1131
- },
1132
-
1133
- nextOpcode: function(n) {
1134
- var opcodes = this.environment.opcodes, opcode = opcodes[this.i + n], name, val;
1135
- var extraParams, codes;
1136
-
1137
- if(opcode === 'DECLARE') {
1138
- name = opcodes[this.i + 1];
1139
- val = opcodes[this.i + 2];
1140
- return ['DECLARE', name, val];
1141
- } else {
1142
- name = Compiler.DISASSEMBLE_MAP[opcode];
1143
-
1144
- extraParams = Compiler.multiParamSize(opcode);
1145
- codes = [];
1146
-
1147
- for(var j=0; j<extraParams; j++) {
1148
- codes.push(opcodes[this.i + j + 1 + n]);
1149
- }
1150
-
1151
- return [name, codes];
1152
- }
1153
- },
1154
-
1155
- eat: function(opcode) {
1156
- this.i = this.i + opcode.length;
1157
- },
1158
-
1159
- preamble: function() {
1160
- var out = [];
1161
-
1162
- if (!this.isChild) {
1163
- var namespace = this.namespace;
1164
- var copies = "helpers = helpers || " + namespace + ".helpers;";
1165
- if(this.environment.usePartial) { copies = copies + " partials = partials || " + namespace + ".partials;"; }
1166
- out.push(copies);
1167
- } else {
1168
- out.push('');
1169
- }
1170
-
1171
- if (!this.environment.isSimple) {
1172
- out.push(", buffer = " + this.initializeBuffer());
1173
- } else {
1174
- out.push("");
1175
- }
1176
-
1177
- // track the last context pushed into place to allow skipping the
1178
- // getContext opcode when it would be a noop
1179
- this.lastContext = 0;
1180
- this.source = out;
1181
- },
1182
-
1183
- createFunctionContext: function(asObject) {
1184
- var locals = this.stackVars;
1185
- if (!this.isChild) {
1186
- locals = locals.concat(this.context.registers.list);
1187
- }
1188
-
1189
- if(locals.length > 0) {
1190
- this.source[1] = this.source[1] + ", " + locals.join(", ");
1191
- }
1192
-
1193
- // Generate minimizer alias mappings
1194
- if (!this.isChild) {
1195
- var aliases = []
1196
- for (var alias in this.context.aliases) {
1197
- this.source[1] = this.source[1] + ', ' + alias + '=' + this.context.aliases[alias];
1198
- }
1199
- }
1200
-
1201
- if (this.source[1]) {
1202
- this.source[1] = "var " + this.source[1].substring(2) + ";";
1203
- }
1204
-
1205
- // Merge children
1206
- if (!this.isChild) {
1207
- this.source[1] += '\n' + this.context.programs.join('\n') + '\n';
1208
- }
1209
-
1210
- if (!this.environment.isSimple) {
1211
- this.source.push("return buffer;");
1212
- }
1213
-
1214
- var params = this.isChild ? ["depth0", "data"] : ["Handlebars", "depth0", "helpers", "partials", "data"];
1215
-
1216
- for(var i=0, l=this.environment.depths.list.length; i<l; i++) {
1217
- params.push("depth" + this.environment.depths.list[i]);
1218
- }
1219
-
1220
- if (asObject) {
1221
- params.push(this.source.join("\n "));
1222
-
1223
- return Function.apply(this, params);
1224
- } else {
1225
- var functionSource = 'function ' + (this.name || '') + '(' + params.join(',') + ') {\n ' + this.source.join("\n ") + '}';
1226
- Handlebars.log(Handlebars.logger.DEBUG, functionSource + "\n\n");
1227
- return functionSource;
1228
- }
1229
- },
1230
-
1231
- appendContent: function(content) {
1232
- this.source.push(this.appendToBuffer(this.quotedString(content)));
1233
- },
1234
-
1235
- append: function() {
1236
- var local = this.popStack();
1237
- this.source.push("if(" + local + " || " + local + " === 0) { " + this.appendToBuffer(local) + " }");
1238
- if (this.environment.isSimple) {
1239
- this.source.push("else { " + this.appendToBuffer("''") + " }");
1240
- }
1241
- },
1242
-
1243
- appendEscaped: function() {
1244
- var opcode = this.nextOpcode(1), extra = "";
1245
- this.context.aliases.escapeExpression = 'this.escapeExpression';
1246
-
1247
- if(opcode[0] === 'appendContent') {
1248
- extra = " + " + this.quotedString(opcode[1][0]);
1249
- this.eat(opcode);
1250
- }
1251
-
1252
- this.source.push(this.appendToBuffer("escapeExpression(" + this.popStack() + ")" + extra));
1253
- },
1254
-
1255
- getContext: function(depth) {
1256
- if(this.lastContext !== depth) {
1257
- this.lastContext = depth;
1258
- }
1259
- },
1260
-
1261
- lookupWithHelpers: function(name, isScoped) {
1262
- if(name) {
1263
- var topStack = this.nextStack();
1264
-
1265
- this.usingKnownHelper = false;
1266
-
1267
- var toPush;
1268
- if (!isScoped && this.options.knownHelpers[name]) {
1269
- toPush = topStack + " = " + this.nameLookup('helpers', name, 'helper');
1270
- this.usingKnownHelper = true;
1271
- } else if (isScoped || this.options.knownHelpersOnly) {
1272
- toPush = topStack + " = " + this.nameLookup('depth' + this.lastContext, name, 'context');
1273
- } else {
1274
- toPush = topStack + " = "
1275
- + this.nameLookup('helpers', name, 'helper')
1276
- + " || "
1277
- + this.nameLookup('depth' + this.lastContext, name, 'context');
1278
- }
1279
-
1280
- toPush += ';';
1281
- this.source.push(toPush);
1282
- } else {
1283
- this.pushStack('depth' + this.lastContext);
1284
- }
1285
- },
1286
-
1287
- lookup: function(name) {
1288
- var topStack = this.topStack();
1289
- this.source.push(topStack + " = (" + topStack + " === null || " + topStack + " === undefined || " + topStack + " === false ? " +
1290
- topStack + " : " + this.nameLookup(topStack, name, 'context') + ");");
1291
- },
1292
-
1293
- pushStringParam: function(string) {
1294
- this.pushStack('depth' + this.lastContext);
1295
- this.pushString(string);
1296
- },
1297
-
1298
- pushString: function(string) {
1299
- this.pushStack(this.quotedString(string));
1300
- },
1301
-
1302
- push: function(name) {
1303
- this.pushStack(name);
1304
- },
1305
-
1306
- invokeMustache: function(paramSize, original, hasHash) {
1307
- this.populateParams(paramSize, this.quotedString(original), "{}", null, hasHash, function(nextStack, helperMissingString, id) {
1308
- if (!this.usingKnownHelper) {
1309
- this.context.aliases.helperMissing = 'helpers.helperMissing';
1310
- this.context.aliases.undef = 'void 0';
1311
- this.source.push("else if(" + id + "=== undef) { " + nextStack + " = helperMissing.call(" + helperMissingString + "); }");
1312
- if (nextStack !== id) {
1313
- this.source.push("else { " + nextStack + " = " + id + "; }");
1314
- }
1315
- }
1316
- });
1317
- },
1318
-
1319
- invokeProgram: function(guid, paramSize, hasHash) {
1320
- var inverse = this.programExpression(this.inverse);
1321
- var mainProgram = this.programExpression(guid);
1322
-
1323
- this.populateParams(paramSize, null, mainProgram, inverse, hasHash, function(nextStack, helperMissingString, id) {
1324
- if (!this.usingKnownHelper) {
1325
- this.context.aliases.blockHelperMissing = 'helpers.blockHelperMissing';
1326
- this.source.push("else { " + nextStack + " = blockHelperMissing.call(" + helperMissingString + "); }");
1327
- }
1328
- });
1329
- },
1330
-
1331
- populateParams: function(paramSize, helperId, program, inverse, hasHash, fn) {
1332
- var needsRegister = hasHash || this.options.stringParams || inverse || this.options.data;
1333
- var id = this.popStack(), nextStack;
1334
- var params = [], param, stringParam, stringOptions;
1335
-
1336
- if (needsRegister) {
1337
- this.register('tmp1', program);
1338
- stringOptions = 'tmp1';
1339
- } else {
1340
- stringOptions = '{ hash: {} }';
1341
- }
1342
-
1343
- if (needsRegister) {
1344
- var hash = (hasHash ? this.popStack() : '{}');
1345
- this.source.push('tmp1.hash = ' + hash + ';');
1346
- }
1347
-
1348
- if(this.options.stringParams) {
1349
- this.source.push('tmp1.contexts = [];');
1350
- }
1351
-
1352
- for(var i=0; i<paramSize; i++) {
1353
- param = this.popStack();
1354
- params.push(param);
1355
-
1356
- if(this.options.stringParams) {
1357
- this.source.push('tmp1.contexts.push(' + this.popStack() + ');');
1358
- }
1359
- }
1360
-
1361
- if(inverse) {
1362
- this.source.push('tmp1.fn = tmp1;');
1363
- this.source.push('tmp1.inverse = ' + inverse + ';');
1364
- }
1365
-
1366
- if(this.options.data) {
1367
- this.source.push('tmp1.data = data;');
1368
- }
1369
-
1370
- params.push(stringOptions);
1371
-
1372
- this.populateCall(params, id, helperId || id, fn);
1373
- },
1374
-
1375
- populateCall: function(params, id, helperId, fn) {
1376
- var paramString = ["depth0"].concat(params).join(", ");
1377
- var helperMissingString = ["depth0"].concat(helperId).concat(params).join(", ");
1378
-
1379
- var nextStack = this.nextStack();
1380
-
1381
- if (this.usingKnownHelper) {
1382
- this.source.push(nextStack + " = " + id + ".call(" + paramString + ");");
1383
- } else {
1384
- this.context.aliases.functionType = '"function"';
1385
- this.source.push("if(typeof " + id + " === functionType) { " + nextStack + " = " + id + ".call(" + paramString + "); }");
1386
- }
1387
- fn.call(this, nextStack, helperMissingString, id);
1388
- this.usingKnownHelper = false;
1389
- },
1390
-
1391
- invokePartial: function(context) {
1392
- this.pushStack("self.invokePartial(" + this.nameLookup('partials', context, 'partial') + ", '" + context + "', " + this.popStack() + ", helpers, partials);");
1393
- },
1394
-
1395
- assignToHash: function(key) {
1396
- var value = this.popStack();
1397
- var hash = this.topStack();
1398
-
1399
- this.source.push(hash + "['" + key + "'] = " + value + ";");
1400
- },
1401
-
1402
- // HELPERS
1403
-
1404
- compiler: JavaScriptCompiler,
1405
-
1406
- compileChildren: function(environment, options) {
1407
- var children = environment.children, child, compiler;
1408
-
1409
- for(var i=0, l=children.length; i<l; i++) {
1410
- child = children[i];
1411
- compiler = new this.compiler();
1412
-
1413
- this.context.programs.push(''); // Placeholder to prevent name conflicts for nested children
1414
- var index = this.context.programs.length;
1415
- child.index = index;
1416
- child.name = 'program' + index;
1417
- this.context.programs[index] = compiler.compile(child, options, this.context);
1418
- }
1419
- },
1420
-
1421
- programExpression: function(guid) {
1422
- if(guid == null) { return "self.noop"; }
1423
-
1424
- var child = this.environment.children[guid],
1425
- depths = child.depths.list;
1426
- var programParams = [child.index, child.name, "data"];
1427
-
1428
- for(var i=0, l = depths.length; i<l; i++) {
1429
- depth = depths[i];
1430
-
1431
- if(depth === 1) { programParams.push("depth0"); }
1432
- else { programParams.push("depth" + (depth - 1)); }
1433
- }
1434
-
1435
- if(depths.length === 0) {
1436
- return "self.program(" + programParams.join(", ") + ")";
1437
- } else {
1438
- programParams.shift();
1439
- return "self.programWithDepth(" + programParams.join(", ") + ")";
1440
- }
1441
- },
1442
-
1443
- register: function(name, val) {
1444
- this.useRegister(name);
1445
- this.source.push(name + " = " + val + ";");
1446
- },
1447
-
1448
- useRegister: function(name) {
1449
- if(!this.context.registers[name]) {
1450
- this.context.registers[name] = true;
1451
- this.context.registers.list.push(name);
1452
- }
1453
- },
1454
-
1455
- pushStack: function(item) {
1456
- this.source.push(this.nextStack() + " = " + item + ";");
1457
- return "stack" + this.stackSlot;
1458
- },
1459
-
1460
- nextStack: function() {
1461
- this.stackSlot++;
1462
- if(this.stackSlot > this.stackVars.length) { this.stackVars.push("stack" + this.stackSlot); }
1463
- return "stack" + this.stackSlot;
1464
- },
1465
-
1466
- popStack: function() {
1467
- return "stack" + this.stackSlot--;
1468
- },
1469
-
1470
- topStack: function() {
1471
- return "stack" + this.stackSlot;
1472
- },
1473
-
1474
- quotedString: function(str) {
1475
- return '"' + str
1476
- .replace(/\\/g, '\\\\')
1477
- .replace(/"/g, '\\"')
1478
- .replace(/\n/g, '\\n')
1479
- .replace(/\r/g, '\\r') + '"';
1480
- }
1481
- };
1482
-
1483
- var reservedWords = ("break case catch continue default delete do else finally " +
1484
- "for function if in instanceof new return switch this throw " +
1485
- "try typeof var void while with null true false").split(" ");
1486
-
1487
- var compilerWords = JavaScriptCompiler.RESERVED_WORDS = {};
1488
-
1489
- for(var i=0, l=reservedWords.length; i<l; i++) {
1490
- compilerWords[reservedWords[i]] = true;
1491
- }
1492
-
1493
- JavaScriptCompiler.isValidJavaScriptVariableName = function(name) {
1494
- if(!JavaScriptCompiler.RESERVED_WORDS[name] && /^[a-zA-Z_$][0-9a-zA-Z_$]+$/.test(name)) {
1495
- return true;
1496
- }
1497
- return false;
1498
- }
1499
-
1500
- })(Handlebars.Compiler, Handlebars.JavaScriptCompiler);
1501
-
1502
- Handlebars.precompile = function(string, options) {
1503
- options = options || {};
1504
-
1505
- var ast = Handlebars.parse(string);
1506
- var environment = new Handlebars.Compiler().compile(ast, options);
1507
- return new Handlebars.JavaScriptCompiler().compile(environment, options);
1508
- };
1509
-
1510
- Handlebars.compile = function(string, options) {
1511
- options = options || {};
1512
-
1513
- var compiled;
1514
- function compile() {
1515
- var ast = Handlebars.parse(string);
1516
- var environment = new Handlebars.Compiler().compile(ast, options);
1517
- var templateSpec = new Handlebars.JavaScriptCompiler().compile(environment, options, undefined, true);
1518
- return Handlebars.template(templateSpec);
1519
- }
1520
-
1521
- // Template is only compiled on first use and cached after that point.
1522
- return function(context, options) {
1523
- if (!compiled) {
1524
- compiled = compile();
1525
- }
1526
- return compiled.call(this, context, options);
1527
- };
1528
- };
1529
- ;
1530
- // lib/handlebars/vm.js
1531
- Handlebars.VM = {
1532
- template: function(templateSpec) {
1533
- // Just add water
1534
- var container = {
1535
- escapeExpression: Handlebars.Utils.escapeExpression,
1536
- invokePartial: Handlebars.VM.invokePartial,
1537
- programs: [],
1538
- program: function(i, fn, data) {
1539
- var programWrapper = this.programs[i];
1540
- if(data) {
1541
- return Handlebars.VM.program(fn, data);
1542
- } else if(programWrapper) {
1543
- return programWrapper;
1544
- } else {
1545
- programWrapper = this.programs[i] = Handlebars.VM.program(fn);
1546
- return programWrapper;
1547
- }
1548
- },
1549
- programWithDepth: Handlebars.VM.programWithDepth,
1550
- noop: Handlebars.VM.noop
1551
- };
1552
-
1553
- return function(context, options) {
1554
- options = options || {};
1555
- return templateSpec.call(container, Handlebars, context, options.helpers, options.partials, options.data);
1556
- };
1557
- },
1558
-
1559
- programWithDepth: function(fn, data, $depth) {
1560
- var args = Array.prototype.slice.call(arguments, 2);
1561
-
1562
- return function(context, options) {
1563
- options = options || {};
1564
-
1565
- return fn.apply(this, [context, options.data || data].concat(args));
1566
- };
1567
- },
1568
- program: function(fn, data) {
1569
- return function(context, options) {
1570
- options = options || {};
1571
-
1572
- return fn(context, options.data || data);
1573
- };
1574
- },
1575
- noop: function() { return ""; },
1576
- invokePartial: function(partial, name, context, helpers, partials) {
1577
- if(partial === undefined) {
1578
- throw new Handlebars.Exception("The partial " + name + " could not be found");
1579
- } else if(partial instanceof Function) {
1580
- return partial(context, {helpers: helpers, partials: partials});
1581
- } else if (!Handlebars.compile) {
1582
- throw new Handlebars.Exception("The partial " + name + " could not be compiled when running in vm mode");
1583
- } else {
1584
- partials[name] = Handlebars.compile(partial);
1585
- return partials[name](context, {helpers: helpers, partials: partials});
1586
- }
1587
- }
1588
- };
1589
-
1590
- Handlebars.template = Handlebars.VM.template;
1591
-
1592
- /*
1593
- @SlexAxton
1594
- https://github.com/SlexAxton/sc-handlebars
1595
- */
1596
-
1597
- var Ember = { Handlebars : Object.create(Handlebars) };
1598
- this.Ember = Ember;
1599
-
1600
- Ember.Handlebars.Compiler = function() {};
1601
- Ember.Handlebars.Compiler.prototype = Object.create( Handlebars.Compiler.prototype );
1602
- Ember.Handlebars.Compiler.prototype.compiler = Ember.Handlebars.Compiler;
1603
-
1604
- Ember.Handlebars.JavaScriptCompiler = function() {};
1605
- Ember.Handlebars.JavaScriptCompiler.prototype = Object.create(Handlebars.JavaScriptCompiler.prototype);
1606
- Ember.Handlebars.JavaScriptCompiler.prototype.compiler = Ember.Handlebars.JavaScriptCompiler;
1607
- Ember.Handlebars.JavaScriptCompiler.prototype.namespace = "Ember.Handlebars";
1608
-
1609
- /**
1610
- Override the default property lookup semantics of Handlebars.
1611
-
1612
- By default, Handlebars uses object[property] to look up properties. SproutCore's Handlebars
1613
- uses Ember.get().
1614
-
1615
- @private
1616
- */
1617
- Ember.Handlebars.JavaScriptCompiler.prototype.nameLookup = function(parent, name, type) {
1618
- if (type === 'context') {
1619
- return "Ember.get(" + parent + ", " + this.quotedString(name) + ");";
1620
- } else {
1621
- return Handlebars.JavaScriptCompiler.prototype.nameLookup.call(this, parent, name, type);
1622
- }
1623
- };
1624
-
1625
- Ember.Handlebars.JavaScriptCompiler.prototype.initializeBuffer = function() {
1626
- return "''";
1627
- };
1628
-
1629
- /**
1630
- Override the default buffer for SproutCore Handlebars. By default, Handlebars creates
1631
- an empty String at the beginning of each invocation and appends to it. SproutCore's
1632
- Handlebars overrides this to append to a single shared buffer.
1633
-
1634
- @private
1635
- */
1636
- Ember.Handlebars.JavaScriptCompiler.prototype.appendToBuffer = function(string) {
1637
- return "data.buffer.push("+string+");";
1638
- };
1639
-
1640
- /**
1641
- Rewrite simple mustaches from {{foo}} to {{bind "foo"}}. This means that all simple
1642
- mustaches in SproutCore's Handlebars will also set up an observer to keep the DOM
1643
- up to date when the underlying property changes.
1644
-
1645
- @private
1646
- */
1647
- Ember.Handlebars.Compiler.prototype.mustache = function(mustache) {
1648
- if (mustache.params.length || mustache.hash) {
1649
- return Handlebars.Compiler.prototype.mustache.call(this, mustache);
1650
- } else {
1651
- var id = new Handlebars.AST.IdNode(['bind']);
1652
-
1653
- // Update the mustache node to include a hash value indicating whether the original node
1654
- // was escaped. This will allow us to properly escape values when the underlying value
1655
- // changes and we need to re-render the value.
1656
- if(mustache.escaped) {
1657
- mustache.hash = mustache.hash || new Handlebars.AST.HashNode([]);
1658
- mustache.hash.pairs.push(["escaped", new Handlebars.AST.StringNode("true")]);
1659
- }
1660
- mustache = new Handlebars.AST.MustacheNode([id].concat([mustache.id]), mustache.hash, !mustache.escaped);
1661
- return Handlebars.Compiler.prototype.mustache.call(this, mustache);
1662
- }
1663
- };
1664
-
1665
- Ember.Handlebars.precompile = function(string) {
1666
- var options = { data: true, stringParams: true };
1667
-
1668
- var ast = Handlebars.parse(string);
1669
-
1670
- var environment = new Ember.Handlebars.Compiler().compile(ast, options);
1671
- return new Ember.Handlebars.JavaScriptCompiler().compile(environment, options);
1672
- };
1673
-