handlebars 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +1 -2
  3. data/README.mdown +15 -7
  4. data/handlebars.gemspec +2 -5
  5. data/lib/handlebars.rb +5 -5
  6. data/lib/handlebars/context.rb +3 -12
  7. data/lib/handlebars/version.rb +1 -1
  8. data/spec/handlebars_spec.rb +1 -1
  9. metadata +47 -58
  10. data/.gitmodules +0 -3
  11. data/vendor/handlebars/.gitignore +0 -8
  12. data/vendor/handlebars/.jshintrc +0 -52
  13. data/vendor/handlebars/.npmignore +0 -10
  14. data/vendor/handlebars/.rspec +0 -1
  15. data/vendor/handlebars/Gemfile +0 -5
  16. data/vendor/handlebars/LICENSE +0 -19
  17. data/vendor/handlebars/README.markdown +0 -317
  18. data/vendor/handlebars/Rakefile +0 -109
  19. data/vendor/handlebars/bench/benchwarmer.js +0 -149
  20. data/vendor/handlebars/bench/handlebars.js +0 -172
  21. data/vendor/handlebars/bin/handlebars +0 -193
  22. data/vendor/handlebars/dist/handlebars.js +0 -2201
  23. data/vendor/handlebars/dist/handlebars.runtime.js +0 -321
  24. data/vendor/handlebars/lib/handlebars.js +0 -14
  25. data/vendor/handlebars/lib/handlebars/base.js +0 -154
  26. data/vendor/handlebars/lib/handlebars/compiler/ast.js +0 -133
  27. data/vendor/handlebars/lib/handlebars/compiler/base.js +0 -21
  28. data/vendor/handlebars/lib/handlebars/compiler/compiler.js +0 -1267
  29. data/vendor/handlebars/lib/handlebars/compiler/index.js +0 -7
  30. data/vendor/handlebars/lib/handlebars/compiler/printer.js +0 -131
  31. data/vendor/handlebars/lib/handlebars/compiler/visitor.js +0 -13
  32. data/vendor/handlebars/lib/handlebars/runtime.js +0 -88
  33. data/vendor/handlebars/lib/handlebars/utils.js +0 -67
  34. data/vendor/handlebars/package.json +0 -35
  35. data/vendor/handlebars/spec/acceptance_spec.rb +0 -101
  36. data/vendor/handlebars/spec/parser_spec.rb +0 -433
  37. data/vendor/handlebars/spec/qunit_spec.js +0 -1370
  38. data/vendor/handlebars/spec/spec_helper.rb +0 -157
  39. data/vendor/handlebars/spec/tokenizer_spec.rb +0 -301
  40. data/vendor/handlebars/src/handlebars.l +0 -53
  41. data/vendor/handlebars/src/handlebars.yy +0 -109
  42. data/vendor/handlebars/src/parser-prefix.js +0 -1
  43. data/vendor/handlebars/src/parser-suffix.js +0 -4
