handlebars-source 2.0.0 → 3.0.0

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.

Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/handlebars.js +1476 -861
  3. data/handlebars.runtime.js +151 -137
  4. metadata +2 -2
@@ -1,58 +1,6 @@
1
1
  /*!
2
2
 
3
- handlebars v2.0.0
4
-
5
- Copyright (C) 2011-2014 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 v2.0.0
30
-
31
- Copyright (C) 2011-2014 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
- /*!
54
-
55
- handlebars v2.0.0
3
+ handlebars v3.0.0
56
4
 
57
5
  Copyright (C) 2011-2014 by Yehuda Katz
58
6
 
@@ -83,33 +31,14 @@ THE SOFTWARE.
83
31
  } else if (typeof exports === 'object') {
84
32
  module.exports = factory();
85
33
  } else {
86
- root.Handlebars = root.Handlebars || factory();
34
+ root.Handlebars = factory();
87
35
  }
88
36
  }(this, function () {
89
- // handlebars/safe-string.js
90
- var __module3__ = (function() {
91
- "use strict";
92
- var __exports__;
93
- // Build out our basic SafeString type
94
- function SafeString(string) {
95
- this.string = string;
96
- }
97
-
98
- SafeString.prototype.toString = function() {
99
- return "" + this.string;
100
- };
101
-
102
- __exports__ = SafeString;
103
- return __exports__;
104
- })();
105
-
106
37
  // handlebars/utils.js
107
- var __module2__ = (function(__dependency1__) {
38
+ var __module2__ = (function() {
108
39
  "use strict";
109
40
  var __exports__ = {};
110
41
  /*jshint -W004 */
