handlebars-source 1.0.12 → 1.1.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.

Potentially problematic release.


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

@@ -0,0 +1,540 @@
1
+ /*!
2
+
3
+ handlebars v1.1.1
4
+
5
+ Copyright (C) 2011 by Yehuda Katz
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in
15
+ all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ THE SOFTWARE.
24
+
25
+ @license
26
+ */
27
+ /*!
28
+
29
+ handlebars v1.1.1
30
+
31
+ Copyright (C) 2011 by Yehuda Katz
32
+
33
+ Permission is hereby granted, free of charge, to any person obtaining a copy
34
+ of this software and associated documentation files (the "Software"), to deal
35
+ in the Software without restriction, including without limitation the rights
36
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
37
+ copies of the Software, and to permit persons to whom the Software is
38
+ furnished to do so, subject to the following conditions:
39
+
40
+ The above copyright notice and this permission notice shall be included in
41
+ all copies or substantial portions of the Software.
42
+
43
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
44
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
45
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
46
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
47
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
48
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
49
+ THE SOFTWARE.
50
+
51
+ @license
52
+ */
53
+ var Handlebars = (function() {
54
+ // handlebars/safe-string.js
55
+ var __module3__ = (function() {
56
+ "use strict";
57
+ var __exports__;
58
+ // Build out our basic SafeString type
59
+ function SafeString(string) {
60
+ this.string = string;
61
+ }
62
+
63
+ SafeString.prototype.toString = function() {
64
+ return "" + this.string;
65
+ };
66
+
67
+ __exports__ = SafeString;
68
+ return __exports__;
69
+ })();
70
+
71
+ // handlebars/utils.js
72
+ var __module2__ = (function(__dependency1__) {
73
+ "use strict";
74
+ var __exports__ = {};
75
+ var SafeString = __dependency1__;
76
+
77
+ var isArray = Array.isArray;
78
+
79
+ var escape = {
80
+ "&": "&",
81
+ "<": "&lt;",
82
+ ">": "&gt;",
83
+ '"': "&quot;",
84
+ "'": "&#x27;",
85
+ "`": "&#x60;"
86
+ };
87
+
88
+ var badChars = /[&<>"'`]/g;
89
+ var possible = /[&<>"'`]/;
90
+
91
+ function escapeChar(chr) {
92
+ return escape[chr] || "&amp;";
93
+ }
94
+
95
+ function extend(obj, value) {
96
+ for(var key in value) {
97
+ if(value.hasOwnProperty(key)) {
98
+ obj[key] = value[key];
99
+ }
100
+ }
101
+ }
102
+
103
+ __exports__.extend = extend;function escapeExpression(string) {
104
+ // don't escape SafeStrings, since they're already safe
105
+ if (string instanceof SafeString) {
106
+ return string.toString();
107
+ } else if (!string && string !== 0) {
108
+ return "";
109
+ }
110
+
111
+ // Force a string conversion as this will be done by the append regardless and
112
+ // the regex test will do this transparently behind the scenes, causing issues if
113
+ // an object's to string has escaped characters in it.
114
+ string = "" + string;
115
+
116
+ if(!possible.test(string)) { return string; }
117
+ return string.replace(badChars, escapeChar);
118
+ }
119
+
120
+ __exports__.escapeExpression = escapeExpression;function isEmpty(value) {
121
+ if (!value && value !== 0) {
122
+ return true;
123
+ } else if (isArray(value) && value.length === 0) {
124
+ return true;
125
+ } else {
126
+ return false;
127
+ }
128
+ }
129
+
130
+ __exports__.isEmpty = isEmpty;
131
+ return __exports__;
132
+ })(__module3__);
133
+
134
+ // handlebars/exception.js
135
+ var __module4__ = (function() {
136
+ "use strict";
137
+ var __exports__;
138
+
139
+ var errorProps = ['description', 'fileName', 'lineNumber', 'message', 'name', 'number', 'stack'];
140
+
141
+ function Exception(/* message */) {
142
+ var tmp = Error.prototype.constructor.apply(this, arguments);
143
+
144
+ // Unfortunately errors are not enumerable in Chrome (at least), so `for prop in tmp` doesn't work.
145
+ for (var idx = 0; idx < errorProps.length; idx++) {
146
+ this[errorProps[idx]] = tmp[errorProps[idx]];
147
+ }
148
+ }
149
+
150
+ Exception.prototype = new Error();
151
+
152
+ __exports__ = Exception;
153
+ return __exports__;
154
+ })();
155
+
156
+ // handlebars/base.js
157
+ var __module1__ = (function(__dependency1__, __dependency2__) {
158
+ "use strict";
159
+ var __exports__ = {};
160
+ /*globals Exception, Utils */
161
+ var Utils = __dependency1__;
162
+ var Exception = __dependency2__;
163
+
164
+ var VERSION = "1.1.1";
165
+ __exports__.VERSION = VERSION;var COMPILER_REVISION = 4;
166
+ __exports__.COMPILER_REVISION = COMPILER_REVISION;
167
+ var REVISION_CHANGES = {
168
+ 1: '<= 1.0.rc.2', // 1.0.rc.2 is actually rev2 but doesn't report it
169
+ 2: '== 1.0.0-rc.3',
170
+ 3: '== 1.0.0-rc.4',
171
+ 4: '>= 1.0.0'
172
+ };
173
+ __exports__.REVISION_CHANGES = REVISION_CHANGES;
174
+ var toString = Object.prototype.toString,
175
+ objectType = '[object Object]';
176
+
177
+ // Sourced from lodash
178
+ // https://github.com/bestiejs/lodash/blob/master/LICENSE.txt
179
+ var isFunction = function(value) {
180
+ return typeof value === 'function';
181
+ };
182
+ // fallback for older versions of Chrome and Safari
183
+ if (isFunction(/x/)) {
184
+ isFunction = function(value) {
185
+ return typeof value === 'function' && toString.call(value) === '[object Function]';
186
+ };
187
+ }
188
+
189
+ function isArray(value) {
190
+ return (value && typeof value === 'object') ? toString.call(value) === '[object Array]' : false;
191
+ }
192
+
193
+ function HandlebarsEnvironment(helpers, partials) {
194
+ this.helpers = helpers || {};
195
+ this.partials = partials || {};
196
+
197
+ registerDefaultHelpers(this);
198
+ }
199
+
200
+ __exports__.HandlebarsEnvironment = HandlebarsEnvironment;HandlebarsEnvironment.prototype = {
201
+ constructor: HandlebarsEnvironment,
202
+
203
+ logger: logger,
204
+ log: log,
205
+
206
+ registerHelper: function(name, fn, inverse) {
207
+ if (toString.call(name) === objectType) {
208
+ if (inverse || fn) { throw new Exception('Arg not supported with multiple helpers'); }
209
+ Utils.extend(this.helpers, name);
210
+ } else {
211
+ if (inverse) { fn.not = inverse; }
212
+ this.helpers[name] = fn;
213
+ }
214
+ },
215
+
216
+ registerPartial: function(name, str) {
217
+ if (toString.call(name) === objectType) {
218
+ Utils.extend(this.partials, name);
219
+ } else {
220
+ this.partials[name] = str;
221
+ }
222
+ }
223
+ };
224
+
225
+ function registerDefaultHelpers(instance) {
226
+ instance.registerHelper('helperMissing', function(arg) {
227
+ if(arguments.length === 2) {
228
+ return undefined;
229
+ } else {
230
+ throw new Error("Missing helper: '" + arg + "'");
231
+ }
232
+ });
233
+
234
+ instance.registerHelper('blockHelperMissing', function(context, options) {
235
+ var inverse = options.inverse || function() {}, fn = options.fn;
236
+
237
+ if (isFunction(context)) { context = context.call(this); }
238
+
239
+ if(context === true) {
240
+ return fn(this);
241
+ } else if(context === false || context == null) {
242
+ return inverse(this);
243
+ } else if (isArray(context)) {
244
+ if(context.length > 0) {
245
+ return instance.helpers.each(context, options);
246
+ } else {
247
+ return inverse(this);
248
+ }
249
+ } else {
250
+ return fn(context);
251
+ }
252
+ });
253
+
254
+ instance.registerHelper('each', function(context, options) {
255
+ var fn = options.fn, inverse = options.inverse;
256
+ var i = 0, ret = "", data;
257
+
258
+ if (isFunction(context)) { context = context.call(this); }
259
+
260
+ if (options.data) {
261
+ data = createFrame(options.data);
262
+ }
263
+
264
+ if(context && typeof context === 'object') {
265
+ if (isArray(context)) {
266
+ for(var j = context.length; i<j; i++) {
267
+ if (data) {
268
+ data.index = i;
269
+ data.first = (i === 0)
270
+ data.last = (i === (context.length-1));
271
+ }
272
+ ret = ret + fn(context[i], { data: data });
273
+ }
274
+ } else {
275
+ for(var key in context) {
276
+ if(context.hasOwnProperty(key)) {
277
+ if(data) { data.key = key; }
278
+ ret = ret + fn(context[key], {data: data});
279
+ i++;
280
+ }
281
+ }
282
+ }
283
+ }
284
+
285
+ if(i === 0){
286
+ ret = inverse(this);
287
+ }
288
+
289
+ return ret;
290
+ });
291
+
292
+ instance.registerHelper('if', function(conditional, options) {
293
+ if (isFunction(conditional)) { conditional = conditional.call(this); }
294
+
295
+ // Default behavior is to render the positive path if the value is truthy and not empty.
296
+ // The `includeZero` option may be set to treat the condtional as purely not empty based on the
297
+ // behavior of isEmpty. Effectively this determines if 0 is handled by the positive path or negative.
298
+ if ((!options.hash.includeZero && !conditional) || Utils.isEmpty(conditional)) {
299
+ return options.inverse(this);
300
+ } else {
301
+ return options.fn(this);
302
+ }
303
+ });
304
+
305
+ instance.registerHelper('unless', function(conditional, options) {
306
+ return instance.helpers['if'].call(this, conditional, {fn: options.inverse, inverse: options.fn, hash: options.hash});
307
+ });
308
+
309
+ instance.registerHelper('with', function(context, options) {
310
+ if (isFunction(context)) { context = context.call(this); }
311
+
312
+ if (!Utils.isEmpty(context)) return options.fn(context);
313
+ });
314
+
315
+ instance.registerHelper('log', function(context, options) {
316
+ var level = options.data && options.data.level != null ? parseInt(options.data.level, 10) : 1;
317
+ instance.log(level, context);
318
+ });
319
+ }
320
+
321
+ var logger = {
322
+ methodMap: { 0: 'debug', 1: 'info', 2: 'warn', 3: 'error' },
323
+
324
+ // State enum
325
+ DEBUG: 0,
326
+ INFO: 1,
327
+ WARN: 2,
328
+ ERROR: 3,
329
+ level: 3,
330
+
331
+ // can be overridden in the host environment
332
+ log: function(level, obj) {
333
+ if (logger.level <= level) {
334
+ var method = logger.methodMap[level];
335
+ if (typeof console !== 'undefined' && console[method]) {
336
+ console[method].call(console, obj);
337
+ }
338
+ }
339
+ }
340
+ };
341
+ __exports__.logger = logger;
342
+ function log(level, obj) { logger.log(level, obj); }
343
+
344
+ __exports__.log = log;var createFrame = function(object) {
345
+ var obj = {};
346
+ Utils.extend(obj, object);
347
+ return obj;
348
+ };
349
+ __exports__.createFrame = createFrame;
350
+ return __exports__;
351
+ })(__module2__, __module4__);
352
+
353
+ // handlebars/runtime.js
354
+ var __module5__ = (function(__dependency1__, __dependency2__, __dependency3__) {
355
+ "use strict";
356
+ var __exports__ = {};
357
+ /*global Utils */
358
+ var Utils = __dependency1__;
359
+ var Exception = __dependency2__;
360
+ var COMPILER_REVISION = __dependency3__.COMPILER_REVISION;
361
+ var REVISION_CHANGES = __dependency3__.REVISION_CHANGES;
362
+
363
+ function checkRevision(compilerInfo) {
364
+ var compilerRevision = compilerInfo && compilerInfo[0] || 1,
365
+ currentRevision = COMPILER_REVISION;
366
+
367
+ if (compilerRevision !== currentRevision) {
368
+ if (compilerRevision < currentRevision) {
369
+ var runtimeVersions = REVISION_CHANGES[currentRevision],
370
+ compilerVersions = REVISION_CHANGES[compilerRevision];
371
+ throw new Error("Template was precompiled with an older version of Handlebars than the current runtime. "+
372
+ "Please update your precompiler to a newer version ("+runtimeVersions+") or downgrade your runtime to an older version ("+compilerVersions+").");
373
+ } else {
374
+ // Use the embedded version info since the runtime doesn't know about this revision yet
375
+ throw new Error("Template was precompiled with a newer version of Handlebars than the current runtime. "+
376
+ "Please update your runtime to a newer version ("+compilerInfo[1]+").");
377
+ }
378
+ }
379
+ }
380
+
381
+ // TODO: Remove this line and break up compilePartial
382
+
383
+ function template(templateSpec, env) {
384
+ if (!env) {
385
+ throw new Error("No environment passed to template");
386
+ }
387
+
388
+ var invokePartialWrapper;
389
+ if (env.compile) {
390
+ invokePartialWrapper = function(partial, name, context, helpers, partials, data) {
391
+ // TODO : Check this for all inputs and the options handling (partial flag, etc). This feels
392
+ // like there should be a common exec path
393
+ var result = invokePartial.apply(this, arguments);
394
+ if (result) { return result; }
395
+
396
+ var options = { helpers: helpers, partials: partials, data: data };
397
+ partials[name] = env.compile(partial, { data: data !== undefined }, env);
398
+ return partials[name](context, options);
399
+ };
400
+ } else {
401
+ invokePartialWrapper = function(partial, name /* , context, helpers, partials, data */) {
402
+ var result = invokePartial.apply(this, arguments);
403
+ if (result) { return result; }
404
+ throw new Exception("The partial " + name + " could not be compiled when running in runtime-only mode");
405
+ };
406
+ }
407
+
408
+ // Just add water
409
+ var container = {
410
+ escapeExpression: Utils.escapeExpression,
411
+ invokePartial: invokePartialWrapper,
412
+ programs: [],
413
+ program: function(i, fn, data) {
414
+ var programWrapper = this.programs[i];
415
+ if(data) {
416
+ programWrapper = program(i, fn, data);
417
+ } else if (!programWrapper) {
418
+ programWrapper = this.programs[i] = program(i, fn);
419
+ }
420
+ return programWrapper;
421
+ },
422
+ merge: function(param, common) {
423
+ var ret = param || common;
424
+
425
+ if (param && common && (param !== common)) {
426
+ ret = {};
427
+ Utils.extend(ret, common);
428
+ Utils.extend(ret, param);
429
+ }
430
+ return ret;
431
+ },
432
+ programWithDepth: programWithDepth,
433
+ noop: noop,
434
+ compilerInfo: null
435
+ };
436
+
437
+ return function(context, options) {
438
+ options = options || {};
439
+ var namespace = options.partial ? options : env,
440
+ helpers,
441
+ partials;
442
+
443
+ if (!options.partial) {
444
+ helpers = options.helpers;
445
+ partials = options.partials;
446
+ }
447
+ var result = templateSpec.call(
448
+ container,
449
+ namespace, context,
450
+ helpers,
451
+ partials,
452
+ options.data);
453
+
454
+ if (!options.partial) {
455
+ checkRevision(container.compilerInfo);
456
+ }
457
+
458
+ return result;
459
+ };
460
+ }
461
+
462
+ __exports__.template = template;function programWithDepth(i, fn, data /*, $depth */) {
463
+ var args = Array.prototype.slice.call(arguments, 3);
464
+
465
+ var prog = function(context, options) {
466
+ options = options || {};
467
+
468
+ return fn.apply(this, [context, options.data || data].concat(args));
469
+ };
470
+ prog.program = i;
471
+ prog.depth = args.length;
472
+ return prog;
473
+ }
474
+
475
+ __exports__.programWithDepth = programWithDepth;function program(i, fn, data) {
476
+ var prog = function(context, options) {
477
+ options = options || {};
478
+
479
+ return fn(context, options.data || data);
480
+ };
481
+ prog.program = i;
482
+ prog.depth = 0;
483
+ return prog;
484
+ }
485
+
486
+ __exports__.program = program;function invokePartial(partial, name, context, helpers, partials, data) {
487
+ var options = { partial: true, helpers: helpers, partials: partials, data: data };
488
+
489
+ if(partial === undefined) {
490
+ throw new Exception("The partial " + name + " could not be found");
491
+ } else if(partial instanceof Function) {
492
+ return partial(context, options);
493
+ }
494
+ }
495
+
496
+ __exports__.invokePartial = invokePartial;function noop() { return ""; }
497
+
498
+ __exports__.noop = noop;
499
+ return __exports__;
500
+ })(__module2__, __module4__, __module1__);
501
+
502
+ // handlebars.runtime.js
503
+ var __module0__ = (function(__dependency1__, __dependency2__, __dependency3__, __dependency4__, __dependency5__) {
504
+ "use strict";
505
+ var __exports__;
506
+ var base = __dependency1__;
507
+
508
+ // Each of these augment the Handlebars object. No need to setup here.
509
+ // (This is done to easily share code between commonjs and browse envs)
510
+ var SafeString = __dependency2__;
511
+ var Exception = __dependency3__;
512
+ var Utils = __dependency4__;
513
+ var runtime = __dependency5__;
514
+
515
+ // For compatibility and usage outside of module systems, make the Handlebars object a namespace
516
+ var create = function() {
517
+ var hb = new base.HandlebarsEnvironment();
518
+
519
+ Utils.extend(hb, base);
520
+ hb.SafeString = SafeString;
521
+ hb.Exception = Exception;
522
+ hb.Utils = Utils;
523
+
524
+ hb.VM = runtime;
525
+ hb.template = function(spec) {
526
+ return runtime.template(spec, hb);
527
+ };
528
+
529
+ return hb;
530
+ };
531
+
532
+ var Handlebars = create();
533
+ Handlebars.create = create;
534
+
535
+ __exports__ = Handlebars;
536
+ return __exports__;
537
+ })(__module1__, __module3__, __module4__, __module2__, __module5__);
538
+
539
+ return __module0__;
540
+ })();