handlebars_assets 0.17.2 → 0.18

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,8 @@
1
1
  /*!
2
2
 
3
- handlebars v1.3.0
3
+ handlebars v2.0.0
4
4
 
5
- Copyright (C) 2011 by Yehuda Katz
5
+ Copyright (C) 2011-2014 by Yehuda Katz
6
6
 
7
7
  Permission is hereby granted, free of charge, to any person obtaining a copy
8
8
  of this software and associated documentation files (the "Software"), to deal
@@ -25,7 +25,15 @@ THE SOFTWARE.
25
25
  @license
26
26
  */
27
27
  /* exported Handlebars */
28
- var Handlebars = (function() {
28
+ (function (root, factory) {
29
+ if (typeof define === 'function' && define.amd) {
30
+ define([], factory);
31
+ } else if (typeof exports === 'object') {
32
+ module.exports = factory();
33
+ } else {
34
+ root.Handlebars = root.Handlebars || factory();
35
+ }
36
+ }(this, function () {
29
37
  // handlebars/safe-string.js
30
38
  var __module3__ = (function() {
31
39
  "use strict";
@@ -63,15 +71,19 @@ var __module2__ = (function(__dependency1__) {
63
71
  var possible = /[&<>"'`]/;
64
72
 
65
73
  function escapeChar(chr) {
66
- return escape[chr] || "&amp;";
74
+ return escape[chr];
67
75
  }
68
76
 
69
- function extend(obj, value) {
70
- for(var key in value) {
71
- if(Object.prototype.hasOwnProperty.call(value, key)) {
72
- obj[key] = value[key];
77
+ function extend(obj /* , ...source */) {
78
+ for (var i = 1; i < arguments.length; i++) {
79
+ for (var key in arguments[i]) {
80
+ if (Object.prototype.hasOwnProperty.call(arguments[i], key)) {
81
+ obj[key] = arguments[i][key];
82
+ }
73
83
  }
74
84
  }
85
+
86
+ return obj;
75
87
  }
76
88
 
77
89
  __exports__.extend = extend;var toString = Object.prototype.toString;
@@ -82,6 +94,7 @@ var __module2__ = (function(__dependency1__) {
82
94
  return typeof value === 'function';
83
95
  };
84
96
  // fallback for older versions of Chrome and Safari
97
+ /* istanbul ignore next */
85
98
  if (isFunction(/x/)) {
86
99
  isFunction = function(value) {
87
100
  return typeof value === 'function' && toString.call(value) === '[object Function]';
@@ -89,6 +102,7 @@ var __module2__ = (function(__dependency1__) {
89
102
  }
90
103
  var isFunction;
91
104
  __exports__.isFunction = isFunction;
105
+ /* istanbul ignore next */
92
106
  var isArray = Array.isArray || function(value) {
93
107
  return (value && typeof value === 'object') ? toString.call(value) === '[object Array]' : false;
94
108
  };
@@ -98,8 +112,10 @@ var __module2__ = (function(__dependency1__) {
98
112
  // don't escape SafeStrings, since they're already safe
99
113
  if (string instanceof SafeString) {
100
114
  return string.toString();
101
- } else if (!string && string !== 0) {
115
+ } else if (string == null) {
102
116
  return "";
117
+ } else if (!string) {
118
+ return string + '';
103
119
  }
104
120
 
105
121
  // Force a string conversion as this will be done by the append regardless and
@@ -121,7 +137,11 @@ var __module2__ = (function(__dependency1__) {
121
137
  }
122
138
  }
123
139
 
124
- __exports__.isEmpty = isEmpty;
140
+ __exports__.isEmpty = isEmpty;function appendContextPath(contextPath, id) {
141
+ return (contextPath ? contextPath + '.' : '') + id;
142
+ }
143
+
144
+ __exports__.appendContextPath = appendContextPath;
125
145
  return __exports__;
126
146
  })(__module3__);
127
147
 
@@ -166,14 +186,16 @@ var __module1__ = (function(__dependency1__, __dependency2__) {
166
186
  var Utils = __dependency1__;
167
187
  var Exception = __dependency2__;
168
188
 
169
- var VERSION = "1.3.0";
170
- __exports__.VERSION = VERSION;var COMPILER_REVISION = 4;
189
+ var VERSION = "2.0.0";
190
+ __exports__.VERSION = VERSION;var COMPILER_REVISION = 6;
171
191
  __exports__.COMPILER_REVISION = COMPILER_REVISION;
172
192
  var REVISION_CHANGES = {
173
193
  1: '<= 1.0.rc.2', // 1.0.rc.2 is actually rev2 but doesn't report it
174
194
  2: '== 1.0.0-rc.3',
175
195
  3: '== 1.0.0-rc.4',
176
- 4: '>= 1.0.0'
196
+ 4: '== 1.x.x',
197
+ 5: '== 2.0.0-alpha.x',
198
+ 6: '>= 2.0.0-beta.1'
177
199
  };
178
200
  __exports__.REVISION_CHANGES = REVISION_CHANGES;
179
201
  var isArray = Utils.isArray,
@@ -194,38 +216,44 @@ var __module1__ = (function(__dependency1__, __dependency2__) {
194
216
  logger: logger,
195
217
  log: log,
196
218
 
197
- registerHelper: function(name, fn, inverse) {
219
+ registerHelper: function(name, fn) {
198
220
  if (toString.call(name) === objectType) {
199
- if (inverse || fn) { throw new Exception('Arg not supported with multiple helpers'); }
221
+ if (fn) { throw new Exception('Arg not supported with multiple helpers'); }
200
222
  Utils.extend(this.helpers, name);
201
223
  } else {
202
- if (inverse) { fn.not = inverse; }
203
224
  this.helpers[name] = fn;
204
225
  }
205
226
  },
227
+ unregisterHelper: function(name) {
228
+ delete this.helpers[name];
229
+ },
206
230
 
207
- registerPartial: function(name, str) {
231
+ registerPartial: function(name, partial) {
208
232
  if (toString.call(name) === objectType) {
209
233
  Utils.extend(this.partials, name);
210
234
  } else {
211
- this.partials[name] = str;
235
+ this.partials[name] = partial;
212
236
  }
237
+ },
238
+ unregisterPartial: function(name) {
239
+ delete this.partials[name];
213
240
  }
214
241
  };
215
242
 
216
243
  function registerDefaultHelpers(instance) {
217
- instance.registerHelper('helperMissing', function(arg) {
218
- if(arguments.length === 2) {
244
+ instance.registerHelper('helperMissing', function(/* [args, ]options */) {
245
+ if(arguments.length === 1) {
246
+ // A missing field in a {{foo}} constuct.
219
247
  return undefined;
220
248
  } else {
221
- throw new Exception("Missing helper: '" + arg + "'");
249
+ // Someone is actually trying to call something, blow up.
250
+ throw new Exception("Missing helper: '" + arguments[arguments.length-1].name + "'");
222
251
  }
223
252
  });
224
253
 
225
254
  instance.registerHelper('blockHelperMissing', function(context, options) {
226
- var inverse = options.inverse || function() {}, fn = options.fn;
227
-
228
- if (isFunction(context)) { context = context.call(this); }
255
+ var inverse = options.inverse,
256
+ fn = options.fn;
229
257
 
230
258
  if(context === true) {
231
259
  return fn(this);
@@ -233,19 +261,38 @@ var __module1__ = (function(__dependency1__, __dependency2__) {
233
261
  return inverse(this);
234
262
  } else if (isArray(context)) {
235
263
  if(context.length > 0) {
264
+ if (options.ids) {
265
+ options.ids = [options.name];
266
+ }
267
+
236
268
  return instance.helpers.each(context, options);
237
269
  } else {
238
270
  return inverse(this);
239
271
  }
240
272
  } else {
241
- return fn(context);
273
+ if (options.data && options.ids) {
274
+ var data = createFrame(options.data);
275
+ data.contextPath = Utils.appendContextPath(options.data.contextPath, options.name);
276
+ options = {data: data};
277
+ }
278
+
279
+ return fn(context, options);
242
280
  }
243
281
  });
244
282
 
245
283
  instance.registerHelper('each', function(context, options) {
284
+ if (!options) {
285
+ throw new Exception('Must pass iterator to #each');
286
+ }
287
+
246
288
  var fn = options.fn, inverse = options.inverse;
247
289
  var i = 0, ret = "", data;
248
290
 
291
+ var contextPath;
292
+ if (options.data && options.ids) {
293
+ contextPath = Utils.appendContextPath(options.data.contextPath, options.ids[0]) + '.';
294
+ }
295
+
249
296
  if (isFunction(context)) { context = context.call(this); }
250
297
 
251
298
  if (options.data) {
@@ -259,16 +306,24 @@ var __module1__ = (function(__dependency1__, __dependency2__) {
259
306
  data.index = i;
260
307
  data.first = (i === 0);
261
308
  data.last = (i === (context.length-1));
309
+
310
+ if (contextPath) {
311
+ data.contextPath = contextPath + i;
312
+ }
262
313
  }
263
314
  ret = ret + fn(context[i], { data: data });
264
315
  }
265
316
  } else {
266
317
  for(var key in context) {
267
318
  if(context.hasOwnProperty(key)) {
268
- if(data) {
269
- data.key = key;
319
+ if(data) {
320
+ data.key = key;
270
321
  data.index = i;
271
322
  data.first = (i === 0);
323
+
324
+ if (contextPath) {
325
+ data.contextPath = contextPath + key;
326
+ }
272
327
  }
273
328
  ret = ret + fn(context[key], {data: data});
274
329
  i++;
@@ -304,12 +359,28 @@ var __module1__ = (function(__dependency1__, __dependency2__) {
304
359
  instance.registerHelper('with', function(context, options) {
305
360
  if (isFunction(context)) { context = context.call(this); }
306
361
 
307
- if (!Utils.isEmpty(context)) return options.fn(context);
362
+ var fn = options.fn;
363
+
364
+ if (!Utils.isEmpty(context)) {
365
+ if (options.data && options.ids) {
366
+ var data = createFrame(options.data);
367
+ data.contextPath = Utils.appendContextPath(options.data.contextPath, options.ids[0]);
368
+ options = {data:data};
369
+ }
370
+
371
+ return fn(context, options);
372
+ } else {
373
+ return options.inverse(this);
374
+ }
308
375
  });
309
376
 
310
- instance.registerHelper('log', function(context, options) {
377
+ instance.registerHelper('log', function(message, options) {
311
378
  var level = options.data && options.data.level != null ? parseInt(options.data.level, 10) : 1;
312
- instance.log(level, context);
379
+ instance.log(level, message);
380
+ });
381
+
382
+ instance.registerHelper('lookup', function(obj, field) {
383
+ return obj && obj[field];
313
384
  });
314
385
  }
315
386
 
@@ -324,22 +395,22 @@ var __module1__ = (function(__dependency1__, __dependency2__) {
324
395
  level: 3,
325
396
 
326
397
  // can be overridden in the host environment
327
- log: function(level, obj) {
398
+ log: function(level, message) {
328
399
  if (logger.level <= level) {
329
400
  var method = logger.methodMap[level];
330
401
  if (typeof console !== 'undefined' && console[method]) {
331
- console[method].call(console, obj);
402
+ console[method].call(console, message);
332
403
  }
333
404
  }
334
405
  }
335
406
  };
336
407
  __exports__.logger = logger;
337
- function log(level, obj) { logger.log(level, obj); }
338
-
339
- __exports__.log = log;var createFrame = function(object) {
340
- var obj = {};
341
- Utils.extend(obj, object);
342
- return obj;
408
+ var log = logger.log;
409
+ __exports__.log = log;
410
+ var createFrame = function(object) {
411
+ var frame = Utils.extend({}, object);
412
+ frame._parent = object;
413
+ return frame;
343
414
  };
344
415
  __exports__.createFrame = createFrame;
345
416
  return __exports__;
@@ -353,6 +424,7 @@ var __module5__ = (function(__dependency1__, __dependency2__, __dependency3__) {
353
424
  var Exception = __dependency2__;
354
425
  var COMPILER_REVISION = __dependency3__.COMPILER_REVISION;
355
426
  var REVISION_CHANGES = __dependency3__.REVISION_CHANGES;
427
+ var createFrame = __dependency3__.createFrame;
356
428
 
357
429
  function checkRevision(compilerInfo) {
358
430
  var compilerRevision = compilerInfo && compilerInfo[0] || 1,
@@ -375,20 +447,43 @@ var __module5__ = (function(__dependency1__, __dependency2__, __dependency3__) {
375
447
  __exports__.checkRevision = checkRevision;// TODO: Remove this line and break up compilePartial
376
448
 
377
449
  function template(templateSpec, env) {
450
+ /* istanbul ignore next */
378
451
  if (!env) {
379
452
  throw new Exception("No environment passed to template");
380
453
  }
454
+ if (!templateSpec || !templateSpec.main) {
455
+ throw new Exception('Unknown template object: ' + typeof templateSpec);
456
+ }
381
457
 
382
458
  // Note: Using env.VM references rather than local var references throughout this section to allow
383
459
  // for external users to override these as psuedo-supported APIs.
384
- var invokePartialWrapper = function(partial, name, context, helpers, partials, data) {
385
- var result = env.VM.invokePartial.apply(this, arguments);
386
- if (result != null) { return result; }
387
-
388
- if (env.compile) {
389
- var options = { helpers: helpers, partials: partials, data: data };
390
- partials[name] = env.compile(partial, { data: data !== undefined }, env);
391
- return partials[name](context, options);
460
+ env.VM.checkRevision(templateSpec.compiler);
461
+
462
+ var invokePartialWrapper = function(partial, indent, name, context, hash, helpers, partials, data, depths) {
463
+ if (hash) {
464
+ context = Utils.extend({}, context, hash);
465
+ }
466
+
467
+ var result = env.VM.invokePartial.call(this, partial, name, context, helpers, partials, data, depths);
468
+
469
+ if (result == null && env.compile) {
470
+ var options = { helpers: helpers, partials: partials, data: data, depths: depths };
471
+ partials[name] = env.compile(partial, { data: data !== undefined, compat: templateSpec.compat }, env);
472
+ result = partials[name](context, options);
473
+ }
474
+ if (result != null) {
475
+ if (indent) {
476
+ var lines = result.split('\n');
477
+ for (var i = 0, l = lines.length; i < l; i++) {
478
+ if (!lines[i] && i + 1 === l) {
479
+ break;
480
+ }
481
+
482
+ lines[i] = indent + lines[i];
483
+ }
484
+ result = lines.join('\n');
485
+ }
486
+ return result;
392
487
  } else {
393
488
  throw new Exception("The partial " + name + " could not be compiled when running in runtime-only mode");
394
489
  }
@@ -396,84 +491,110 @@ var __module5__ = (function(__dependency1__, __dependency2__, __dependency3__) {
396
491
 
397
492
  // Just add water
398
493
  var container = {
494
+ lookup: function(depths, name) {
495
+ var len = depths.length;
496
+ for (var i = 0; i < len; i++) {
497
+ if (depths[i] && depths[i][name] != null) {
498
+ return depths[i][name];
499
+ }
500
+ }
501
+ },
502
+ lambda: function(current, context) {
503
+ return typeof current === 'function' ? current.call(context) : current;
504
+ },
505
+
399
506
  escapeExpression: Utils.escapeExpression,
400
507
  invokePartial: invokePartialWrapper,
508
+
509
+ fn: function(i) {
510
+ return templateSpec[i];
511
+ },
512
+
401
513
  programs: [],
402
- program: function(i, fn, data) {
403
- var programWrapper = this.programs[i];
404
- if(data) {
405
- programWrapper = program(i, fn, data);
514
+ program: function(i, data, depths) {
515
+ var programWrapper = this.programs[i],
516
+ fn = this.fn(i);
517
+ if (data || depths) {
518
+ programWrapper = program(this, i, fn, data, depths);
406
519
  } else if (!programWrapper) {
407
- programWrapper = this.programs[i] = program(i, fn);
520
+ programWrapper = this.programs[i] = program(this, i, fn);
408
521
  }
409
522
  return programWrapper;
410
523
  },
524
+
525
+ data: function(data, depth) {
526
+ while (data && depth--) {
527
+ data = data._parent;
528
+ }
529
+ return data;
530
+ },
411
531
  merge: function(param, common) {
412
532
  var ret = param || common;
413
533
 
414
534
  if (param && common && (param !== common)) {
415
- ret = {};
416
- Utils.extend(ret, common);
417
- Utils.extend(ret, param);
535
+ ret = Utils.extend({}, common, param);
418
536
  }
537
+
419
538
  return ret;
420
539
  },
421
- programWithDepth: env.VM.programWithDepth,
540
+
422
541
  noop: env.VM.noop,
423
- compilerInfo: null
542
+ compilerInfo: templateSpec.compiler
424
543
  };
425
544
 
426
- return function(context, options) {
545
+ var ret = function(context, options) {
427
546
  options = options || {};
428
- var namespace = options.partial ? options : env,
429
- helpers,
430
- partials;
547
+ var data = options.data;
431
548
 
432
- if (!options.partial) {
433
- helpers = options.helpers;
434
- partials = options.partials;
549
+ ret._setup(options);
550
+ if (!options.partial && templateSpec.useData) {
551
+ data = initData(context, data);
435
552
  }
436
- var result = templateSpec.call(
437
- container,
438
- namespace, context,
439
- helpers,
440
- partials,
441
- options.data);
442
-
443
- if (!options.partial) {
444
- env.VM.checkRevision(container.compilerInfo);
553
+ var depths;
554
+ if (templateSpec.useDepths) {
555
+ depths = options.depths ? [context].concat(options.depths) : [context];
445
556
  }
446
557
 
447
- return result;
558
+ return templateSpec.main.call(container, context, container.helpers, container.partials, data, depths);
448
559
  };
449
- }
560
+ ret.isTop = true;
450
561
 
451
- __exports__.template = template;function programWithDepth(i, fn, data /*, $depth */) {
452
- var args = Array.prototype.slice.call(arguments, 3);
562
+ ret._setup = function(options) {
563
+ if (!options.partial) {
564
+ container.helpers = container.merge(options.helpers, env.helpers);
453
565
 
454
- var prog = function(context, options) {
455
- options = options || {};
566
+ if (templateSpec.usePartial) {
567
+ container.partials = container.merge(options.partials, env.partials);
568
+ }
569
+ } else {
570
+ container.helpers = options.helpers;
571
+ container.partials = options.partials;
572
+ }
573
+ };
574
+
575
+ ret._child = function(i, data, depths) {
576
+ if (templateSpec.useDepths && !depths) {
577
+ throw new Exception('must pass parent depths');
578
+ }
456
579
 
457
- return fn.apply(this, [context, options.data || data].concat(args));
580
+ return program(container, i, templateSpec[i], data, depths);
458
581
  };
459
- prog.program = i;
460
- prog.depth = args.length;
461
- return prog;
582
+ return ret;
462
583
  }
463
584
 
464
- __exports__.programWithDepth = programWithDepth;function program(i, fn, data) {
585
+ __exports__.template = template;function program(container, i, fn, data, depths) {
465
586
  var prog = function(context, options) {
466
587
  options = options || {};
467
588
 
468
- return fn(context, options.data || data);
589
+ return fn.call(container, context, container.helpers, container.partials, options.data || data, depths && [context].concat(depths));
469
590
  };
470
591
  prog.program = i;
471
- prog.depth = 0;
592
+ prog.depth = depths ? depths.length : 0;
472
593
  return prog;
473
594
  }
474
595
 
475
- __exports__.program = program;function invokePartial(partial, name, context, helpers, partials, data) {
476
- var options = { partial: true, helpers: helpers, partials: partials, data: data };
596
+ __exports__.program = program;function invokePartial(partial, name, context, helpers, partials, data, depths) {
597
+ var options = { partial: true, helpers: helpers, partials: partials, data: data, depths: depths };
477
598
 
478
599
  if(partial === undefined) {
479
600
  throw new Exception("The partial " + name + " could not be found");
@@ -484,7 +605,13 @@ var __module5__ = (function(__dependency1__, __dependency2__, __dependency3__) {
484
605
 
485
606
  __exports__.invokePartial = invokePartial;function noop() { return ""; }
486
607
 
487
- __exports__.noop = noop;
608
+ __exports__.noop = noop;function initData(context, data) {
609
+ if (!data || !('root' in data)) {
610
+ data = data ? createFrame(data) : {};
611
+ data.root = context;
612
+ }
613
+ return data;
614
+ }
488
615
  return __exports__;
489
616
  })(__module2__, __module4__, __module1__);
490
617
 
@@ -510,6 +637,7 @@ var __module0__ = (function(__dependency1__, __dependency2__, __dependency3__, _
510
637
  hb.SafeString = SafeString;
511
638
  hb.Exception = Exception;
512
639
  hb.Utils = Utils;
640
+ hb.escapeExpression = Utils.escapeExpression;
513
641
 
514
642
  hb.VM = runtime;
515
643
  hb.template = function(spec) {
@@ -522,9 +650,11 @@ var __module0__ = (function(__dependency1__, __dependency2__, __dependency3__, _
522
650
  var Handlebars = create();
523
651
  Handlebars.create = create;
524
652
 
653
+ Handlebars['default'] = Handlebars;
654
+
525
655
  __exports__ = Handlebars;
526
656
  return __exports__;
527
657
  })(__module1__, __module3__, __module4__, __module2__, __module5__);
528
658
 
529
659
  return __module0__;
530
- })();
660
+ }));