111
- var SafeString = __dependency1__;
112
-
113
42
  var escape = {
114
43
  "&": "&",
115
44
  "<": "&lt;",
@@ -159,11 +88,21 @@ var __module2__ = (function(__dependency1__) {
159
88
  return (value && typeof value === 'object') ? toString.call(value) === '[object Array]' : false;
160
89
  };
161
90
  __exports__.isArray = isArray;
91
+ // Older IE versions do not directly support indexOf so we must implement our own, sadly.
92
+ function indexOf(array, value) {
93
+ for (var i = 0, len = array.length; i < len; i++) {
94
+ if (array[i] === value) {
95
+ return i;
96
+ }
97
+ }
98
+ return -1;
99
+ }
162
100
 
101
+ __exports__.indexOf = indexOf;
163
102
  function escapeExpression(string) {
164
103
  // don't escape SafeStrings, since they're already safe
165
- if (string instanceof SafeString) {
166
- return string.toString();
104
+ if (string && string.toHTML) {
105
+ return string.toHTML();
167
106
  } else if (string == null) {
168
107
  return "";
169
108
  } else if (!string) {
@@ -189,27 +128,35 @@ var __module2__ = (function(__dependency1__) {
189
128
  }
190
129
  }
191
130
 
192
- __exports__.isEmpty = isEmpty;function appendContextPath(contextPath, id) {
131
+ __exports__.isEmpty = isEmpty;function blockParams(params, ids) {
132
+ params.path = ids;
133
+ return params;
134
+ }
135
+
136
+ __exports__.blockParams = blockParams;function appendContextPath(contextPath, id) {
193
137
  return (contextPath ? contextPath + '.' : '') + id;
194
138
  }
195
139
 
196
140
  __exports__.appendContextPath = appendContextPath;
197
141
  return __exports__;
198
- })(__module3__);
142
+ })();
199
143
 
200
144
  // handlebars/exception.js
201
- var __module4__ = (function() {
145
+ var __module3__ = (function() {
202
146
  "use strict";
203
147
  var __exports__;
204
148
 
205
149
  var errorProps = ['description', 'fileName', 'lineNumber', 'message', 'name', 'number', 'stack'];
206
150
 
207
151
  function Exception(message, node) {
208
- var line;
209
- if (node && node.firstLine) {
210
- line = node.firstLine;
211
-
212
- message += ' - ' + line + ':' + node.firstColumn;
152
+ var loc = node && node.loc,
153
+ line,
154
+ column;
155
+ if (loc) {
156
+ line = loc.start.line;
157
+ column = loc.start.column;
158
+
159
+ message += ' - ' + line + ':' + column;
213
160
  }
214
161
 
215
162
  var tmp = Error.prototype.constructor.call(this, message);
@@ -219,9 +166,9 @@ var __module4__ = (function() {
219
166
  this[errorProps[idx]] = tmp[errorProps[idx]];
220
167
  }
221
168
 
222
- if (line) {
169
+ if (loc) {
223
170
  this.lineNumber = line;
224
- this.column = node.firstColumn;
171
+ this.column = column;
225
172
  }
226
173
  }
227
174
 
@@ -238,7 +185,7 @@ var __module1__ = (function(__dependency1__, __dependency2__) {
238
185
  var Utils = __dependency1__;
239
186
  var Exception = __dependency2__;
240
187
 
241
- var VERSION = "2.0.0";
188
+ var VERSION = "3.0.0";
242
189
  __exports__.VERSION = VERSION;var COMPILER_REVISION = 6;
243
190
  __exports__.COMPILER_REVISION = COMPILER_REVISION;
244
191
  var REVISION_CHANGES = {
@@ -284,6 +231,9 @@ var __module1__ = (function(__dependency1__, __dependency2__) {
284
231
  if (toString.call(name) === objectType) {
285
232
  Utils.extend(this.partials, name);
286
233
  } else {
234
+ if (typeof partial === 'undefined') {
235
+ throw new Exception('Attempting to register a partial as undefined');
236
+ }
287
237
  this.partials[name] = partial;
288
238
  }
289
239
  },
@@ -351,36 +301,47 @@ var __module1__ = (function(__dependency1__, __dependency2__) {
351
301
  data = createFrame(options.data);
352
302
  }
353
303
 
304
+ function execIteration(key, i, last) {
305
+ if (data) {
306
+ data.key = key;
307
+ data.index = i;
308
+ data.first = i === 0;
309
+ data.last = !!last;
310
+
311
+ if (contextPath) {
312
+ data.contextPath = contextPath + key;
313
+ }
314
+ }
315
+
316
+ ret = ret + fn(context[key], {
317
+ data: data,
318
+ blockParams: Utils.blockParams([context[key], key], [contextPath + key, null])
319
+ });
320
+ }
321
+
354
322
  if(context && typeof context === 'object') {
355
323
  if (isArray(context)) {
356
324
  for(var j = context.length; i<j; i++) {
357
- if (data) {
358
- data.index = i;
359
- data.first = (i === 0);
360
- data.last = (i === (context.length-1));
361
-
362
- if (contextPath) {
363
- data.contextPath = contextPath + i;
364
- }
365
- }
366
- ret = ret + fn(context[i], { data: data });
325
+ execIteration(i, i, i === context.length-1);
367
326
  }
368
327
  } else {
328
+ var priorKey;
329
+
369
330
  for(var key in context) {
370
331
  if(context.hasOwnProperty(key)) {
371
- if(data) {
372
- data.key = key;
373
- data.index = i;
374
- data.first = (i === 0);
375
-
376
- if (contextPath) {
377
- data.contextPath = contextPath + key;
378
- }
332
+ // We're running the iterations one step out of sync so we can detect
333
+ // the last iteration without have to scan the object twice and create
334
+ // an itermediate keys array.
335
+ if (priorKey) {
336
+ execIteration(priorKey, i-1);
379
337
  }
380
- ret = ret + fn(context[key], {data: data});
338
+ priorKey = key;
381
339
  i++;
382
340
  }
383
341
  }
342
+ if (priorKey) {
343
+ execIteration(priorKey, i-1, true);
344
+ }
384
345
  }
385
346
  }
386
347
 
@@ -444,15 +405,13 @@ var __module1__ = (function(__dependency1__, __dependency2__) {
444
405
  INFO: 1,
445
406
  WARN: 2,
446
407
  ERROR: 3,
447
- level: 3,
408
+ level: 1,
448
409
 
449
- // can be overridden in the host environment
410
+ // Can be overridden in the host environment
450
411
  log: function(level, message) {
451
- if (logger.level <= level) {
412
+ if (typeof console !== 'undefined' && logger.level <= level) {
452
413
  var method = logger.methodMap[level];
453
- if (typeof console !== 'undefined' && console[method]) {
454
- console[method].call(console, message);
455
- }
414
+ (console[method] || console.log).call(console, message);
456
415
  }
457
416
  }
458
417
  };
@@ -466,7 +425,24 @@ var __module1__ = (function(__dependency1__, __dependency2__) {
466
425
  };
467
426
  __exports__.createFrame = createFrame;
468
427
  return __exports__;
469
- })(__module2__, __module4__);
428
+ })(__module2__, __module3__);
429
+
430
+ // handlebars/safe-string.js
431
+ var __module4__ = (function() {
432
+ "use strict";
433
+ var __exports__;
434
+ // Build out our basic SafeString type
435
+ function SafeString(string) {
436
+ this.string = string;
437
+ }
438
+
439
+ SafeString.prototype.toString = SafeString.prototype.toHTML = function() {
440
+ return "" + this.string;
441
+ };
442
+
443
+ __exports__ = SafeString;
444
+ return __exports__;
445
+ })();
470
446
 
471
447
  // handlebars/runtime.js
472
448
  var __module5__ = (function(__dependency1__, __dependency2__, __dependency3__) {
@@ -511,38 +487,44 @@ var __module5__ = (function(__dependency1__, __dependency2__, __dependency3__) {
511
487
  // for external users to override these as psuedo-supported APIs.
512
488
  env.VM.checkRevision(templateSpec.compiler);
513
489
 
514
- var invokePartialWrapper = function(partial, indent, name, context, hash, helpers, partials, data, depths) {
515
- if (hash) {
516
- context = Utils.extend({}, context, hash);
490
+ var invokePartialWrapper = function(partial, context, options) {
491
+ if (options.hash) {
492
+ context = Utils.extend({}, context, options.hash);
517
493
  }
518
494
 
519
- var result = env.VM.invokePartial.call(this, partial, name, context, helpers, partials, data, depths);
495
+ partial = env.VM.resolvePartial.call(this, partial, context, options);
496
+ var result = env.VM.invokePartial.call(this, partial, context, options);
520
497
 
521
498
  if (result == null && env.compile) {
522
- var options = { helpers: helpers, partials: partials, data: data, depths: depths };
523
- partials[name] = env.compile(partial, { data: data !== undefined, compat: templateSpec.compat }, env);
524
- result = partials[name](context, options);
499
+ options.partials[options.name] = env.compile(partial, templateSpec.compilerOptions, env);
500
+ result = options.partials[options.name](context, options);
525
501
  }
526
502
  if (result != null) {
527
- if (indent) {
503
+ if (options.indent) {
528
504
  var lines = result.split('\n');
529
505
  for (var i = 0, l = lines.length; i < l; i++) {
530
506
  if (!lines[i] && i + 1 === l) {
531
507
  break;
532
508
  }
533
509
 
534
- lines[i] = indent + lines[i];
510
+ lines[i] = options.indent + lines[i];
535
511
  }
536
512
  result = lines.join('\n');
537
513
  }
538
514
  return result;
539
515
  } else {
540
- throw new Exception("The partial " + name + " could not be compiled when running in runtime-only mode");
516
+ throw new Exception("The partial " + options.name + " could not be compiled when running in runtime-only mode");
541
517
  }
542
518
  };
543
519
 
544
520
  // Just add water
545
521
  var container = {
522
+ strict: function(obj, name) {
523
+ if (!(name in obj)) {
524
+ throw new Exception('"' + name + '" not defined in ' + obj);
525
+ }
526
+ return obj[name];
527
+ },
546
528
  lookup: function(depths, name) {
547
529
  var len = depths.length;
548
530
  for (var i = 0; i < len; i++) {
@@ -563,11 +545,11 @@ var __module5__ = (function(__dependency1__, __dependency2__, __dependency3__) {
563
545
  },
564
546
 
565
547
  programs: [],
566
- program: function(i, data, depths) {
548
+ program: function(i, data, declaredBlockParams, blockParams, depths) {
567
549
  var programWrapper = this.programs[i],
568
550
  fn = this.fn(i);
569
- if (data || depths) {
570
- programWrapper = program(this, i, fn, data, depths);
551
+ if (data || depths || blockParams || declaredBlockParams) {
552
+ programWrapper = program(this, i, fn, data, declaredBlockParams, blockParams, depths);
571
553
  } else if (!programWrapper) {
572
554
  programWrapper = this.programs[i] = program(this, i, fn);
573
555
  }
@@ -602,12 +584,13 @@ var __module5__ = (function(__dependency1__, __dependency2__, __dependency3__) {
602
584
  if (!options.partial && templateSpec.useData) {
603
585
  data = initData(context, data);
604
586
  }
605
- var depths;
587
+ var depths,
588
+ blockParams = templateSpec.useBlockParams ? [] : undefined;
606
589
  if (templateSpec.useDepths) {
607
590
  depths = options.depths ? [context].concat(options.depths) : [context];
608
591
  }
609
592
 
610
- return templateSpec.main.call(container, context, container.helpers, container.partials, data, depths);
593
+ return templateSpec.main.call(container, context, container.helpers, container.partials, data, blockParams, depths);
611
594
  };
612
595
  ret.isTop = true;
613
596
 
@@ -624,32 +607,52 @@ var __module5__ = (function(__dependency1__, __dependency2__, __dependency3__) {
624
607
  }
625
608
  };
626
609
 
627
- ret._child = function(i, data, depths) {
610
+ ret._child = function(i, data, blockParams, depths) {
611
+ if (templateSpec.useBlockParams && !blockParams) {
612
+ throw new Exception('must pass block params');
613
+ }
628
614
  if (templateSpec.useDepths && !depths) {
629
615
  throw new Exception('must pass parent depths');
630
616
  }
631
617
 
632
- return program(container, i, templateSpec[i], data, depths);
618
+ return program(container, i, templateSpec[i], data, 0, blockParams, depths);
633
619
  };
634
620
  return ret;
635
621
  }
636
622
 
637
- __exports__.template = template;function program(container, i, fn, data, depths) {
623
+ __exports__.template = template;function program(container, i, fn, data, declaredBlockParams, blockParams, depths) {
638
624
  var prog = function(context, options) {
639
625
  options = options || {};
640
626
 
641
- return fn.call(container, context, container.helpers, container.partials, options.data || data, depths && [context].concat(depths));
627
+ return fn.call(container,
628
+ context,
629
+ container.helpers, container.partials,
630
+ options.data || data,
631
+ blockParams && [options.blockParams].concat(blockParams),
632
+ depths && [context].concat(depths));
642
633
  };
643
634
  prog.program = i;
644
635
  prog.depth = depths ? depths.length : 0;
636
+ prog.blockParams = declaredBlockParams || 0;
645
637
  return prog;
646
638
  }
647
639
 
648
- __exports__.program = program;function invokePartial(partial, name, context, helpers, partials, data, depths) {
649
- var options = { partial: true, helpers: helpers, partials: partials, data: data, depths: depths };
640
+ __exports__.program = program;function resolvePartial(partial, context, options) {
641
+ if (!partial) {
642
+ partial = options.partials[options.name];
643
+ } else if (!partial.call && !options.name) {
644
+ // This is a dynamic partial that returned a string
645
+ options.name = partial;
646
+ partial = options.partials[partial];
647
+ }
648
+ return partial;
649
+ }
650
+
651
+ __exports__.resolvePartial = resolvePartial;function invokePartial(partial, context, options) {
652
+ options.partial = true;
650
653
 
651
654
  if(partial === undefined) {
652
- throw new Exception("The partial " + name + " could not be found");
655
+ throw new Exception("The partial " + options.name + " could not be found");
653
656
  } else if(partial instanceof Function) {
654
657
  return partial(context, options);
655
658
  }
@@ -665,7 +668,7 @@ var __module5__ = (function(__dependency1__, __dependency2__, __dependency3__) {
665
668
  return data;
666
669
  }
667
670
  return __exports__;
668
- })(__module2__, __module4__, __module1__);
671
+ })(__module2__, __module3__, __module1__);
669
672
 
670
673
  // handlebars.runtime.js
671
674
  var __module0__ = (function(__dependency1__, __dependency2__, __dependency3__, __dependency4__, __dependency5__) {
@@ -702,11 +705,22 @@ var __module0__ = (function(__dependency1__, __dependency2__, __dependency3__, _
702
705
  var Handlebars = create();
703
706
  Handlebars.create = create;
704
707
 
708
+ /*jshint -W040 */
709
+ /* istanbul ignore next */
710
+ var root = typeof global !== 'undefined' ? global : window,
711
+ $Handlebars = root.Handlebars;
712
+ /* istanbul ignore next */
713
+ Handlebars.noConflict = function() {
714
+ if (root.Handlebars === Handlebars) {
715
+ root.Handlebars = $Handlebars;
716
+ }
717
+ };
718
+
705
719
  Handlebars['default'] = Handlebars;
706
720
 
707
721
  __exports__ = Handlebars;
708
722
  return __exports__;
709
- })(__module1__, __module3__, __module4__, __module2__, __module5__);
723
+ })(__module1__, __module4__, __module3__, __module2__, __module5__);
710
724
 
711
725
  return __module0__;
712
726
  }));