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