templebars 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +13 -13
- data/lib/templebars/rails/templates.rb +1 -1
- data/lib/templebars/rails/version.rb +2 -2
- data/vendor/assets/javascripts/handlebars.js +235 -137
- metadata +6 -7
data/README.md
CHANGED
@@ -1,33 +1,33 @@
|
|
1
1
|
# templebars
|
2
2
|
|
3
|
-
|
3
|
+
`templebars` allows you to precomile Handlebars templates and make them available globally in a `Templates` object. (This can be set via `Templebars::Rails::GLOBAL`) Create files with a "handlebars", "hbs", or "hb" extension inside of a `templates/` directory in any `assets/javascripts/` directory:
|
4
4
|
|
5
|
-
```
|
6
|
-
|
5
|
+
```
|
6
|
+
app/assets/javascripts/templates/todo_item.js.handlebars
|
7
7
|
```
|
8
8
|
|
9
|
-
You can
|
9
|
+
You can then access it like any other JavaScript asset:
|
10
10
|
|
11
11
|
```ruby
|
12
|
-
javascript_include_tag( "
|
12
|
+
javascript_include_tag( "templates/todo_item" )
|
13
13
|
```
|
14
14
|
|
15
|
-
|
15
|
+
The above template would be stored as `Templates.todo_item`.
|
16
16
|
|
17
|
-
|
17
|
+
## Handlebars
|
18
18
|
|
19
|
-
|
20
|
-
|
19
|
+
This gem also provides Handlebars 1.0.beta.6 to the Rails assert pipeline via `handlebars`. You can include it in other JS files:
|
20
|
+
|
21
|
+
```js
|
22
|
+
//= require handlebars
|
21
23
|
```
|
22
24
|
|
23
|
-
You can
|
25
|
+
You can also include it via a regular ol' `javascript_include_tag` call:
|
24
26
|
|
25
27
|
```ruby
|
26
|
-
javascript_include_tag( "
|
28
|
+
javascript_include_tag( "handlebars" )
|
27
29
|
```
|
28
30
|
|
29
|
-
The above template would be stored as `Templates.todo_item`.
|
30
|
-
|
31
31
|
## Installation
|
32
32
|
|
33
33
|
Add this to your Gemfile, preferably in the `:assets` gem group:
|
@@ -1,7 +1,9 @@
|
|
1
1
|
// lib/handlebars/base.js
|
2
|
+
|
3
|
+
/*jshint eqnull:true*/
|
2
4
|
var Handlebars = {};
|
3
5
|
|
4
|
-
Handlebars.VERSION = "1.0.beta.
|
6
|
+
Handlebars.VERSION = "1.0.beta.5";
|
5
7
|
|
6
8
|
Handlebars.helpers = {};
|
7
9
|
Handlebars.partials = {};
|
@@ -96,7 +98,6 @@ Handlebars.registerHelper('log', function(context) {
|
|
96
98
|
// lib/handlebars/compiler/parser.js
|
97
99
|
/* Jison generated parser */
|
98
100
|
var handlebars = (function(){
|
99
|
-
|
100
101
|
var parser = {trace: function trace() { },
|
101
102
|
yy: {},
|
102
103
|
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},
|
@@ -106,85 +107,85 @@ performAction: function anonymous(yytext,yyleng,yylineno,yy,yystate,$$,_$) {
|
|
106
107
|
|
107
108
|
var $0 = $$.length - 1;
|
108
109
|
switch (yystate) {
|
109
|
-
case 1: return $$[$0-1]
|
110
|
+
case 1: return $$[$0-1];
|
110
111
|
break;
|
111
|
-
case 2: this.$ = new yy.ProgramNode($$[$0-2], $$[$0])
|
112
|
+
case 2: this.$ = new yy.ProgramNode($$[$0-2], $$[$0]);
|
112
113
|
break;
|
113
|
-
case 3: this.$ = new yy.ProgramNode($$[$0])
|
114
|
+
case 3: this.$ = new yy.ProgramNode($$[$0]);
|
114
115
|
break;
|
115
|
-
case 4: this.$ = new yy.ProgramNode([])
|
116
|
+
case 4: this.$ = new yy.ProgramNode([]);
|
116
117
|
break;
|
117
|
-
case 5: this.$ = [$$[$0]]
|
118
|
+
case 5: this.$ = [$$[$0]];
|
118
119
|
break;
|
119
|
-
case 6: $$[$0-1].push($$[$0]); this.$ = $$[$0-1]
|
120
|
+
case 6: $$[$0-1].push($$[$0]); this.$ = $$[$0-1];
|
120
121
|
break;
|
121
|
-
case 7: this.$ = new yy.InverseNode($$[$0-2], $$[$0-1], $$[$0])
|
122
|
+
case 7: this.$ = new yy.InverseNode($$[$0-2], $$[$0-1], $$[$0]);
|
122
123
|
break;
|
123
|
-
case 8: this.$ = new yy.BlockNode($$[$0-2], $$[$0-1], $$[$0])
|
124
|
+
case 8: this.$ = new yy.BlockNode($$[$0-2], $$[$0-1], $$[$0]);
|
124
125
|
break;
|
125
|
-
case 9: this.$ = $$[$0]
|
126
|
+
case 9: this.$ = $$[$0];
|
126
127
|
break;
|
127
|
-
case 10: this.$ = $$[$0]
|
128
|
+
case 10: this.$ = $$[$0];
|
128
129
|
break;
|
129
|
-
case 11: this.$ = new yy.ContentNode($$[$0])
|
130
|
+
case 11: this.$ = new yy.ContentNode($$[$0]);
|
130
131
|
break;
|
131
|
-
case 12: this.$ = new yy.CommentNode($$[$0])
|
132
|
+
case 12: this.$ = new yy.CommentNode($$[$0]);
|
132
133
|
break;
|
133
|
-
case 13: this.$ = new yy.MustacheNode($$[$0-1][0], $$[$0-1][1])
|
134
|
+
case 13: this.$ = new yy.MustacheNode($$[$0-1][0], $$[$0-1][1]);
|
134
135
|
break;
|
135
|
-
case 14: this.$ = new yy.MustacheNode($$[$0-1][0], $$[$0-1][1])
|
136
|
+
case 14: this.$ = new yy.MustacheNode($$[$0-1][0], $$[$0-1][1]);
|
136
137
|
break;
|
137
|
-
case 15: this.$ = $$[$0-1]
|
138
|
+
case 15: this.$ = $$[$0-1];
|
138
139
|
break;
|
139
|
-
case 16: this.$ = new yy.MustacheNode($$[$0-1][0], $$[$0-1][1])
|
140
|
+
case 16: this.$ = new yy.MustacheNode($$[$0-1][0], $$[$0-1][1]);
|
140
141
|
break;
|
141
|
-
case 17: this.$ = new yy.MustacheNode($$[$0-1][0], $$[$0-1][1], true)
|
142
|
+
case 17: this.$ = new yy.MustacheNode($$[$0-1][0], $$[$0-1][1], true);
|
142
143
|
break;
|
143
|
-
case 18: this.$ = new yy.PartialNode($$[$0-1])
|
144
|
+
case 18: this.$ = new yy.PartialNode($$[$0-1]);
|
144
145
|
break;
|
145
|
-
case 19: this.$ = new yy.PartialNode($$[$0-2], $$[$0-1])
|
146
|
+
case 19: this.$ = new yy.PartialNode($$[$0-2], $$[$0-1]);
|
146
147
|
break;
|
147
148
|
case 20:
|
148
149
|
break;
|
149
|
-
case 21: this.$ = [[$$[$0-2]].concat($$[$0-1]), $$[$0]]
|
150
|
+
case 21: this.$ = [[$$[$0-2]].concat($$[$0-1]), $$[$0]];
|
150
151
|
break;
|
151
|
-
case 22: this.$ = [[$$[$0-1]].concat($$[$0]), null]
|
152
|
+
case 22: this.$ = [[$$[$0-1]].concat($$[$0]), null];
|
152
153
|
break;
|
153
|
-
case 23: this.$ = [[$$[$0-1]], $$[$0]]
|
154
|
+
case 23: this.$ = [[$$[$0-1]], $$[$0]];
|
154
155
|
break;
|
155
|
-
case 24: this.$ = [[$$[$0]], null]
|
156
|
+
case 24: this.$ = [[$$[$0]], null];
|
156
157
|
break;
|
157
158
|
case 25: $$[$0-1].push($$[$0]); this.$ = $$[$0-1];
|
158
159
|
break;
|
159
|
-
case 26: this.$ = [$$[$0]]
|
160
|
+
case 26: this.$ = [$$[$0]];
|
160
161
|
break;
|
161
|
-
case 27: this.$ = $$[$0]
|
162
|
+
case 27: this.$ = $$[$0];
|
162
163
|
break;
|
163
|
-
case 28: this.$ = new yy.StringNode($$[$0])
|
164
|
+
case 28: this.$ = new yy.StringNode($$[$0]);
|
164
165
|
break;
|
165
|
-
case 29: this.$ = new yy.IntegerNode($$[$0])
|
166
|
+
case 29: this.$ = new yy.IntegerNode($$[$0]);
|
166
167
|
break;
|
167
|
-
case 30: this.$ = new yy.BooleanNode($$[$0])
|
168
|
+
case 30: this.$ = new yy.BooleanNode($$[$0]);
|
168
169
|
break;
|
169
|
-
case 31: this.$ = new yy.HashNode($$[$0])
|
170
|
+
case 31: this.$ = new yy.HashNode($$[$0]);
|
170
171
|
break;
|
171
|
-
case 32: $$[$0-1].push($$[$0]); this.$ = $$[$0-1]
|
172
|
+
case 32: $$[$0-1].push($$[$0]); this.$ = $$[$0-1];
|
172
173
|
break;
|
173
|
-
case 33: this.$ = [$$[$0]]
|
174
|
+
case 33: this.$ = [$$[$0]];
|
174
175
|
break;
|
175
|
-
case 34: this.$ = [$$[$0-2], $$[$0]]
|
176
|
+
case 34: this.$ = [$$[$0-2], $$[$0]];
|
176
177
|
break;
|
177
|
-
case 35: this.$ = [$$[$0-2], new yy.StringNode($$[$0])]
|
178
|
+
case 35: this.$ = [$$[$0-2], new yy.StringNode($$[$0])];
|
178
179
|
break;
|
179
|
-
case 36: this.$ = [$$[$0-2], new yy.IntegerNode($$[$0])]
|
180
|
+
case 36: this.$ = [$$[$0-2], new yy.IntegerNode($$[$0])];
|
180
181
|
break;
|
181
|
-
case 37: this.$ = [$$[$0-2], new yy.BooleanNode($$[$0])]
|
182
|
+
case 37: this.$ = [$$[$0-2], new yy.BooleanNode($$[$0])];
|
182
183
|
break;
|
183
|
-
case 38: this.$ = new yy.IdNode($$[$0])
|
184
|
+
case 38: this.$ = new yy.IdNode($$[$0]);
|
184
185
|
break;
|
185
186
|
case 39: $$[$0-2].push($$[$0]); this.$ = $$[$0-2];
|
186
187
|
break;
|
187
|
-
case 40: this.$ = [$$[$0]]
|
188
|
+
case 40: this.$ = [$$[$0]];
|
188
189
|
break;
|
189
190
|
}
|
190
191
|
},
|
@@ -194,105 +195,191 @@ parseError: function parseError(str, hash) {
|
|
194
195
|
throw new Error(str);
|
195
196
|
},
|
196
197
|
parse: function parse(input) {
|
197
|
-
var self = this,
|
198
|
+
var self = this,
|
199
|
+
stack = [0],
|
200
|
+
vstack = [null], // semantic value stack
|
201
|
+
lstack = [], // location stack
|
202
|
+
table = this.table,
|
203
|
+
yytext = '',
|
204
|
+
yylineno = 0,
|
205
|
+
yyleng = 0,
|
206
|
+
recovering = 0,
|
207
|
+
TERROR = 2,
|
208
|
+
EOF = 1;
|
209
|
+
|
210
|
+
//this.reductionCount = this.shiftCount = 0;
|
211
|
+
|
198
212
|
this.lexer.setInput(input);
|
199
213
|
this.lexer.yy = this.yy;
|
200
214
|
this.yy.lexer = this.lexer;
|
201
|
-
if (typeof this.lexer.yylloc ==
|
215
|
+
if (typeof this.lexer.yylloc == 'undefined')
|
202
216
|
this.lexer.yylloc = {};
|
203
217
|
var yyloc = this.lexer.yylloc;
|
204
218
|
lstack.push(yyloc);
|
205
|
-
|
219
|
+
|
220
|
+
if (typeof this.yy.parseError === 'function')
|
206
221
|
this.parseError = this.yy.parseError;
|
207
|
-
|
208
|
-
|
222
|
+
|
223
|
+
function popStack (n) {
|
224
|
+
stack.length = stack.length - 2*n;
|
209
225
|
vstack.length = vstack.length - n;
|
210
226
|
lstack.length = lstack.length - n;
|
211
227
|
}
|
228
|
+
|
212
229
|
function lex() {
|
213
230
|
var token;
|
214
|
-
token = self.lexer.lex() || 1;
|
215
|
-
if
|
231
|
+
token = self.lexer.lex() || 1; // $end = 1
|
232
|
+
// if token isn't its numeric value, convert
|
233
|
+
if (typeof token !== 'number') {
|
216
234
|
token = self.symbols_[token] || token;
|
217
235
|
}
|
218
236
|
return token;
|
219
237
|
}
|
220
|
-
|
238
|
+
|
239
|
+
var symbol, preErrorSymbol, state, action, a, r, yyval={},p,len,newState, expected;
|
221
240
|
while (true) {
|
222
|
-
state
|
241
|
+
// retreive state number from top of stack
|
242
|
+
state = stack[stack.length-1];
|
243
|
+
|
244
|
+
// use default actions if available
|
223
245
|
if (this.defaultActions[state]) {
|
224
246
|
action = this.defaultActions[state];
|
225
247
|
} else {
|
226
248
|
if (symbol == null)
|
227
249
|
symbol = lex();
|
250
|
+
// read action for current state and first input
|
228
251
|
action = table[state] && table[state][symbol];
|
229
252
|
}
|
230
|
-
|
253
|
+
|
254
|
+
// handle parse error
|
255
|
+
_handle_error:
|
256
|
+
if (typeof action === 'undefined' || !action.length || !action[0]) {
|
257
|
+
|
231
258
|
if (!recovering) {
|
259
|
+
// Report error
|
232
260
|
expected = [];
|
233
|
-
for (p in table[state])
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
var errStr = "";
|
261
|
+
for (p in table[state]) if (this.terminals_[p] && p > 2) {
|
262
|
+
expected.push("'"+this.terminals_[p]+"'");
|
263
|
+
}
|
264
|
+
var errStr = '';
|
238
265
|
if (this.lexer.showPosition) {
|
239
|
-
errStr =
|
266
|
+
errStr = 'Parse error on line '+(yylineno+1)+":\n"+this.lexer.showPosition()+"\nExpecting "+expected.join(', ') + ", got '" + this.terminals_[symbol]+ "'";
|
240
267
|
} else {
|
241
|
-
errStr =
|
268
|
+
errStr = 'Parse error on line '+(yylineno+1)+": Unexpected " +
|
269
|
+
(symbol == 1 /*EOF*/ ? "end of input" :
|
270
|
+
("'"+(this.terminals_[symbol] || symbol)+"'"));
|
242
271
|
}
|
243
|
-
this.parseError(errStr,
|
272
|
+
this.parseError(errStr,
|
273
|
+
{text: this.lexer.match, token: this.terminals_[symbol] || symbol, line: this.lexer.yylineno, loc: yyloc, expected: expected});
|
244
274
|
}
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
lstack.push(this.lexer.yylloc);
|
254
|
-
stack.push(action[1]);
|
255
|
-
symbol = null;
|
256
|
-
if (!preErrorSymbol) {
|
275
|
+
|
276
|
+
// just recovered from another error
|
277
|
+
if (recovering == 3) {
|
278
|
+
if (symbol == EOF) {
|
279
|
+
throw new Error(errStr || 'Parsing halted.');
|
280
|
+
}
|
281
|
+
|
282
|
+
// discard current lookahead and grab another
|
257
283
|
yyleng = this.lexer.yyleng;
|
258
284
|
yytext = this.lexer.yytext;
|
259
285
|
yylineno = this.lexer.yylineno;
|
260
286
|
yyloc = this.lexer.yylloc;
|
261
|
-
|
262
|
-
recovering--;
|
263
|
-
} else {
|
264
|
-
symbol = preErrorSymbol;
|
265
|
-
preErrorSymbol = null;
|
266
|
-
}
|
267
|
-
break;
|
268
|
-
case 2:
|
269
|
-
len = this.productions_[action[1]][1];
|
270
|
-
yyval.$ = vstack[vstack.length - len];
|
271
|
-
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};
|
272
|
-
r = this.performAction.call(yyval, yytext, yyleng, yylineno, this.yy, action[1], vstack, lstack);
|
273
|
-
if (typeof r !== "undefined") {
|
274
|
-
return r;
|
287
|
+
symbol = lex();
|
275
288
|
}
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
289
|
+
|
290
|
+
// try to recover from error
|
291
|
+
while (1) {
|
292
|
+
// check for error recovery rule in this state
|
293
|
+
if ((TERROR.toString()) in table[state]) {
|
294
|
+
break;
|
295
|
+
}
|
296
|
+
if (state == 0) {
|
297
|
+
throw new Error(errStr || 'Parsing halted.');
|
298
|
+
}
|
299
|
+
popStack(1);
|
300
|
+
state = stack[stack.length-1];
|
280
301
|
}
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
case 3:
|
288
|
-
return true;
|
302
|
+
|
303
|
+
preErrorSymbol = symbol; // save the lookahead token
|
304
|
+
symbol = TERROR; // insert generic error symbol as new lookahead
|
305
|
+
state = stack[stack.length-1];
|
306
|
+
action = table[state] && table[state][TERROR];
|
307
|
+
recovering = 3; // allow 3 real symbols to be shifted before reporting a new error
|
289
308
|
}
|
309
|
+
|
310
|
+
// this shouldn't happen, unless resolve defaults are off
|
311
|
+
if (action[0] instanceof Array && action.length > 1) {
|
312
|
+
throw new Error('Parse Error: multiple actions possible at state: '+state+', token: '+symbol);
|
313
|
+
}
|
314
|
+
|
315
|
+
switch (action[0]) {
|
316
|
+
|
317
|
+
case 1: // shift
|
318
|
+
//this.shiftCount++;
|
319
|
+
|
320
|
+
stack.push(symbol);
|
321
|
+
vstack.push(this.lexer.yytext);
|
322
|
+
lstack.push(this.lexer.yylloc);
|
323
|
+
stack.push(action[1]); // push state
|
324
|
+
symbol = null;
|
325
|
+
if (!preErrorSymbol) { // normal execution/no error
|
326
|
+
yyleng = this.lexer.yyleng;
|
327
|
+
yytext = this.lexer.yytext;
|
328
|
+
yylineno = this.lexer.yylineno;
|
329
|
+
yyloc = this.lexer.yylloc;
|
330
|
+
if (recovering > 0)
|
331
|
+
recovering--;
|
332
|
+
} else { // error just occurred, resume old lookahead f/ before error
|
333
|
+
symbol = preErrorSymbol;
|
334
|
+
preErrorSymbol = null;
|
335
|
+
}
|
336
|
+
break;
|
337
|
+
|
338
|
+
case 2: // reduce
|
339
|
+
//this.reductionCount++;
|
340
|
+
|
341
|
+
len = this.productions_[action[1]][1];
|
342
|
+
|
343
|
+
// perform semantic action
|
344
|
+
yyval.$ = vstack[vstack.length-len]; // default to $$ = $1
|
345
|
+
// default location, uses first token for firsts, last for lasts
|
346
|
+
yyval._$ = {
|
347
|
+
first_line: lstack[lstack.length-(len||1)].first_line,
|
348
|
+
last_line: lstack[lstack.length-1].last_line,
|
349
|
+
first_column: lstack[lstack.length-(len||1)].first_column,
|
350
|
+
last_column: lstack[lstack.length-1].last_column
|
351
|
+
};
|
352
|
+
r = this.performAction.call(yyval, yytext, yyleng, yylineno, this.yy, action[1], vstack, lstack);
|
353
|
+
|
354
|
+
if (typeof r !== 'undefined') {
|
355
|
+
return r;
|
356
|
+
}
|
357
|
+
|
358
|
+
// pop off stack
|
359
|
+
if (len) {
|
360
|
+
stack = stack.slice(0,-1*len*2);
|
361
|
+
vstack = vstack.slice(0, -1*len);
|
362
|
+
lstack = lstack.slice(0, -1*len);
|
363
|
+
}
|
364
|
+
|
365
|
+
stack.push(this.productions_[action[1]][0]); // push nonterminal (reduce)
|
366
|
+
vstack.push(yyval.$);
|
367
|
+
lstack.push(yyval._$);
|
368
|
+
// goto new state = table[STATE][NONTERMINAL]
|
369
|
+
newState = table[stack[stack.length-2]][stack[stack.length-1]];
|
370
|
+
stack.push(newState);
|
371
|
+
break;
|
372
|
+
|
373
|
+
case 3: // accept
|
374
|
+
return true;
|
375
|
+
}
|
376
|
+
|
290
377
|
}
|
378
|
+
|
291
379
|
return true;
|
292
|
-
}
|
293
|
-
|
380
|
+
}};
|
381
|
+
/* Jison generated lexer */
|
294
382
|
var lexer = (function(){
|
295
|
-
|
296
383
|
var lexer = ({EOF:1,
|
297
384
|
parseError:function parseError(str, hash) {
|
298
385
|
if (this.yy.parseError) {
|
@@ -353,6 +440,8 @@ next:function () {
|
|
353
440
|
|
354
441
|
var token,
|
355
442
|
match,
|
443
|
+
tempMatch,
|
444
|
+
index,
|
356
445
|
col,
|
357
446
|
lines;
|
358
447
|
if (!this._more) {
|
@@ -361,26 +450,30 @@ next:function () {
|
|
361
450
|
}
|
362
451
|
var rules = this._currentRules();
|
363
452
|
for (var i=0;i < rules.length; i++) {
|
364
|
-
|
365
|
-
if (match) {
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
last_line: this.yylineno+1,
|
370
|
-
first_column: this.yylloc.last_column,
|
371
|
-
last_column: lines ? lines[lines.length-1].length-1 : this.yylloc.last_column + match[0].length}
|
372
|
-
this.yytext += match[0];
|
373
|
-
this.match += match[0];
|
374
|
-
this.matches = match;
|
375
|
-
this.yyleng = this.yytext.length;
|
376
|
-
this._more = false;
|
377
|
-
this._input = this._input.slice(match[0].length);
|
378
|
-
this.matched += match[0];
|
379
|
-
token = this.performAction.call(this, this.yy, this, rules[i],this.conditionStack[this.conditionStack.length-1]);
|
380
|
-
if (token) return token;
|
381
|
-
else return;
|
453
|
+
tempMatch = this._input.match(this.rules[rules[i]]);
|
454
|
+
if (tempMatch && (!match || tempMatch[0].length > match[0].length)) {
|
455
|
+
match = tempMatch;
|
456
|
+
index = i;
|
457
|
+
if (!this.options.flex) break;
|
382
458
|
}
|
383
459
|
}
|
460
|
+
if (match) {
|
461
|
+
lines = match[0].match(/\n.*/g);
|
462
|
+
if (lines) this.yylineno += lines.length;
|
463
|
+
this.yylloc = {first_line: this.yylloc.last_line,
|
464
|
+
last_line: this.yylineno+1,
|
465
|
+
first_column: this.yylloc.last_column,
|
466
|
+
last_column: lines ? lines[lines.length-1].length-1 : this.yylloc.last_column + match[0].length}
|
467
|
+
this.yytext += match[0];
|
468
|
+
this.match += match[0];
|
469
|
+
this.yyleng = this.yytext.length;
|
470
|
+
this._more = false;
|
471
|
+
this._input = this._input.slice(match[0].length);
|
472
|
+
this.matched += match[0];
|
473
|
+
token = this.performAction.call(this, this.yy, this, rules[index],this.conditionStack[this.conditionStack.length-1]);
|
474
|
+
if (token) return token;
|
475
|
+
else return;
|
476
|
+
}
|
384
477
|
if (this._input === "") {
|
385
478
|
return this.EOF;
|
386
479
|
} else {
|
@@ -411,6 +504,7 @@ topState:function () {
|
|
411
504
|
pushState:function begin(condition) {
|
412
505
|
this.begin(condition);
|
413
506
|
}});
|
507
|
+
lexer.options = {};
|
414
508
|
lexer.performAction = function anonymous(yy,yy_,$avoiding_name_collisions,YY_START) {
|
415
509
|
|
416
510
|
var YYSTATE=YY_START
|
@@ -476,7 +570,8 @@ break;
|
|
476
570
|
}
|
477
571
|
};
|
478
572
|
lexer.rules = [/^[^\x00]*?(?=(\{\{))/,/^[^\x00]+/,/^[^\x00]{2,}?(?=(\{\{))/,/^\{\{>/,/^\{\{#/,/^\{\{\//,/^\{\{\^/,/^\{\{\s*else\b/,/^\{\{\{/,/^\{\{&/,/^\{\{![\s\S]*?\}\}/,/^\{\{/,/^=/,/^\.(?=[} ])/,/^\.\./,/^[\/.]/,/^\s+/,/^\}\}\}/,/^\}\}/,/^"(\\["]|[^"])*"/,/^true(?=[}\s])/,/^false(?=[}\s])/,/^[0-9]+(?=[}\s])/,/^[a-zA-Z0-9_$-]+(?=[=}\s\/.])/,/^\[[^\]]*\]/,/^./,/^$/];
|
479
|
-
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}};
|
573
|
+
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}};
|
574
|
+
return lexer;})()
|
480
575
|
parser.lexer = lexer;
|
481
576
|
return parser;
|
482
577
|
})();
|
@@ -629,7 +724,7 @@ Handlebars.Exception = function(message) {
|
|
629
724
|
|
630
725
|
this.message = tmp.message;
|
631
726
|
};
|
632
|
-
Handlebars.Exception.prototype = new Error;
|
727
|
+
Handlebars.Exception.prototype = new Error();
|
633
728
|
|
634
729
|
// Build out our basic SafeString type
|
635
730
|
Handlebars.SafeString = function(string) {
|
@@ -684,6 +779,8 @@ Handlebars.SafeString.prototype.toString = function() {
|
|
684
779
|
};
|
685
780
|
})();;
|
686
781
|
// lib/handlebars/compiler/compiler.js
|
782
|
+
|
783
|
+
/*jshint eqnull:true*/
|
687
784
|
Handlebars.Compiler = function() {};
|
688
785
|
Handlebars.JavaScriptCompiler = function() {};
|
689
786
|
|
@@ -822,7 +919,7 @@ Handlebars.JavaScriptCompiler = function() {};
|
|
822
919
|
|
823
920
|
compileProgram: function(program) {
|
824
921
|
var result = new this.compiler().compile(program, this.options);
|
825
|
-
var guid = this.guid
|
922
|
+
var guid = this.guid++, depth;
|
826
923
|
|
827
924
|
this.usePartial = this.usePartial || result.usePartial;
|
828
925
|
|
@@ -999,13 +1096,13 @@ Handlebars.JavaScriptCompiler = function() {};
|
|
999
1096
|
// PUBLIC API: You can override these methods in a subclass to provide
|
1000
1097
|
// alternative compiled forms for name lookup and buffering semantics
|
1001
1098
|
nameLookup: function(parent, name, type) {
|
1002
|
-
|
1099
|
+
if (/^[0-9]+$/.test(name)) {
|
1003
1100
|
return parent + "[" + name + "]";
|
1004
1101
|
} else if (JavaScriptCompiler.isValidJavaScriptVariableName(name)) {
|
1005
|
-
|
1006
|
-
|
1007
|
-
|
1008
|
-
|
1102
|
+
return parent + "." + name;
|
1103
|
+
}
|
1104
|
+
else {
|
1105
|
+
return parent + "['" + name + "']";
|
1009
1106
|
}
|
1010
1107
|
},
|
1011
1108
|
|
@@ -1130,7 +1227,7 @@ Handlebars.JavaScriptCompiler = function() {};
|
|
1130
1227
|
|
1131
1228
|
// Generate minimizer alias mappings
|
1132
1229
|
if (!this.isChild) {
|
1133
|
-
var aliases = []
|
1230
|
+
var aliases = [];
|
1134
1231
|
for (var alias in this.context.aliases) {
|
1135
1232
|
this.source[1] = this.source[1] + ', ' + alias + '=' + this.context.aliases[alias];
|
1136
1233
|
}
|
@@ -1223,7 +1320,7 @@ Handlebars.JavaScriptCompiler = function() {};
|
|
1223
1320
|
lookup: function(name) {
|
1224
1321
|
var topStack = this.topStack();
|
1225
1322
|
this.source.push(topStack + " = (" + topStack + " === null || " + topStack + " === undefined || " + topStack + " === false ? " +
|
1226
|
-
|
1323
|
+
topStack + " : " + this.nameLookup(topStack, name, 'context') + ");");
|
1227
1324
|
},
|
1228
1325
|
|
1229
1326
|
pushStringParam: function(string) {
|
@@ -1318,7 +1415,7 @@ Handlebars.JavaScriptCompiler = function() {};
|
|
1318
1415
|
this.source.push(nextStack + " = " + id + ".call(" + paramString + ");");
|
1319
1416
|
} else {
|
1320
1417
|
this.context.aliases.functionType = '"function"';
|
1321
|
-
var condition = program ? "foundHelper && " : ""
|
1418
|
+
var condition = program ? "foundHelper && " : "";
|
1322
1419
|
this.source.push("if(" + condition + "typeof " + id + " === functionType) { " + nextStack + " = " + id + ".call(" + paramString + "); }");
|
1323
1420
|
}
|
1324
1421
|
fn.call(this, nextStack, helperMissingString, id);
|
@@ -1326,7 +1423,7 @@ Handlebars.JavaScriptCompiler = function() {};
|
|
1326
1423
|
},
|
1327
1424
|
|
1328
1425
|
invokePartial: function(context) {
|
1329
|
-
params = [this.nameLookup('partials', context, 'partial'), "'" + context + "'", this.popStack(), "helpers", "partials"];
|
1426
|
+
var params = [this.nameLookup('partials', context, 'partial'), "'" + context + "'", this.popStack(), "helpers", "partials"];
|
1330
1427
|
|
1331
1428
|
if (this.options.data) {
|
1332
1429
|
params.push("data");
|
@@ -1365,7 +1462,8 @@ Handlebars.JavaScriptCompiler = function() {};
|
|
1365
1462
|
if(guid == null) { return "self.noop"; }
|
1366
1463
|
|
1367
1464
|
var child = this.environment.children[guid],
|
1368
|
-
depths = child.depths.list;
|
1465
|
+
depths = child.depths.list, depth;
|
1466
|
+
|
1369
1467
|
var programParams = [child.index, child.name, "data"];
|
1370
1468
|
|
1371
1469
|
for(var i=0, l = depths.length; i<l; i++) {
|
@@ -1447,12 +1545,12 @@ Handlebars.JavaScriptCompiler = function() {};
|
|
1447
1545
|
compilerWords[reservedWords[i]] = true;
|
1448
1546
|
}
|
1449
1547
|
|
1450
|
-
|
1451
|
-
|
1452
|
-
|
1453
|
-
|
1454
|
-
|
1455
|
-
|
1548
|
+
JavaScriptCompiler.isValidJavaScriptVariableName = function(name) {
|
1549
|
+
if(!JavaScriptCompiler.RESERVED_WORDS[name] && /^[a-zA-Z_$][0-9a-zA-Z_$]+$/.test(name)) {
|
1550
|
+
return true;
|
1551
|
+
}
|
1552
|
+
return false;
|
1553
|
+
};
|
1456
1554
|
|
1457
1555
|
})(Handlebars.Compiler, Handlebars.JavaScriptCompiler);
|
1458
1556
|
|
@@ -1531,7 +1629,7 @@ Handlebars.VM = {
|
|
1531
1629
|
},
|
1532
1630
|
noop: function() { return ""; },
|
1533
1631
|
invokePartial: function(partial, name, context, helpers, partials, data) {
|
1534
|
-
options = { helpers: helpers, partials: partials, data: data };
|
1632
|
+
var options = { helpers: helpers, partials: partials, data: data };
|
1535
1633
|
|
1536
1634
|
if(partial === undefined) {
|
1537
1635
|
throw new Handlebars.Exception("The partial " + name + " could not be found");
|
@@ -1547,4 +1645,4 @@ Handlebars.VM = {
|
|
1547
1645
|
};
|
1548
1646
|
|
1549
1647
|
Handlebars.template = Handlebars.VM.template;
|
1550
|
-
;
|
1648
|
+
;
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: templebars
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-02-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: railties
|
16
|
-
requirement: &
|
16
|
+
requirement: &70340437390040 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -24,10 +24,10 @@ dependencies:
|
|
24
24
|
version: '5.0'
|
25
25
|
type: :runtime
|
26
26
|
prerelease: false
|
27
|
-
version_requirements: *
|
27
|
+
version_requirements: *70340437390040
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: execjs
|
30
|
-
requirement: &
|
30
|
+
requirement: &70340437388320 !ruby/object:Gem::Requirement
|
31
31
|
none: false
|
32
32
|
requirements:
|
33
33
|
- - ! '>='
|
@@ -35,7 +35,7 @@ dependencies:
|
|
35
35
|
version: '0'
|
36
36
|
type: :runtime
|
37
37
|
prerelease: false
|
38
|
-
version_requirements: *
|
38
|
+
version_requirements: *70340437388320
|
39
39
|
description: This gem provides Handlebars magic for your Rails 3 application.
|
40
40
|
email:
|
41
41
|
- tyson@stovepipestudios.com
|
@@ -81,4 +81,3 @@ signing_key:
|
|
81
81
|
specification_version: 3
|
82
82
|
summary: Use precompiled Handlebars templates with Rails 3
|
83
83
|
test_files: []
|
84
|
-
has_rdoc:
|