@@ -1,321 +0,0 @@
1
- /*
2
-
3
- Copyright (C) 2011 by Yehuda Katz
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
22
-
23
- */
24
-
25
- // lib/handlebars/base.js
26
-
27
- /*jshint eqnull:true*/
28
- this.Handlebars = {};
29
-
30
- (function(Handlebars) {
31
-
32
- Handlebars.VERSION = "1.0.0-rc.3";
33
- Handlebars.COMPILER_REVISION = 2;
34
-
35
- Handlebars.REVISION_CHANGES = {
36
- 1: '<= 1.0.rc.2', // 1.0.rc.2 is actually rev2 but doesn't report it
37
- 2: '>= 1.0.0-rc.3'
38
- };
39
-
40
- Handlebars.helpers = {};
41
- Handlebars.partials = {};
42
-
43
- Handlebars.registerHelper = function(name, fn, inverse) {
44
- if(inverse) { fn.not = inverse; }
45
- this.helpers[name] = fn;
46
- };
47
-
48
- Handlebars.registerPartial = function(name, str) {
49
- this.partials[name] = str;
50
- };
51
-
52
- Handlebars.registerHelper('helperMissing', function(arg) {
53
- if(arguments.length === 2) {
54
- return undefined;
55
- } else {
56
- throw new Error("Could not find property '" + arg + "'");
57
- }
58
- });
59
-
60
- var toString = Object.prototype.toString, functionType = "[object Function]";
61
-
62
- Handlebars.registerHelper('blockHelperMissing', function(context, options) {
63
- var inverse = options.inverse || function() {}, fn = options.fn;
64
-
65
-
66
- var ret = "";
67
- var type = toString.call(context);
68
-
69
- if(type === functionType) { context = context.call(this); }
70
-
71
- if(context === true) {
72
- return fn(this);
73
- } else if(context === false || context == null) {
74
- return inverse(this);
75
- } else if(type === "[object Array]") {
76
- if(context.length > 0) {
77
- return Handlebars.helpers.each(context, options);
78
- } else {
79
- return inverse(this);
80
- }
81
- } else {
82
- return fn(context);
83
- }
84
- });
85
-
86
- Handlebars.K = function() {};
87
-
88
- Handlebars.createFrame = Object.create || function(object) {
89
- Handlebars.K.prototype = object;
90
- var obj = new Handlebars.K();
91
- Handlebars.K.prototype = null;
92
- return obj;
93
- };
94
-
95
- Handlebars.logger = {
96
- DEBUG: 0, INFO: 1, WARN: 2, ERROR: 3, level: 3,
97
-
98
- methodMap: {0: 'debug', 1: 'info', 2: 'warn', 3: 'error'},
99
-
100
- // can be overridden in the host environment
101
- log: function(level, obj) {
102
- if (Handlebars.logger.level <= level) {
103
- var method = Handlebars.logger.methodMap[level];
104
- if (typeof console !== 'undefined' && console[method]) {
105
- console[method].call(console, obj);
106
- }
107
- }
108
- }
109
- };
110
-
111
- Handlebars.log = function(level, obj) { Handlebars.logger.log(level, obj); };
112
-
113
- Handlebars.registerHelper('each', function(context, options) {
114
- var fn = options.fn, inverse = options.inverse;
115
- var i = 0, ret = "", data;
116
-
117
- if (options.data) {
118
- data = Handlebars.createFrame(options.data);
119
- }
120
-
121
- if(context && typeof context === 'object') {
122
- if(context instanceof Array){
123
- for(var j = context.length; i<j; i++) {
124
- if (data) { data.index = i; }
125
- ret = ret + fn(context[i], { data: data });
126
- }
127
- } else {
128
- for(var key in context) {
129
- if(context.hasOwnProperty(key)) {
130
- if(data) { data.key = key; }
131
- ret = ret + fn(context[key], {data: data});
132
- i++;
133
- }
134
- }
135
- }
136
- }
137
-
138
- if(i === 0){
139
- ret = inverse(this);
140
- }
141
-
142
- return ret;
143
- });
144
-
145
- Handlebars.registerHelper('if', function(context, options) {
146
- var type = toString.call(context);
147
- if(type === functionType) { context = context.call(this); }
148
-
149
- if(!context || Handlebars.Utils.isEmpty(context)) {
150
- return options.inverse(this);
151
- } else {
152
- return options.fn(this);
153
- }
154
- });
155
-
156
- Handlebars.registerHelper('unless', function(context, options) {
157
- var fn = options.fn, inverse = options.inverse;
158
- options.fn = inverse;
159
- options.inverse = fn;
160
-
161
- return Handlebars.helpers['if'].call(this, context, options);
162
- });
163
-
164
- Handlebars.registerHelper('with', function(context, options) {
165
- return options.fn(context);
166
- });
167
-
168
- Handlebars.registerHelper('log', function(context, options) {
169
- var level = options.data && options.data.level != null ? parseInt(options.data.level, 10) : 1;
170
- Handlebars.log(level, context);
171
- });
172
-
173
- }(this.Handlebars));
174
- ;
175
- // lib/handlebars/utils.js
176
-
177
- var errorProps = ['description', 'fileName', 'lineNumber', 'message', 'name', 'number', 'stack'];
178
-
179
- Handlebars.Exception = function(message) {
180
- var tmp = Error.prototype.constructor.apply(this, arguments);
181
-
182
- // Unfortunately errors are not enumerable in Chrome (at least), so `for prop in tmp` doesn't work.
183
- for (var idx = 0; idx < errorProps.length; idx++) {
184
- this[errorProps[idx]] = tmp[errorProps[idx]];
185
- }
186
- };
187
- Handlebars.Exception.prototype = new Error();
188
-
189
- // Build out our basic SafeString type
190
- Handlebars.SafeString = function(string) {
191
- this.string = string;
192
- };
193
- Handlebars.SafeString.prototype.toString = function() {
194
- return this.string.toString();
195
- };
196
-
197
- (function() {
198
- var escape = {
199
- "&": "&amp;",
200
- "<": "&lt;",
201
- ">": "&gt;",
202
- '"': "&quot;",
203
- "'": "&#x27;",
204
- "`": "&#x60;"
205
- };
206
-
207
- var badChars = /[&<>"'`]/g;
208
- var possible = /[&<>"'`]/;
209
-
210
- var escapeChar = function(chr) {
211
- return escape[chr] || "&amp;";
212
- };
213
-
214
- Handlebars.Utils = {
215
- escapeExpression: function(string) {
216
- // don't escape SafeStrings, since they're already safe
217
- if (string instanceof Handlebars.SafeString) {
218
- return string.toString();
219
- } else if (string == null || string === false) {
220
- return "";
221
- }
222
-
223
- if(!possible.test(string)) { return string; }
224
- return string.replace(badChars, escapeChar);
225
- },
226
-
227
- isEmpty: function(value) {
228
- if (!value && value !== 0) {
229
- return true;
230
- } else if(Object.prototype.toString.call(value) === "[object Array]" && value.length === 0) {
231
- return true;
232
- } else {
233
- return false;
234
- }
235
- }
236
- };
237
- })();;
238
- // lib/handlebars/runtime.js
239
- Handlebars.VM = {
240
- template: function(templateSpec) {
241
- // Just add water
242
- var container = {
243
- escapeExpression: Handlebars.Utils.escapeExpression,
244
- invokePartial: Handlebars.VM.invokePartial,
245
- programs: [],
246
- program: function(i, fn, data) {
247
- var programWrapper = this.programs[i];
248
- if(data) {
249
- return Handlebars.VM.program(fn, data);
250
- } else if(programWrapper) {
251
- return programWrapper;
252
- } else {
253
- programWrapper = this.programs[i] = Handlebars.VM.program(fn);
254
- return programWrapper;
255
- }
256
- },
257
- programWithDepth: Handlebars.VM.programWithDepth,
258
- noop: Handlebars.VM.noop,
259
- compilerInfo: null
260
- };
261
-
262
- return function(context, options) {
263
- options = options || {};
264
- var result = templateSpec.call(container, Handlebars, context, options.helpers, options.partials, options.data);
265
-
266
- var compilerInfo = container.compilerInfo || [],
267
- compilerRevision = compilerInfo[0] || 1,
268
- currentRevision = Handlebars.COMPILER_REVISION;
269
-
270
- if (compilerRevision !== currentRevision) {
271
- if (compilerRevision < currentRevision) {
272
- var runtimeVersions = Handlebars.REVISION_CHANGES[currentRevision],
273
- compilerVersions = Handlebars.REVISION_CHANGES[compilerRevision];
274
- throw "Template was precompiled with an older version of Handlebars than the current runtime. "+
275
- "Please update your precompiler to a newer version ("+runtimeVersions+") or downgrade your runtime to an older version ("+compilerVersions+").";
276
- } else {
277
- // Use the embedded version info since the runtime doesn't know about this revision yet
278
- throw "Template was precompiled with a newer version of Handlebars than the current runtime. "+
279
- "Please update your runtime to a newer version ("+compilerInfo[1]+").";
280
- }
281
- }
282
-
283
- return result;
284
- };
285
- },
286
-
287
- programWithDepth: function(fn, data, $depth) {
288
- var args = Array.prototype.slice.call(arguments, 2);
289
-
290
- return function(context, options) {
291
- options = options || {};
292
-
293
- return fn.apply(this, [context, options.data || data].concat(args));
294
- };
295
- },
296
- program: function(fn, data) {
297
- return function(context, options) {
298
- options = options || {};
299
-
300
- return fn(context, options.data || data);
301
- };
302
- },
303
- noop: function() { return ""; },
304
- invokePartial: function(partial, name, context, helpers, partials, data) {
305
- var options = { helpers: helpers, partials: partials, data: data };
306
-
307
- if(partial === undefined) {
308
- throw new Handlebars.Exception("The partial " + name + " could not be found");
309
- } else if(partial instanceof Function) {
310
- return partial(context, options);
311
- } else if (!Handlebars.compile) {
312
- throw new Handlebars.Exception("The partial " + name + " could not be compiled when running in runtime-only mode");
313
- } else {
314
- partials[name] = Handlebars.compile(partial, {data: data !== undefined});
315
- return partials[name](context, options);
316
- }
317
- }
318
- };
319
-
320
- Handlebars.template = Handlebars.VM.template;
321
- ;
@@ -1,14 +0,0 @@
1
- var Handlebars = require("./handlebars/base");
2
- module.exports = Handlebars;
3
-
4
- // Each of these augment the Handlebars object. No need to setup here.
5
- // (This is done to easily share code between commonjs and browse envs)
6
- require("./handlebars/utils");
7
-
8
- require("./handlebars/compiler");
9
- require("./handlebars/runtime");
10
-
11
- // BEGIN(BROWSER)
12
-
13
- // END(BROWSER)
14
-
@@ -1,154 +0,0 @@
1
- // BEGIN(BROWSER)
2
-
3
- /*jshint eqnull:true*/
4
- this.Handlebars = {};
5
-
6
- (function(Handlebars) {
7
-
8
- Handlebars.VERSION = "1.0.0-rc.3";
9
- Handlebars.COMPILER_REVISION = 2;
10
-
11
- Handlebars.REVISION_CHANGES = {
12
- 1: '<= 1.0.rc.2', // 1.0.rc.2 is actually rev2 but doesn't report it
13
- 2: '>= 1.0.0-rc.3'
14
- };
15
-
16
- Handlebars.helpers = {};
17
- Handlebars.partials = {};
18
-
19
- Handlebars.registerHelper = function(name, fn, inverse) {
20
- if(inverse) { fn.not = inverse; }
21
- this.helpers[name] = fn;
22
- };
23
-
24
- Handlebars.registerPartial = function(name, str) {
25
- this.partials[name] = str;
26
- };
27
-
28
- Handlebars.registerHelper('helperMissing', function(arg) {
29
- if(arguments.length === 2) {
30
- return undefined;
31
- } else {
32
- throw new Error("Could not find property '" + arg + "'");
33
- }
34
- });
35
-
36
- var toString = Object.prototype.toString, functionType = "[object Function]";
37
-
38
- Handlebars.registerHelper('blockHelperMissing', function(context, options) {
39
- var inverse = options.inverse || function() {}, fn = options.fn;
40
-
41
-
42
- var ret = "";
43
- var type = toString.call(context);
44
-
45
- if(type === functionType) { context = context.call(this); }
46
-
47
- if(context === true) {
48
- return fn(this);
49
- } else if(context === false || context == null) {
50
- return inverse(this);
51
- } else if(type === "[object Array]") {
52
- if(context.length > 0) {
53
- return Handlebars.helpers.each(context, options);
54
- } else {
55
- return inverse(this);
56
- }
57
- } else {
58
- return fn(context);
59
- }
60
- });
61
-
62
- Handlebars.K = function() {};
63
-
64
- Handlebars.createFrame = Object.create || function(object) {
65
- Handlebars.K.prototype = object;
66
- var obj = new Handlebars.K();
67
- Handlebars.K.prototype = null;
68
- return obj;
69
- };
70
-
71
- Handlebars.logger = {
72
- DEBUG: 0, INFO: 1, WARN: 2, ERROR: 3, level: 3,
73
-
74
- methodMap: {0: 'debug', 1: 'info', 2: 'warn', 3: 'error'},
75
-
76
- // can be overridden in the host environment
77
- log: function(level, obj) {
78
- if (Handlebars.logger.level <= level) {
79
- var method = Handlebars.logger.methodMap[level];
80
- if (typeof console !== 'undefined' && console[method]) {
81
- console[method].call(console, obj);
82
- }
83
- }
84
- }
85
- };
86
-
87
- Handlebars.log = function(level, obj) { Handlebars.logger.log(level, obj); };
88
-
89
- Handlebars.registerHelper('each', function(context, options) {
90
- var fn = options.fn, inverse = options.inverse;
91
- var i = 0, ret = "", data;
92
-
93
- if (options.data) {
94
- data = Handlebars.createFrame(options.data);
95
- }
96
-
97
- if(context && typeof context === 'object') {
98
- if(context instanceof Array){
99
- for(var j = context.length; i<j; i++) {
100
- if (data) { data.index = i; }
101
- ret = ret + fn(context[i], { data: data });
102
- }
103
- } else {
104
- for(var key in context) {
105
- if(context.hasOwnProperty(key)) {
106
- if(data) { data.key = key; }
107
- ret = ret + fn(context[key], {data: data});
108
- i++;
109
- }
110
- }
111
- }
112
- }
113
-
114
- if(i === 0){
115
- ret = inverse(this);
116
- }
117
-
118
- return ret;
119
- });
120
-
121
- Handlebars.registerHelper('if', function(context, options) {
122
- var type = toString.call(context);
123
- if(type === functionType) { context = context.call(this); }
124
-
125
- if(!context || Handlebars.Utils.isEmpty(context)) {
126
- return options.inverse(this);
127
- } else {
128
- return options.fn(this);
129
- }
130
- });
131
-
132
- Handlebars.registerHelper('unless', function(context, options) {
133
- var fn = options.fn, inverse = options.inverse;
134
- options.fn = inverse;
135
- options.inverse = fn;
136
-
137
- return Handlebars.helpers['if'].call(this, context, options);
138
- });
139
-
140
- Handlebars.registerHelper('with', function(context, options) {
141
- return options.fn(context);
142
- });
143
-
144
- Handlebars.registerHelper('log', function(context, options) {
145
- var level = options.data && options.data.level != null ? parseInt(options.data.level, 10) : 1;
146
- Handlebars.log(level, context);
147
- });
148
-
149
- }(this.Handlebars));
150
-
151
- // END(BROWSER)
152
-
153
- module.exports = this.Handlebars;
154
-