handlebars-source 1.0.12 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of handlebars-source might be problematic. Click here for more details.

@@ -1,374 +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
- @license
24
- */
25
-
26
- // lib/handlebars/browser-prefix.js
27
- (function(undefined) {
28
- var Handlebars = {};
29
- ;
30
- // lib/handlebars/base.js
31
-
32
- Handlebars.VERSION = "1.0.0";
33
- Handlebars.COMPILER_REVISION = 4;
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
- 3: '== 1.0.0-rc.4',
39
- 4: '>= 1.0.0'
40
- };
41
-
42
- Handlebars.helpers = {};
43
- Handlebars.partials = {};
44
-
45
- var toString = Object.prototype.toString,
46
- functionType = '[object Function]',
47
- objectType = '[object Object]';
48
-
49
- Handlebars.registerHelper = function(name, fn, inverse) {
50
- if (toString.call(name) === objectType) {
51
- if (inverse || fn) { throw new Handlebars.Exception('Arg not supported with multiple helpers'); }
52
- Handlebars.Utils.extend(this.helpers, name);
53
- } else {
54
- if (inverse) { fn.not = inverse; }
55
- this.helpers[name] = fn;
56
- }
57
- };
58
-
59
- Handlebars.registerPartial = function(name, str) {
60
- if (toString.call(name) === objectType) {
61
- Handlebars.Utils.extend(this.partials, name);
62
- } else {
63
- this.partials[name] = str;
64
- }
65
- };
66
-
67
- Handlebars.registerHelper('helperMissing', function(arg) {
68
- if(arguments.length === 2) {
69
- return undefined;
70
- } else {
71
- throw new Error("Missing helper: '" + arg + "'");
72
- }
73
- });
74
-
75
- Handlebars.registerHelper('blockHelperMissing', function(context, options) {
76
- var inverse = options.inverse || function() {}, fn = options.fn;
77
-
78
- var type = toString.call(context);
79
-
80
- if(type === functionType) { context = context.call(this); }
81
-
82
- if(context === true) {
83
- return fn(this);
84
- } else if(context === false || context == null) {
85
- return inverse(this);
86
- } else if(type === "[object Array]") {
87
- if(context.length > 0) {
88
- return Handlebars.helpers.each(context, options);
89
- } else {
90
- return inverse(this);
91
- }
92
- } else {
93
- return fn(context);
94
- }
95
- });
96
-
97
- Handlebars.K = function() {};
98
-
99
- Handlebars.createFrame = Object.create || function(object) {
100
- Handlebars.K.prototype = object;
101
- var obj = new Handlebars.K();
102
- Handlebars.K.prototype = null;
103
- return obj;
104
- };
105
-
106
- Handlebars.logger = {
107
- DEBUG: 0, INFO: 1, WARN: 2, ERROR: 3, level: 3,
108
-
109
- methodMap: {0: 'debug', 1: 'info', 2: 'warn', 3: 'error'},
110
-
111
- // can be overridden in the host environment
112
- log: function(level, obj) {
113
- if (Handlebars.logger.level <= level) {
114
- var method = Handlebars.logger.methodMap[level];
115
- if (typeof console !== 'undefined' && console[method]) {
116
- console[method].call(console, obj);
117
- }
118
- }
119
- }
120
- };
121
-
122
- Handlebars.log = function(level, obj) { Handlebars.logger.log(level, obj); };
123
-
124
- Handlebars.registerHelper('each', function(context, options) {
125
- var fn = options.fn, inverse = options.inverse;
126
- var i = 0, ret = "", data;
127
-
128
- var type = toString.call(context);
129
- if(type === functionType) { context = context.call(this); }
130
-
131
- if (options.data) {
132
- data = Handlebars.createFrame(options.data);
133
- }
134
-
135
- if(context && typeof context === 'object') {
136
- if(context instanceof Array){
137
- for(var j = context.length; i<j; i++) {
138
- if (data) { data.index = i; }
139
- ret = ret + fn(context[i], { data: data });
140
- }
141
- } else {
142
- for(var key in context) {
143
- if(context.hasOwnProperty(key)) {
144
- if(data) { data.key = key; }
145
- ret = ret + fn(context[key], {data: data});
146
- i++;
147
- }
148
- }
149
- }
150
- }
151
-
152
- if(i === 0){
153
- ret = inverse(this);
154
- }
155
-
156
- return ret;
157
- });
158
-
159
- Handlebars.registerHelper('if', function(conditional, options) {
160
- var type = toString.call(conditional);
161
- if(type === functionType) { conditional = conditional.call(this); }
162
-
163
- if(!conditional || Handlebars.Utils.isEmpty(conditional)) {
164
- return options.inverse(this);
165
- } else {
166
- return options.fn(this);
167
- }
168
- });
169
-
170
- Handlebars.registerHelper('unless', function(conditional, options) {
171
- return Handlebars.helpers['if'].call(this, conditional, {fn: options.inverse, inverse: options.fn});
172
- });
173
-
174
- Handlebars.registerHelper('with', function(context, options) {
175
- var type = toString.call(context);
176
- if(type === functionType) { context = context.call(this); }
177
-
178
- if (!Handlebars.Utils.isEmpty(context)) return options.fn(context);
179
- });
180
-
181
- Handlebars.registerHelper('log', function(context, options) {
182
- var level = options.data && options.data.level != null ? parseInt(options.data.level, 10) : 1;
183
- Handlebars.log(level, context);
184
- });
185
- ;
186
- // lib/handlebars/utils.js
187
-
188
- var errorProps = ['description', 'fileName', 'lineNumber', 'message', 'name', 'number', 'stack'];
189
-
190
- Handlebars.Exception = function(message) {
191
- var tmp = Error.prototype.constructor.apply(this, arguments);
192
-
193
- // Unfortunately errors are not enumerable in Chrome (at least), so `for prop in tmp` doesn't work.
194
- for (var idx = 0; idx < errorProps.length; idx++) {
195
- this[errorProps[idx]] = tmp[errorProps[idx]];
196
- }
197
- };
198
- Handlebars.Exception.prototype = new Error();
199
-
200
- // Build out our basic SafeString type
201
- Handlebars.SafeString = function(string) {
202
- this.string = string;
203
- };
204
- Handlebars.SafeString.prototype.toString = function() {
205
- return this.string.toString();
206
- };
207
-
208
- var escape = {
209
- "&": "&amp;",
210
- "<": "&lt;",
211
- ">": "&gt;",
212
- '"': "&quot;",
213
- "'": "&#x27;",
214
- "`": "&#x60;"
215
- };
216
-
217
- var badChars = /[&<>"'`]/g;
218
- var possible = /[&<>"'`]/;
219
-
220
- var escapeChar = function(chr) {
221
- return escape[chr] || "&amp;";
222
- };
223
-
224
- Handlebars.Utils = {
225
- extend: function(obj, value) {
226
- for(var key in value) {
227
- if(value.hasOwnProperty(key)) {
228
- obj[key] = value[key];
229
- }
230
- }
231
- },
232
-
233
- escapeExpression: function(string) {
234
- // don't escape SafeStrings, since they're already safe
235
- if (string instanceof Handlebars.SafeString) {
236
- return string.toString();
237
- } else if (string == null || string === false) {
238
- return "";
239
- }
240
-
241
- // Force a string conversion as this will be done by the append regardless and
242
- // the regex test will do this transparently behind the scenes, causing issues if
243
- // an object's to string has escaped characters in it.
244
- string = string.toString();
245
-
246
- if(!possible.test(string)) { return string; }
247
- return string.replace(badChars, escapeChar);
248
- },
249
-
250
- isEmpty: function(value) {
251
- if (!value && value !== 0) {
252
- return true;
253
- } else if(toString.call(value) === "[object Array]" && value.length === 0) {
254
- return true;
255
- } else {
256
- return false;
257
- }
258
- }
259
- };
260
- ;
261
- // lib/handlebars/runtime.js
262
-
263
- Handlebars.VM = {
264
- template: function(templateSpec) {
265
- // Just add water
266
- var container = {
267
- escapeExpression: Handlebars.Utils.escapeExpression,
268
- invokePartial: Handlebars.VM.invokePartial,
269
- programs: [],
270
- program: function(i, fn, data) {
271
- var programWrapper = this.programs[i];
272
- if(data) {
273
- programWrapper = Handlebars.VM.program(i, fn, data);
274
- } else if (!programWrapper) {
275
- programWrapper = this.programs[i] = Handlebars.VM.program(i, fn);
276
- }
277
- return programWrapper;
278
- },
279
- merge: function(param, common) {
280
- var ret = param || common;
281
-
282
- if (param && common) {
283
- ret = {};
284
- Handlebars.Utils.extend(ret, common);
285
- Handlebars.Utils.extend(ret, param);
286
- }
287
- return ret;
288
- },
289
- programWithDepth: Handlebars.VM.programWithDepth,
290
- noop: Handlebars.VM.noop,
291
- compilerInfo: null
292
- };
293
-
294
- return function(context, options) {
295
- options = options || {};
296
- var result = templateSpec.call(container, Handlebars, context, options.helpers, options.partials, options.data);
297
-
298
- var compilerInfo = container.compilerInfo || [],
299
- compilerRevision = compilerInfo[0] || 1,
300
- currentRevision = Handlebars.COMPILER_REVISION;
301
-
302
- if (compilerRevision !== currentRevision) {
303
- if (compilerRevision < currentRevision) {
304
- var runtimeVersions = Handlebars.REVISION_CHANGES[currentRevision],
305
- compilerVersions = Handlebars.REVISION_CHANGES[compilerRevision];
306
- throw "Template was precompiled with an older version of Handlebars than the current runtime. "+
307
- "Please update your precompiler to a newer version ("+runtimeVersions+") or downgrade your runtime to an older version ("+compilerVersions+").";
308
- } else {
309
- // Use the embedded version info since the runtime doesn't know about this revision yet
310
- throw "Template was precompiled with a newer version of Handlebars than the current runtime. "+
311
- "Please update your runtime to a newer version ("+compilerInfo[1]+").";
312
- }
313
- }
314
-
315
- return result;
316
- };
317
- },
318
-
319
- programWithDepth: function(i, fn, data /*, $depth */) {
320
- var args = Array.prototype.slice.call(arguments, 3);
321
-
322
- var program = function(context, options) {
323
- options = options || {};
324
-
325
- return fn.apply(this, [context, options.data || data].concat(args));
326
- };
327
- program.program = i;
328
- program.depth = args.length;
329
- return program;
330
- },
331
- program: function(i, fn, data) {
332
- var program = function(context, options) {
333
- options = options || {};
334
-
335
- return fn(context, options.data || data);
336
- };
337
- program.program = i;
338
- program.depth = 0;
339
- return program;
340
- },
341
- noop: function() { return ""; },
342
- invokePartial: function(partial, name, context, helpers, partials, data) {
343
- var options = { helpers: helpers, partials: partials, data: data };
344
-
345
- if(partial === undefined) {
346
- throw new Handlebars.Exception("The partial " + name + " could not be found");
347
- } else if(partial instanceof Function) {
348
- return partial(context, options);
349
- } else if (!Handlebars.compile) {
350
- throw new Handlebars.Exception("The partial " + name + " could not be compiled when running in runtime-only mode");
351
- } else {
352
- partials[name] = Handlebars.compile(partial, {data: data !== undefined});
353
- return partials[name](context, options);
354
- }
355
- }
356
- };
357
-
358
- Handlebars.template = Handlebars.VM.template;
359
- ;
360
- // lib/handlebars/browser-suffix.js
361
- if (typeof module === 'object' && module.exports) {
362
- // CommonJS
363
- module.exports = Handlebars;
364
-
365
- } else if (typeof define === "function" && define.amd) {
366
- // AMD modules
367
- define(function() { return Handlebars; });
368
-
369
- } else {
370
- // other, i.e. browser
371
- this.Handlebars = Handlebars;
372
- }
373
- }).call(this);
374
- ;