barber 0.1.3 → 0.2.0

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