3 Copyright 2012 Yahoo! Inc. All rights reserved.
4 Licensed under the BSD License.
5 http://yuilibrary.com/license/
7 YUI.add('handlebars-compiler', function(Y) {
10 Handlebars.js - Copyright (C) 2011 Yehuda Katz
11 https://raw.github.com/wycats/handlebars.js/master/LICENSE
13 // This file contains code that will be inserted at the beginning of the
14 // handlebars-compiler module.
16 // This is necessary because the Y.Handlebars object is created in the
17 // handlebars-base module, but the native Handlebars code expects to use a local
18 // Handlebars reference.
19 var Handlebars = Y.Handlebars;
20 /* THIS FILE IS GENERATED BY A BUILD SCRIPT - DO NOT EDIT! */
22 /* Jison generated parser */
23 var handlebars = (function(){
25 var parser = {trace: function trace() { },
27 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},
28 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"},
29 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]],
30 performAction: function anonymous(yytext,yyleng,yylineno,yy,yystate,$$,_$) {
32 var $0 = $$.length - 1;
34 case 1: return $$[$0-1];
36 case 2: this.$ = new yy.ProgramNode($$[$0-2], $$[$0]);
38 case 3: this.$ = new yy.ProgramNode($$[$0]);
40 case 4: this.$ = new yy.ProgramNode([]);
42 case 5: this.$ = [$$[$0]];
44 case 6: $$[$0-1].push($$[$0]); this.$ = $$[$0-1];
46 case 7: this.$ = new yy.InverseNode($$[$0-2], $$[$0-1], $$[$0]);
48 case 8: this.$ = new yy.BlockNode($$[$0-2], $$[$0-1], $$[$0]);
50 case 9: this.$ = $$[$0];
52 case 10: this.$ = $$[$0];
54 case 11: this.$ = new yy.ContentNode($$[$0]);
56 case 12: this.$ = new yy.CommentNode($$[$0]);
58 case 13: this.$ = new yy.MustacheNode($$[$0-1][0], $$[$0-1][1]);
60 case 14: this.$ = new yy.MustacheNode($$[$0-1][0], $$[$0-1][1]);
62 case 15: this.$ = $$[$0-1];
64 case 16: this.$ = new yy.MustacheNode($$[$0-1][0], $$[$0-1][1]);
66 case 17: this.$ = new yy.MustacheNode($$[$0-1][0], $$[$0-1][1], true);
68 case 18: this.$ = new yy.PartialNode($$[$0-1]);
70 case 19: this.$ = new yy.PartialNode($$[$0-2], $$[$0-1]);
74 case 21: this.$ = [[$$[$0-2]].concat($$[$0-1]), $$[$0]];
76 case 22: this.$ = [[$$[$0-1]].concat($$[$0]), null];
78 case 23: this.$ = [[$$[$0-1]], $$[$0]];
80 case 24: this.$ = [[$$[$0]], null];
82 case 25: $$[$0-1].push($$[$0]); this.$ = $$[$0-1];
84 case 26: this.$ = [$$[$0]];
86 case 27: this.$ = $$[$0];
88 case 28: this.$ = new yy.StringNode($$[$0]);
90 case 29: this.$ = new yy.IntegerNode($$[$0]);
92 case 30: this.$ = new yy.BooleanNode($$[$0]);
94 case 31: this.$ = new yy.HashNode($$[$0]);
96 case 32: $$[$0-1].push($$[$0]); this.$ = $$[$0-1];
98 case 33: this.$ = [$$[$0]];
100 case 34: this.$ = [$$[$0-2], $$[$0]];
102 case 35: this.$ = [$$[$0-2], new yy.StringNode($$[$0])];
104 case 36: this.$ = [$$[$0-2], new yy.IntegerNode($$[$0])];
106 case 37: this.$ = [$$[$0-2], new yy.BooleanNode($$[$0])];
108 case 38: this.$ = new yy.IdNode($$[$0]);
110 case 39: $$[$0-2].push($$[$0]); this.$ = $$[$0-2];
112 case 40: this.$ = [$$[$0]];
116 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]}],
117 defaultActions: {16:[2,1],37:[2,23],53:[2,21]},
118 parseError: function parseError(str, hash) {
119 throw new Error(str);
121 parse: function parse(input) {
124 vstack = [null], // semantic value stack
125 lstack = [], // location stack
134 //this.reductionCount = this.shiftCount = 0;
136 this.lexer.setInput(input);
137 this.lexer.yy = this.yy;
138 this.yy.lexer = this.lexer;
139 if (typeof this.lexer.yylloc == 'undefined')
140 this.lexer.yylloc = {};
141 var yyloc = this.lexer.yylloc;
144 if (typeof this.yy.parseError === 'function')
145 this.parseError = this.yy.parseError;
147 function popStack (n) {
148 stack.length = stack.length - 2*n;
149 vstack.length = vstack.length - n;
150 lstack.length = lstack.length - n;
155 token = self.lexer.lex() || 1; // $end = 1
156 // if token isn't its numeric value, convert
157 if (typeof token !== 'number') {
158 token = self.symbols_[token] || token;
163 var symbol, preErrorSymbol, state, action, a, r, yyval={},p,len,newState, expected;
165 // retreive state number from top of stack
166 state = stack[stack.length-1];
168 // use default actions if available
169 if (this.defaultActions[state]) {
170 action = this.defaultActions[state];
174 // read action for current state and first input
175 action = table[state] && table[state][symbol];
178 // handle parse error
180 if (typeof action === 'undefined' || !action.length || !action[0]) {
185 for (p in table[state]) if (this.terminals_[p] && p > 2) {
186 expected.push("'"+this.terminals_[p]+"'");
189 if (this.lexer.showPosition) {
190 errStr = 'Parse error on line '+(yylineno+1)+":\n"+this.lexer.showPosition()+"\nExpecting "+expected.join(', ') + ", got '" + this.terminals_[symbol]+ "'";
192 errStr = 'Parse error on line '+(yylineno+1)+": Unexpected " +
193 (symbol == 1 /*EOF*/ ? "end of input" :
194 ("'"+(this.terminals_[symbol] || symbol)+"'"));
196 this.parseError(errStr,
197 {text: this.lexer.match, token: this.terminals_[symbol] || symbol, line: this.lexer.yylineno, loc: yyloc, expected: expected});
200 // just recovered from another error
201 if (recovering == 3) {
203 throw new Error(errStr || 'Parsing halted.');
206 // discard current lookahead and grab another
207 yyleng = this.lexer.yyleng;
208 yytext = this.lexer.yytext;
209 yylineno = this.lexer.yylineno;
210 yyloc = this.lexer.yylloc;
214 // try to recover from error
216 // check for error recovery rule in this state
217 if ((TERROR.toString()) in table[state]) {
221 throw new Error(errStr || 'Parsing halted.');
224 state = stack[stack.length-1];
227 preErrorSymbol = symbol; // save the lookahead token
228 symbol = TERROR; // insert generic error symbol as new lookahead
229 state = stack[stack.length-1];
230 action = table[state] && table[state][TERROR];
231 recovering = 3; // allow 3 real symbols to be shifted before reporting a new error
234 // this shouldn't happen, unless resolve defaults are off
235 if (action[0] instanceof Array && action.length > 1) {
236 throw new Error('Parse Error: multiple actions possible at state: '+state+', token: '+symbol);
245 vstack.push(this.lexer.yytext);
246 lstack.push(this.lexer.yylloc);
247 stack.push(action[1]); // push state
249 if (!preErrorSymbol) { // normal execution/no error
250 yyleng = this.lexer.yyleng;
251 yytext = this.lexer.yytext;
252 yylineno = this.lexer.yylineno;
253 yyloc = this.lexer.yylloc;
256 } else { // error just occurred, resume old lookahead f/ before error
257 symbol = preErrorSymbol;
258 preErrorSymbol = null;
263 //this.reductionCount++;
265 len = this.productions_[action[1]][1];
267 // perform semantic action
268 yyval.$ = vstack[vstack.length-len]; // default to $$ = $1
269 // default location, uses first token for firsts, last for lasts
271 first_line: lstack[lstack.length-(len||1)].first_line,
272 last_line: lstack[lstack.length-1].last_line,
273 first_column: lstack[lstack.length-(len||1)].first_column,
274 last_column: lstack[lstack.length-1].last_column
276 r = this.performAction.call(yyval, yytext, yyleng, yylineno, this.yy, action[1], vstack, lstack);
278 if (typeof r !== 'undefined') {
284 stack = stack.slice(0,-1*len*2);
285 vstack = vstack.slice(0, -1*len);
286 lstack = lstack.slice(0, -1*len);
289 stack.push(this.productions_[action[1]][0]); // push nonterminal (reduce)
290 vstack.push(yyval.$);
291 lstack.push(yyval._$);
292 // goto new state = table[STATE][NONTERMINAL]
293 newState = table[stack[stack.length-2]][stack[stack.length-1]];
294 stack.push(newState);
304 }};/* Jison generated lexer */
305 var lexer = (function(){
308 parseError:function parseError(str, hash) {
309 if (this.yy.parseError) {
310 this.yy.parseError(str, hash);
312 throw new Error(str);
315 setInput:function (input) {
317 this._more = this._less = this.done = false;
318 this.yylineno = this.yyleng = 0;
319 this.yytext = this.matched = this.match = '';
320 this.conditionStack = ['INITIAL'];
321 this.yylloc = {first_line:1,first_column:0,last_line:1,last_column:0};
325 var ch = this._input[0];
330 var lines = ch.match(/\n/);
331 if (lines) this.yylineno++;
332 this._input = this._input.slice(1);
335 unput:function (ch) {
336 this._input = ch + this._input;
343 pastInput:function () {
344 var past = this.matched.substr(0, this.matched.length - this.match.length);
345 return (past.length > 20 ? '...':'') + past.substr(-20).replace(/\n/g, "");
347 upcomingInput:function () {
348 var next = this.match;
349 if (next.length < 20) {
350 next += this._input.substr(0, 20-next.length);
352 return (next.substr(0,20)+(next.length > 20 ? '...':'')).replace(/\n/g, "");
354 showPosition:function () {
355 var pre = this.pastInput();
356 var c = new Array(pre.length + 1).join("-");
357 return pre + this.upcomingInput() + "\n" + c+"^";
363 if (!this._input) this.done = true;
373 var rules = this._currentRules();
374 for (var i=0;i < rules.length; i++) {
375 match = this._input.match(this.rules[rules[i]]);
377 lines = match[0].match(/\n.*/g);
378 if (lines) this.yylineno += lines.length;
379 this.yylloc = {first_line: this.yylloc.last_line,
380 last_line: this.yylineno+1,
381 first_column: this.yylloc.last_column,
382 last_column: lines ? lines[lines.length-1].length-1 : this.yylloc.last_column + match[0].length}
383 this.yytext += match[0];
384 this.match += match[0];
385 this.matches = match;
386 this.yyleng = this.yytext.length;
388 this._input = this._input.slice(match[0].length);
389 this.matched += match[0];
390 token = this.performAction.call(this, this.yy, this, rules[i],this.conditionStack[this.conditionStack.length-1]);
391 if (token) return token;
395 if (this._input === "") {
398 this.parseError('Lexical error on line '+(this.yylineno+1)+'. Unrecognized text.\n'+this.showPosition(),
399 {text: "", token: null, line: this.yylineno});
404 if (typeof r !== 'undefined') {
410 begin:function begin(condition) {
411 this.conditionStack.push(condition);
413 popState:function popState() {
414 return this.conditionStack.pop();
416 _currentRules:function _currentRules() {
417 return this.conditions[this.conditionStack[this.conditionStack.length-1]].rules;
419 topState:function () {
420 return this.conditionStack[this.conditionStack.length-2];
422 pushState:function begin(condition) {
423 this.begin(condition);
425 lexer.performAction = function anonymous(yy,yy_,$avoiding_name_collisions,YY_START) {
428 switch($avoiding_name_collisions) {
430 if(yy_.yytext.slice(-1) !== "\\") this.begin("mu");
431 if(yy_.yytext.slice(-1) === "\\") yy_.yytext = yy_.yytext.substr(0,yy_.yyleng-1), this.begin("emu");
432 if(yy_.yytext) return 14;
437 case 2: this.popState(); return 14;
453 case 10: yy_.yytext = yy_.yytext.substr(3,yy_.yyleng-5); this.popState(); return 15;
465 case 16: /*ignore whitespace*/
467 case 17: this.popState(); return 18;
469 case 18: this.popState(); return 18;
471 case 19: yy_.yytext = yy_.yytext.substr(1,yy_.yyleng-2).replace(/\\"/g,'"'); return 28;
481 case 24: yy_.yytext = yy_.yytext.substr(1, yy_.yyleng-2); return 33;
483 case 25: return 'INVALID';
489 lexer.rules = [/^[^\x00]*?(?=(\{\{))/,/^[^\x00]+/,/^[^\x00]{2,}?(?=(\{\{))/,/^\{\{>/,/^\{\{#/,/^\{\{\//,/^\{\{\^/,/^\{\{\s*else\b/,/^\{\{\{/,/^\{\{&/,/^\{\{![\s\S]*?\}\}/,/^\{\{/,/^=/,/^\.(?=[} ])/,/^\.\./,/^[\/.]/,/^\s+/,/^\}\}\}/,/^\}\}/,/^"(\\["]|[^"])*"/,/^true(?=[}\s])/,/^false(?=[}\s])/,/^[0-9]+(?=[}\s])/,/^[a-zA-Z0-9_$-]+(?=[=}\s\/.])/,/^\[[^\]]*\]/,/^./,/^$/];
490 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;})()
491 parser.lexer = lexer;
494 if (typeof require !== 'undefined' && typeof exports !== 'undefined') {
495 exports.parser = handlebars;
496 exports.parse = function () { return handlebars.parse.apply(handlebars, arguments); }
497 exports.main = function commonjsMain(args) {
499 throw new Error('Usage: '+args[0]+' FILE');
500 if (typeof process !== 'undefined') {
501 var source = require('fs').readFileSync(require('path').join(process.cwd(), args[1]), "utf8");
503 var cwd = require("file").path(require("file").cwd());
504 var source = cwd.join(args[1]).read({charset: "utf-8"});
506 return exports.parser.parse(source);
508 if (typeof module !== 'undefined' && require.main === module) {
509 exports.main(typeof process !== 'undefined' ? process.argv.slice(1) : require("system").args);
512 /* THIS FILE IS GENERATED BY A BUILD SCRIPT - DO NOT EDIT! */
515 Handlebars.Parser = handlebars;
517 Handlebars.parse = function(string) {
518 Handlebars.Parser.yy = Handlebars.AST;
519 return Handlebars.Parser.parse(string);
522 Handlebars.print = function(ast) {
523 return new Handlebars.PrintVisitor().accept(ast);
526 Handlebars.logger = {
527 DEBUG: 0, INFO: 1, WARN: 2, ERROR: 3, level: 3,
529 // override in the host environment
530 log: function(level, str) {}
533 Handlebars.log = function(level, str) { Handlebars.logger.log(level, str); };
536 /* THIS FILE IS GENERATED BY A BUILD SCRIPT - DO NOT EDIT! */
543 Handlebars.AST.ProgramNode = function(statements, inverse) {
544 this.type = "program";
545 this.statements = statements;
546 if(inverse) { this.inverse = new Handlebars.AST.ProgramNode(inverse); }
549 Handlebars.AST.MustacheNode = function(params, hash, unescaped) {
550 this.type = "mustache";
552 this.params = params.slice(1);
554 this.escaped = !unescaped;
557 Handlebars.AST.PartialNode = function(id, context) {
558 this.type = "partial";
560 // TODO: disallow complex IDs
563 this.context = context;
566 var verifyMatch = function(open, close) {
567 if(open.original !== close.original) {
568 throw new Handlebars.Exception(open.original + " doesn't match " + close.original);
572 Handlebars.AST.BlockNode = function(mustache, program, close) {
573 verifyMatch(mustache.id, close);
575 this.mustache = mustache;
576 this.program = program;
579 Handlebars.AST.InverseNode = function(mustache, program, close) {
580 verifyMatch(mustache.id, close);
581 this.type = "inverse";
582 this.mustache = mustache;
583 this.program = program;
586 Handlebars.AST.ContentNode = function(string) {
587 this.type = "content";
588 this.string = string;
591 Handlebars.AST.HashNode = function(pairs) {
596 Handlebars.AST.IdNode = function(parts) {
598 this.original = parts.join(".");
600 var dig = [], depth = 0;
602 for(var i=0,l=parts.length; i<l; i++) {
605 if(part === "..") { depth++; }
606 else if(part === "." || part === "this") { this.isScoped = true; }
607 else { dig.push(part); }
611 this.string = dig.join('.');
613 this.isSimple = (dig.length === 1) && (depth === 0);
616 Handlebars.AST.StringNode = function(string) {
617 this.type = "STRING";
618 this.string = string;
621 Handlebars.AST.IntegerNode = function(integer) {
622 this.type = "INTEGER";
623 this.integer = integer;
626 Handlebars.AST.BooleanNode = function(bool) {
627 this.type = "BOOLEAN";
631 Handlebars.AST.CommentNode = function(comment) {
632 this.type = "comment";
633 this.comment = comment;
638 /* THIS FILE IS GENERATED BY A BUILD SCRIPT - DO NOT EDIT! */
642 /*jshint eqnull:true*/
643 Handlebars.Compiler = function() {};
644 Handlebars.JavaScriptCompiler = function() {};
646 (function(Compiler, JavaScriptCompiler) {
647 Compiler.OPCODE_MAP = {
650 lookupWithHelpers: 3,
657 functionOrFallback: 10,
665 Compiler.MULTI_PARAM_OPCODES = {
668 lookupWithHelpers: 2,
673 functionOrFallback: 1,
681 Compiler.DISASSEMBLE_MAP = {};
683 for(var prop in Compiler.OPCODE_MAP) {
684 var value = Compiler.OPCODE_MAP[prop];
685 Compiler.DISASSEMBLE_MAP[value] = prop;
688 Compiler.multiParamSize = function(code) {
689 return Compiler.MULTI_PARAM_OPCODES[Compiler.DISASSEMBLE_MAP[code]];
692 Compiler.prototype = {
695 disassemble: function() {
696 var opcodes = this.opcodes, opcode, nextCode;
697 var out = [], str, name, value;
699 for(var i=0, l=opcodes.length; i<l; i++) {
702 if(opcode === 'DECLARE') {
704 value = opcodes[++i];
705 out.push("DECLARE " + name + " = " + value);
707 str = Compiler.DISASSEMBLE_MAP[opcode];
709 var extraParams = Compiler.multiParamSize(opcode);
712 for(var j=0; j<extraParams; j++) {
713 nextCode = opcodes[++i];
715 if(typeof nextCode === "string") {
716 nextCode = "\"" + nextCode.replace("\n", "\\n") + "\"";
719 codes.push(nextCode);
722 str = str + " " + codes.join(" ");
728 return out.join("\n");
733 compile: function(program, options) {
735 this.depths = {list: []};
736 this.options = options;
738 // These changes will propagate to the other compiler components
739 var knownHelpers = this.options.knownHelpers;
740 this.options.knownHelpers = {
741 'helperMissing': true,
742 'blockHelperMissing': true,
750 for (var name in knownHelpers) {
751 this.options.knownHelpers[name] = knownHelpers[name];
755 return this.program(program);
758 accept: function(node) {
759 return this[node.type](node);
762 program: function(program) {
763 var statements = program.statements, statement;
766 for(var i=0, l=statements.length; i<l; i++) {
767 statement = statements[i];
768 this[statement.type](statement);
770 this.isSimple = l === 1;
772 this.depths.list = this.depths.list.sort(function(a, b) {
779 compileProgram: function(program) {
780 var result = new this.compiler().compile(program, this.options);
781 var guid = this.guid++, depth;
783 this.usePartial = this.usePartial || result.usePartial;
785 this.children[guid] = result;
787 for(var i=0, l=result.depths.list.length; i<l; i++) {
788 depth = result.depths.list[i];
790 if(depth < 2) { continue; }
791 else { this.addDepth(depth - 1); }
797 block: function(block) {
798 var mustache = block.mustache;
799 var depth, child, inverse, inverseGuid;
801 var params = this.setupStackForMustache(mustache);
803 var programGuid = this.compileProgram(block.program);
805 if(block.program.inverse) {
806 inverseGuid = this.compileProgram(block.program.inverse);
807 this.declare('inverse', inverseGuid);
810 this.opcode('invokeProgram', programGuid, params.length, !!mustache.hash);
811 this.declare('inverse', null);
812 this.opcode('append');
815 inverse: function(block) {
816 var params = this.setupStackForMustache(block.mustache);
818 var programGuid = this.compileProgram(block.program);
820 this.declare('inverse', programGuid);
822 this.opcode('invokeProgram', null, params.length, !!block.mustache.hash);
823 this.declare('inverse', null);
824 this.opcode('append');
827 hash: function(hash) {
828 var pairs = hash.pairs, pair, val;
830 this.opcode('push', '{}');
832 for(var i=0, l=pairs.length; i<l; i++) {
837 this.opcode('assignToHash', pair[0]);
841 partial: function(partial) {
843 this.usePartial = true;
845 if(partial.context) {
846 this.ID(partial.context);
848 this.opcode('push', 'depth0');
851 this.opcode('invokePartial', id.original);
852 this.opcode('append');
855 content: function(content) {
856 this.opcode('appendContent', content.string);
859 mustache: function(mustache) {
860 var params = this.setupStackForMustache(mustache);
862 this.opcode('invokeMustache', params.length, mustache.id.original, !!mustache.hash);
864 if(mustache.escaped && !this.options.noEscape) {
865 this.opcode('appendEscaped');
867 this.opcode('append');
872 this.addDepth(id.depth);
874 this.opcode('getContext', id.depth);
876 this.opcode('lookupWithHelpers', id.parts[0] || null, id.isScoped || false);
878 for(var i=1, l=id.parts.length; i<l; i++) {
879 this.opcode('lookup', id.parts[i]);
883 STRING: function(string) {
884 this.opcode('pushString', string.string);
887 INTEGER: function(integer) {
888 this.opcode('push', integer.integer);
891 BOOLEAN: function(bool) {
892 this.opcode('push', bool.bool);
895 comment: function() {},
898 pushParams: function(params) {
899 var i = params.length, param;
904 if(this.options.stringParams) {
906 this.addDepth(param.depth);
909 this.opcode('getContext', param.depth || 0);
910 this.opcode('pushStringParam', param.string);
912 this[param.type](param);
917 opcode: function(name, val1, val2, val3) {
918 this.opcodes.push(Compiler.OPCODE_MAP[name]);
919 if(val1 !== undefined) { this.opcodes.push(val1); }
920 if(val2 !== undefined) { this.opcodes.push(val2); }
921 if(val3 !== undefined) { this.opcodes.push(val3); }
924 declare: function(name, value) {
925 this.opcodes.push('DECLARE');
926 this.opcodes.push(name);
927 this.opcodes.push(value);
930 addDepth: function(depth) {
931 if(depth === 0) { return; }
933 if(!this.depths[depth]) {
934 this.depths[depth] = true;
935 this.depths.list.push(depth);
939 setupStackForMustache: function(mustache) {
940 var params = mustache.params;
942 this.pushParams(params);
945 this.hash(mustache.hash);
948 this.ID(mustache.id);
954 JavaScriptCompiler.prototype = {
955 // PUBLIC API: You can override these methods in a subclass to provide
956 // alternative compiled forms for name lookup and buffering semantics
957 nameLookup: function(parent, name, type) {
958 if (/^[0-9]+$/.test(name)) {
959 return parent + "[" + name + "]";
960 } else if (JavaScriptCompiler.isValidJavaScriptVariableName(name)) {
961 return parent + "." + name;
964 return parent + "['" + name + "']";
968 appendToBuffer: function(string) {
969 if (this.environment.isSimple) {
970 return "return " + string + ";";
972 return "buffer += " + string + ";";
976 initializeBuffer: function() {
977 return this.quotedString("");
980 namespace: "Handlebars",
983 compile: function(environment, options, context, asObject) {
984 this.environment = environment;
985 this.options = options || {};
987 this.name = this.environment.name;
988 this.isChild = !!context;
989 this.context = context || {
991 aliases: { self: 'this' },
992 registers: {list: []}
1000 this.compileChildren(environment, options);
1002 var opcodes = environment.opcodes, opcode;
1006 for(l=opcodes.length; this.i<l; this.i++) {
1007 opcode = this.nextOpcode(0);
1009 if(opcode[0] === 'DECLARE') {
1010 this.i = this.i + 2;
1011 this[opcode[1]] = opcode[2];
1013 this.i = this.i + opcode[1].length;
1014 this[opcode[0]].apply(this, opcode[1]);
1018 return this.createFunctionContext(asObject);
1021 nextOpcode: function(n) {
1022 var opcodes = this.environment.opcodes, opcode = opcodes[this.i + n], name, val;
1023 var extraParams, codes;
1025 if(opcode === 'DECLARE') {
1026 name = opcodes[this.i + 1];
1027 val = opcodes[this.i + 2];
1028 return ['DECLARE', name, val];
1030 name = Compiler.DISASSEMBLE_MAP[opcode];
1032 extraParams = Compiler.multiParamSize(opcode);
1035 for(var j=0; j<extraParams; j++) {
1036 codes.push(opcodes[this.i + j + 1 + n]);
1039 return [name, codes];
1043 eat: function(opcode) {
1044 this.i = this.i + opcode.length;
1047 preamble: function() {
1050 // this register will disambiguate helper lookup from finding a function in
1051 // a context. This is necessary for mustache compatibility, which requires
1052 // that context functions in blocks are evaluated by blockHelperMissing, and
1053 // then proceed as if the resulting value was provided to blockHelperMissing.
1054 this.useRegister('foundHelper');
1056 if (!this.isChild) {
1057 var namespace = this.namespace;
1058 var copies = "helpers = helpers || " + namespace + ".helpers;";
1059 if(this.environment.usePartial) { copies = copies + " partials = partials || " + namespace + ".partials;"; }
1065 if (!this.environment.isSimple) {
1066 out.push(", buffer = " + this.initializeBuffer());
1071 // track the last context pushed into place to allow skipping the
1072 // getContext opcode when it would be a noop
1073 this.lastContext = 0;
1077 createFunctionContext: function(asObject) {
1078 var locals = this.stackVars;
1079 if (!this.isChild) {
1080 locals = locals.concat(this.context.registers.list);
1083 if(locals.length > 0) {
1084 this.source[1] = this.source[1] + ", " + locals.join(", ");
1087 // Generate minimizer alias mappings
1088 if (!this.isChild) {
1090 for (var alias in this.context.aliases) {
1091 this.source[1] = this.source[1] + ', ' + alias + '=' + this.context.aliases[alias];
1095 if (this.source[1]) {
1096 this.source[1] = "var " + this.source[1].substring(2) + ";";
1100 if (!this.isChild) {
1101 this.source[1] += '\n' + this.context.programs.join('\n') + '\n';
1104 if (!this.environment.isSimple) {
1105 this.source.push("return buffer;");
1108 var params = this.isChild ? ["depth0", "data"] : ["Handlebars", "depth0", "helpers", "partials", "data"];
1110 for(var i=0, l=this.environment.depths.list.length; i<l; i++) {
1111 params.push("depth" + this.environment.depths.list[i]);
1115 params.push(this.source.join("\n "));
1117 return Function.apply(this, params);
1119 var functionSource = 'function ' + (this.name || '') + '(' + params.join(',') + ') {\n ' + this.source.join("\n ") + '}';
1120 Handlebars.log(Handlebars.logger.DEBUG, functionSource + "\n\n");
1121 return functionSource;
1125 appendContent: function(content) {
1126 this.source.push(this.appendToBuffer(this.quotedString(content)));
1129 append: function() {
1130 var local = this.popStack();
1131 this.source.push("if(" + local + " || " + local + " === 0) { " + this.appendToBuffer(local) + " }");
1132 if (this.environment.isSimple) {
1133 this.source.push("else { " + this.appendToBuffer("''") + " }");
1137 appendEscaped: function() {
1138 var opcode = this.nextOpcode(1), extra = "";
1139 this.context.aliases.escapeExpression = 'this.escapeExpression';
1141 if(opcode[0] === 'appendContent') {
1142 extra = " + " + this.quotedString(opcode[1][0]);
1146 this.source.push(this.appendToBuffer("escapeExpression(" + this.popStack() + ")" + extra));
1149 getContext: function(depth) {
1150 if(this.lastContext !== depth) {
1151 this.lastContext = depth;
1155 lookupWithHelpers: function(name, isScoped) {
1157 var topStack = this.nextStack();
1159 this.usingKnownHelper = false;
1162 if (!isScoped && this.options.knownHelpers[name]) {
1163 toPush = topStack + " = " + this.nameLookup('helpers', name, 'helper');
1164 this.usingKnownHelper = true;
1165 } else if (isScoped || this.options.knownHelpersOnly) {
1166 toPush = topStack + " = " + this.nameLookup('depth' + this.lastContext, name, 'context');
1168 this.register('foundHelper', this.nameLookup('helpers', name, 'helper'));
1169 toPush = topStack + " = foundHelper || " + this.nameLookup('depth' + this.lastContext, name, 'context');
1173 this.source.push(toPush);
1175 this.pushStack('depth' + this.lastContext);
1179 lookup: function(name) {
1180 var topStack = this.topStack();
1181 this.source.push(topStack + " = (" + topStack + " === null || " + topStack + " === undefined || " + topStack + " === false ? " +
1182 topStack + " : " + this.nameLookup(topStack, name, 'context') + ");");
1185 pushStringParam: function(string) {
1186 this.pushStack('depth' + this.lastContext);
1187 this.pushString(string);
1190 pushString: function(string) {
1191 this.pushStack(this.quotedString(string));
1194 push: function(name) {
1195 this.pushStack(name);
1198 invokeMustache: function(paramSize, original, hasHash) {
1199 this.populateParams(paramSize, this.quotedString(original), "{}", null, hasHash, function(nextStack, helperMissingString, id) {
1200 if (!this.usingKnownHelper) {
1201 this.context.aliases.helperMissing = 'helpers.helperMissing';
1202 this.context.aliases.undef = 'void 0';
1203 this.source.push("else if(" + id + "=== undef) { " + nextStack + " = helperMissing.call(" + helperMissingString + "); }");
1204 if (nextStack !== id) {
1205 this.source.push("else { " + nextStack + " = " + id + "; }");
1211 invokeProgram: function(guid, paramSize, hasHash) {
1212 var inverse = this.programExpression(this.inverse);
1213 var mainProgram = this.programExpression(guid);
1215 this.populateParams(paramSize, null, mainProgram, inverse, hasHash, function(nextStack, helperMissingString, id) {
1216 if (!this.usingKnownHelper) {
1217 this.context.aliases.blockHelperMissing = 'helpers.blockHelperMissing';
1218 this.source.push("else { " + nextStack + " = blockHelperMissing.call(" + helperMissingString + "); }");
1223 populateParams: function(paramSize, helperId, program, inverse, hasHash, fn) {
1224 var needsRegister = hasHash || this.options.stringParams || inverse || this.options.data;
1225 var id = this.popStack(), nextStack;
1226 var params = [], param, stringParam, stringOptions;
1228 if (needsRegister) {
1229 this.register('tmp1', program);
1230 stringOptions = 'tmp1';
1232 stringOptions = '{ hash: {} }';
1235 if (needsRegister) {
1236 var hash = (hasHash ? this.popStack() : '{}');
1237 this.source.push('tmp1.hash = ' + hash + ';');
1240 if(this.options.stringParams) {
1241 this.source.push('tmp1.contexts = [];');
1244 for(var i=0; i<paramSize; i++) {
1245 param = this.popStack();
1248 if(this.options.stringParams) {
1249 this.source.push('tmp1.contexts.push(' + this.popStack() + ');');
1254 this.source.push('tmp1.fn = tmp1;');
1255 this.source.push('tmp1.inverse = ' + inverse + ';');
1258 if(this.options.data) {
1259 this.source.push('tmp1.data = data;');
1262 params.push(stringOptions);
1264 this.populateCall(params, id, helperId || id, fn, program !== '{}');
1267 populateCall: function(params, id, helperId, fn, program) {
1268 var paramString = ["depth0"].concat(params).join(", ");
1269 var helperMissingString = ["depth0"].concat(helperId).concat(params).join(", ");
1271 var nextStack = this.nextStack();
1273 if (this.usingKnownHelper) {
1274 this.source.push(nextStack + " = " + id + ".call(" + paramString + ");");
1276 this.context.aliases.functionType = '"function"';
1277 var condition = program ? "foundHelper && " : "";
1278 this.source.push("if(" + condition + "typeof " + id + " === functionType) { " + nextStack + " = " + id + ".call(" + paramString + "); }");
1280 fn.call(this, nextStack, helperMissingString, id);
1281 this.usingKnownHelper = false;
1284 invokePartial: function(context) {
1285 var params = [this.nameLookup('partials', context, 'partial'), "'" + context + "'", this.popStack(), "helpers", "partials"];
1287 if (this.options.data) {
1288 params.push("data");
1291 this.pushStack("self.invokePartial(" + params.join(", ") + ");");
1294 assignToHash: function(key) {
1295 var value = this.popStack();
1296 var hash = this.topStack();
1298 this.source.push(hash + "['" + key + "'] = " + value + ";");
1303 compiler: JavaScriptCompiler,
1305 compileChildren: function(environment, options) {
1306 var children = environment.children, child, compiler;
1308 for(var i=0, l=children.length; i<l; i++) {
1309 child = children[i];
1310 compiler = new this.compiler();
1312 this.context.programs.push(''); // Placeholder to prevent name conflicts for nested children
1313 var index = this.context.programs.length;
1314 child.index = index;
1315 child.name = 'program' + index;
1316 this.context.programs[index] = compiler.compile(child, options, this.context);
1320 programExpression: function(guid) {
1321 if(guid == null) { return "self.noop"; }
1323 var child = this.environment.children[guid],
1324 depths = child.depths.list, depth;
1326 var programParams = [child.index, child.name, "data"];
1328 for(var i=0, l = depths.length; i<l; i++) {
1331 if(depth === 1) { programParams.push("depth0"); }
1332 else { programParams.push("depth" + (depth - 1)); }
1335 if(depths.length === 0) {
1336 return "self.program(" + programParams.join(", ") + ")";
1338 programParams.shift();
1339 return "self.programWithDepth(" + programParams.join(", ") + ")";
1343 register: function(name, val) {
1344 this.useRegister(name);
1345 this.source.push(name + " = " + val + ";");
1348 useRegister: function(name) {
1349 if(!this.context.registers[name]) {
1350 this.context.registers[name] = true;
1351 this.context.registers.list.push(name);
1355 pushStack: function(item) {
1356 this.source.push(this.nextStack() + " = " + item + ";");
1357 return "stack" + this.stackSlot;
1360 nextStack: function() {
1362 if(this.stackSlot > this.stackVars.length) { this.stackVars.push("stack" + this.stackSlot); }
1363 return "stack" + this.stackSlot;
1366 popStack: function() {
1367 return "stack" + this.stackSlot--;
1370 topStack: function() {
1371 return "stack" + this.stackSlot;
1374 quotedString: function(str) {
1376 .replace(/\\/g, '\\\\')
1377 .replace(/"/g, '\\"')
1378 .replace(/\n/g, '\\n')
1379 .replace(/\r/g, '\\r') + '"';
1383 var reservedWords = (
1384 "break else new var" +
1385 " case finally return void" +
1386 " catch for switch while" +
1387 " continue function this with" +
1388 " default if throw" +
1390 " do instanceof typeof" +
1391 " abstract enum int short" +
1392 " boolean export interface static" +
1393 " byte extends long super" +
1394 " char final native synchronized" +
1395 " class float package throws" +
1396 " const goto private transient" +
1397 " debugger implements protected volatile" +
1398 " double import public let yield"
1401 var compilerWords = JavaScriptCompiler.RESERVED_WORDS = {};
1403 for(var i=0, l=reservedWords.length; i<l; i++) {
1404 compilerWords[reservedWords[i]] = true;
1407 JavaScriptCompiler.isValidJavaScriptVariableName = function(name) {
1408 if(!JavaScriptCompiler.RESERVED_WORDS[name] && /^[a-zA-Z_$][0-9a-zA-Z_$]+$/.test(name)) {
1414 })(Handlebars.Compiler, Handlebars.JavaScriptCompiler);
1416 Handlebars.precompile = function(string, options) {
1417 options = options || {};
1419 var ast = Handlebars.parse(string);
1420 var environment = new Handlebars.Compiler().compile(ast, options);
1421 return new Handlebars.JavaScriptCompiler().compile(environment, options);
1424 Handlebars.compile = function(string, options) {
1425 options = options || {};
1428 function compile() {
1429 var ast = Handlebars.parse(string);
1430 var environment = new Handlebars.Compiler().compile(ast, options);
1431 var templateSpec = new Handlebars.JavaScriptCompiler().compile(environment, options, undefined, true);
1432 return Handlebars.template(templateSpec);
1435 // Template is only compiled on first use and cached after that point.
1436 return function(context, options) {
1438 compiled = compile();
1440 return compiled.call(this, context, options);
1445 // This file contains YUI-specific wrapper code and overrides for the
1446 // handlebars-compiler module.
1449 Handlebars parser and compiler. Use this module when you need to compile
1450 Handlebars templates.
1453 @submodule handlebars-compiler
1456 var levels = ['debug', 'info', 'warn', 'error'];
1459 Logs a debugging message. Note that messages will only be logged when the
1460 handlebars module is loaded in "debug" mode.
1463 @param {String} level Log level for this message. Supported levels are "debug",
1464 "info", "warn", and "error".
1465 @param {String} message Message to log.
1468 Handlebars.logger.log = function (level, message) {
1469 Y.log(message, levels[level] || 'error', 'Handlebars');
1473 Compiles and renders a Handlebars template string.
1477 Y.Handlebars.render('The pie of the day is {{pie}}!', {
1478 pie: 'Maple Custard'
1480 // => "The pie of the day is Maple Custard!"
1483 @param {String} string Handlebars template string to render.
1484 @param {Object} context Context object to pass to the template.
1485 @param {Object} [options] Compile/render options.
1486 @param {Object} [options.helpers] Helper functions.
1487 @param {Object} [options.partials] Partials.
1488 @param {Object} [options.data] Data.
1489 @return {String} Rendered template string.
1491 Handlebars.render = function (string, context, options) {
1492 return Handlebars.compile(string)(context, options);
1495 // The rest of this file is just API docs for methods defined in Handlebars
1499 Compiles a Handlebars template string into a function. To render the template,
1500 call the function and pass in a context object.
1504 var template = Y.Handlebars.compile('The pie of the day is {{pie}}!.');
1505 template({pie: 'Pecan'});
1506 // => "The pie of the day is Pecan!"
1509 @param {String} string Handlebars template string to compile.
1510 @param {Object} [options] Compiler options.
1511 @return {Function} Compiled template function.
1515 Precompiles a Handlebars template string into a string of JavaScript code. This
1516 can be used to precompile a template at build time or on the server, and the
1517 resulting template can then be rendered at runtime or on the client without
1518 needing to go through a compile step.
1520 To render a precompiled template, evaluate the code and then pass the resulting
1521 function to `Y.Handlebars.template()` to get back an executable template
1525 @param {String} string Handlebars template string to compile.
1526 @param {Object} [options] Compiler options.
1527 @return {String} Precompiled template code.
1531 }, '3.5.0' ,{requires:['handlebars-base']});