booster 0.0.1

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