mustache-js-rails 1.1.0 → 2.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 mustache-js-rails might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d658a53c1a9063220c7daf0d0a9ba752fec30531
4
- data.tar.gz: ce7b2dd677355aad2e6a45deaf819cbaad132ac1
3
+ metadata.gz: 3efc59f2fbc6520360b21c37a205213dde47dc25
4
+ data.tar.gz: dda31c41707ad5a12d80c760385d866a24cdff1d
5
5
  SHA512:
6
- metadata.gz: cf540b78ab2ace41dd12eeda6cfc3cc7fcf3420b29ec0557034900f749e70f215670c0a4ef5d69ee63dcb214c98085829367e0c575f6630c5784d4422a6883ea
7
- data.tar.gz: da57b314657f3bbff435ff8c73ce25d6d575600085ad44dbe4912502a9e42d4d8bc55d1e95f552449a436e12cb92112b51fdec635164ea7e2f5281a322dec72e
6
+ metadata.gz: a8f72c19a95b1a00cfb4953bc79fcc5e7df4d7280424d5b19996e1558a242f8e37f23e5e188ea07ad1e709c2510a4f5c5c5f7267710fadde6027a9632bb4ab65
7
+ data.tar.gz: 4ab84cfefbb4885678259d0ea97b28817ec7a0d5ff012ae89da717afaacaafe0be56ea71c8e5f9a84f5bf690e80dd087e734d87d0c113db281c7f35ae1096343
data/README.md CHANGED
@@ -5,7 +5,7 @@ and [mustache jQuery integration](https://github.com/jonnyreeves/jquery-Mustache
5
5
 
6
6
  Integrated versions are:
7
7
 
8
- * mustache.js - <b id="mustache-js-version">1.1.0</b>
8
+ * mustache.js - <b id="mustache-js-version">2.0.0</b>
9
9
  * jQuery mustache - <b id="jquery-mustache-js-version">0.2.8</b>
10
10
 
11
11
  ### Installation
@@ -1,3 +1,3 @@
1
1
  module MustacheJsRails
2
- VERSION = "1.1.0"
2
+ VERSION = "2.0.0"
3
3
  end
@@ -5,52 +5,52 @@
5
5
 
6
6
  /*global define: false*/
7
7
 
8
- (function (global, factory) {
9
- if (typeof exports === "object" && exports) {
8
+ (function defineMustache (global, factory) {
9
+ if (typeof exports === 'object' && exports) {
10
10
  factory(exports); // CommonJS
11
- } else if (typeof define === "function" && define.amd) {
11
+ } else if (typeof define === 'function' && define.amd) {
12
12
  define(['exports'], factory); // AMD
13
13
  } else {
14
14
  factory(global.Mustache = {}); // <script>
15
15
  }
16
- }(this, function (mustache) {
16
+ }(this, function mustacheFactory (mustache) {
17
17
 
18
- var Object_toString = Object.prototype.toString;
19
- var isArray = Array.isArray || function (object) {
20
- return Object_toString.call(object) === '[object Array]';
18
+ var objectToString = Object.prototype.toString;
19
+ var isArray = Array.isArray || function isArrayPolyfill (object) {
20
+ return objectToString.call(object) === '[object Array]';
21
21
  };
22
22
 
23
- function isFunction(object) {
23
+ function isFunction (object) {
24
24
  return typeof object === 'function';
25
25
  }
26
26
 
27
- function escapeRegExp(string) {
28
- return string.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&");
27
+ function escapeRegExp (string) {
28
+ return string.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, '\\$&');
29
29
  }
30
30
 
31
31
  // Workaround for https://issues.apache.org/jira/browse/COUCHDB-577
32
32
  // See https://github.com/janl/mustache.js/issues/189
33
- var RegExp_test = RegExp.prototype.test;
34
- function testRegExp(re, string) {
35
- return RegExp_test.call(re, string);
33
+ var regExpTest = RegExp.prototype.test;
34
+ function testRegExp (re, string) {
35
+ return regExpTest.call(re, string);
36
36
  }
37
37
 
38
38
  var nonSpaceRe = /\S/;
39
- function isWhitespace(string) {
39
+ function isWhitespace (string) {
40
40
  return !testRegExp(nonSpaceRe, string);
41
41
  }
42
42
 
43
43
  var entityMap = {
44
- "&": "&amp;",
45
- "<": "&lt;",
46
- ">": "&gt;",
44
+ '&': '&amp;',
45
+ '<': '&lt;',
46
+ '>': '&gt;',
47
47
  '"': '&quot;',
48
48
  "'": '&#39;',
49
- "/": '&#x2F;'
49
+ '/': '&#x2F;'
50
50
  };
51
51
 
52
- function escapeHtml(string) {
53
- return String(string).replace(/[&<>"'\/]/g, function (s) {
52
+ function escapeHtml (string) {
53
+ return String(string).replace(/[&<>"'\/]/g, function fromEntityMap (s) {
54
54
  return entityMap[s];
55
55
  });
56
56
  }
@@ -83,7 +83,7 @@
83
83
  * array of tokens in the subtree and 2) the index in the original template at
84
84
  * which the closing tag for that section begins.
85
85
  */
86
- function parseTemplate(template, tags) {
86
+ function parseTemplate (template, tags) {
87
87
  if (!template)
88
88
  return [];
89
89
 
@@ -95,7 +95,7 @@
95
95
 
96
96
  // Strips all whitespace tokens array for the current line
97
97
  // if there was a {{#tag}} on it and otherwise only space.
98
- function stripSpace() {
98
+ function stripSpace () {
99
99
  if (hasTag && !nonSpace) {
100
100
  while (spaces.length)
101
101
  delete tokens[spaces.pop()];
@@ -108,16 +108,16 @@
108
108
  }
109
109
 
110
110
  var openingTagRe, closingTagRe, closingCurlyRe;
111
- function compileTags(tags) {
112
- if (typeof tags === 'string')
113
- tags = tags.split(spaceRe, 2);
111
+ function compileTags (tagsToCompile) {
112
+ if (typeof tagsToCompile === 'string')
113
+ tagsToCompile = tagsToCompile.split(spaceRe, 2);
114
114
 
115
- if (!isArray(tags) || tags.length !== 2)
116
- throw new Error('Invalid tags: ' + tags);
115
+ if (!isArray(tagsToCompile) || tagsToCompile.length !== 2)
116
+ throw new Error('Invalid tags: ' + tagsToCompile);
117
117
 
118
- openingTagRe = new RegExp(escapeRegExp(tags[0]) + '\\s*');
119
- closingTagRe = new RegExp('\\s*' + escapeRegExp(tags[1]));
120
- closingCurlyRe = new RegExp('\\s*' + escapeRegExp('}' + tags[1]));
118
+ openingTagRe = new RegExp(escapeRegExp(tagsToCompile[0]) + '\\s*');
119
+ closingTagRe = new RegExp('\\s*' + escapeRegExp(tagsToCompile[1]));
120
+ closingCurlyRe = new RegExp('\\s*' + escapeRegExp('}' + tagsToCompile[1]));
121
121
  }
122
122
 
123
123
  compileTags(tags || mustache.tags);
@@ -213,7 +213,7 @@
213
213
  * Combines the values of consecutive text tokens in the given `tokens` array
214
214
  * to a single token.
215
215
  */
216
- function squashTokens(tokens) {
216
+ function squashTokens (tokens) {
217
217
  var squashedTokens = [];
218
218
 
219
219
  var token, lastToken;
@@ -240,7 +240,7 @@
240
240
  * all tokens that appear in that section and 2) the index in the original
241
241
  * template that represents the end of that section.
242
242
  */
243
- function nestTokens(tokens) {
243
+ function nestTokens (tokens) {
244
244
  var nestedTokens = [];
245
245
  var collector = nestedTokens;
246
246
  var sections = [];
@@ -273,7 +273,7 @@
273
273
  * A simple string scanner that is used by the template parser to find
274
274
  * tokens in template strings.
275
275
  */
276
- function Scanner(string) {
276
+ function Scanner (string) {
277
277
  this.string = string;
278
278
  this.tail = string;
279
279
  this.pos = 0;
@@ -282,15 +282,15 @@
282
282
  /**
283
283
  * Returns `true` if the tail is empty (end of string).
284
284
  */
285
- Scanner.prototype.eos = function () {
286
- return this.tail === "";
285
+ Scanner.prototype.eos = function eos () {
286
+ return this.tail === '';
287
287
  };
288
288
 
289
289
  /**
290
290
  * Tries to match the given regular expression at the current position.
291
291
  * Returns the matched text if it can match, the empty string otherwise.
292
292
  */
293
- Scanner.prototype.scan = function (re) {
293
+ Scanner.prototype.scan = function scan (re) {
294
294
  var match = this.tail.match(re);
295
295
 
296
296
  if (!match || match.index !== 0)
@@ -308,16 +308,16 @@
308
308
  * Skips all text until the given regular expression can be matched. Returns
309
309
  * the skipped string, which is the entire tail if no match can be made.
310
310
  */
311
- Scanner.prototype.scanUntil = function (re) {
311
+ Scanner.prototype.scanUntil = function scanUntil (re) {
312
312
  var index = this.tail.search(re), match;
313
313
 
314
314
  switch (index) {
315
315
  case -1:
316
316
  match = this.tail;
317
- this.tail = "";
317
+ this.tail = '';
318
318
  break;
319
319
  case 0:
320
- match = "";
320
+ match = '';
321
321
  break;
322
322
  default:
323
323
  match = this.tail.substring(0, index);
@@ -333,8 +333,8 @@
333
333
  * Represents a rendering context by wrapping a view object and
334
334
  * maintaining a reference to the parent context.
335
335
  */
336
- function Context(view, parentContext) {
337
- this.view = view == null ? {} : view;
336
+ function Context (view, parentContext) {
337
+ this.view = view;
338
338
  this.cache = { '.': this.view };
339
339
  this.parent = parentContext;
340
340
  }
@@ -343,7 +343,7 @@
343
343
  * Creates a new context using the given view with this context
344
344
  * as the parent.
345
345
  */
346
- Context.prototype.push = function (view) {
346
+ Context.prototype.push = function push (view) {
347
347
  return new Context(view, this);
348
348
  };
349
349
 
@@ -351,14 +351,14 @@
351
351
  * Returns the value of the given name in this context, traversing
352
352
  * up the context hierarchy if the value is absent in this context's view.
353
353
  */
354
- Context.prototype.lookup = function (name) {
354
+ Context.prototype.lookup = function lookup (name) {
355
355
  var cache = this.cache;
356
356
 
357
357
  var value;
358
358
  if (name in cache) {
359
359
  value = cache[name];
360
360
  } else {
361
- var context = this, names, index;
361
+ var context = this, names, index, lookupHit = false;
362
362
 
363
363
  while (context) {
364
364
  if (name.indexOf('.') > 0) {
@@ -366,13 +366,29 @@
366
366
  names = name.split('.');
367
367
  index = 0;
368
368
 
369
- while (value != null && index < names.length)
369
+ /**
370
+ * Using the dot notion path in `name`, we descend through the
371
+ * nested objects.
372
+ *
373
+ * To be certain that the lookup has been successful, we have to
374
+ * check if the last object in the path actually has the property
375
+ * we are looking for. We store the result in `lookupHit`.
376
+ *
377
+ * This is specially necessary for when the value has been set to
378
+ * `undefined` and we want to avoid looking up parent contexts.
379
+ **/
380
+ while (value != null && index < names.length) {
381
+ if (index === names.length - 1 && value != null)
382
+ lookupHit = (typeof value === 'object') &&
383
+ value.hasOwnProperty(names[index]);
370
384
  value = value[names[index++]];
371
- } else if (typeof context.view == 'object') {
385
+ }
386
+ } else if (context.view != null && typeof context.view === 'object') {
372
387
  value = context.view[name];
388
+ lookupHit = context.view.hasOwnProperty(name);
373
389
  }
374
390
 
375
- if (value != null)
391
+ if (lookupHit)
376
392
  break;
377
393
 
378
394
  context = context.parent;
@@ -392,14 +408,14 @@
392
408
  * string, given a context. It also maintains a cache of templates to
393
409
  * avoid the need to parse the same template twice.
394
410
  */
395
- function Writer() {
411
+ function Writer () {
396
412
  this.cache = {};
397
413
  }
398
414
 
399
415
  /**
400
416
  * Clears all cached templates in this writer.
401
417
  */
402
- Writer.prototype.clearCache = function () {
418
+ Writer.prototype.clearCache = function clearCache () {
403
419
  this.cache = {};
404
420
  };
405
421
 
@@ -407,7 +423,7 @@
407
423
  * Parses and caches the given `template` and returns the array of tokens
408
424
  * that is generated from the parse.
409
425
  */
410
- Writer.prototype.parse = function (template, tags) {
426
+ Writer.prototype.parse = function parse (template, tags) {
411
427
  var cache = this.cache;
412
428
  var tokens = cache[template];
413
429
 
@@ -426,7 +442,7 @@
426
442
  * also be a function that is used to load partial templates on the fly
427
443
  * that takes a single argument: the name of the partial.
428
444
  */
429
- Writer.prototype.render = function (template, view, partials) {
445
+ Writer.prototype.render = function render (template, view, partials) {
430
446
  var tokens = this.parse(template);
431
447
  var context = (view instanceof Context) ? view : new Context(view);
432
448
  return this.renderTokens(tokens, context, partials, template);
@@ -441,7 +457,7 @@
441
457
  * If the template doesn't use higher-order sections, this argument may
442
458
  * be omitted.
443
459
  */
444
- Writer.prototype.renderTokens = function (tokens, context, partials, originalTemplate) {
460
+ Writer.prototype.renderTokens = function renderTokens (tokens, context, partials, originalTemplate) {
445
461
  var buffer = '';
446
462
 
447
463
  var token, symbol, value;
@@ -450,12 +466,12 @@
450
466
  token = tokens[i];
451
467
  symbol = token[0];
452
468
 
453
- if (symbol === '#') value = this._renderSection(token, context, partials, originalTemplate);
454
- else if (symbol === '^') value = this._renderInverted(token, context, partials, originalTemplate);
455
- else if (symbol === '>') value = this._renderPartial(token, context, partials, originalTemplate);
456
- else if (symbol === '&') value = this._unescapedValue(token, context);
457
- else if (symbol === 'name') value = this._escapedValue(token, context);
458
- else if (symbol === 'text') value = this._rawValue(token);
469
+ if (symbol === '#') value = this.renderSection(token, context, partials, originalTemplate);
470
+ else if (symbol === '^') value = this.renderInverted(token, context, partials, originalTemplate);
471
+ else if (symbol === '>') value = this.renderPartial(token, context, partials, originalTemplate);
472
+ else if (symbol === '&') value = this.unescapedValue(token, context);
473
+ else if (symbol === 'name') value = this.escapedValue(token, context);
474
+ else if (symbol === 'text') value = this.rawValue(token);
459
475
 
460
476
  if (value !== undefined)
461
477
  buffer += value;
@@ -464,14 +480,14 @@
464
480
  return buffer;
465
481
  };
466
482
 
467
- Writer.prototype._renderSection = function (token, context, partials, originalTemplate) {
483
+ Writer.prototype.renderSection = function renderSection (token, context, partials, originalTemplate) {
468
484
  var self = this;
469
485
  var buffer = '';
470
486
  var value = context.lookup(token[1]);
471
487
 
472
488
  // This function is used to render an arbitrary template
473
489
  // in the current context by higher-order sections.
474
- function subRender(template) {
490
+ function subRender (template) {
475
491
  return self.render(template, context, partials);
476
492
  }
477
493
 
@@ -481,7 +497,7 @@
481
497
  for (var j = 0, valueLength = value.length; j < valueLength; ++j) {
482
498
  buffer += this.renderTokens(token[4], context.push(value[j]), partials, originalTemplate);
483
499
  }
484
- } else if (typeof value === 'object' || typeof value === 'string') {
500
+ } else if (typeof value === 'object' || typeof value === 'string' || typeof value === 'number') {
485
501
  buffer += this.renderTokens(token[4], context.push(value), partials, originalTemplate);
486
502
  } else if (isFunction(value)) {
487
503
  if (typeof originalTemplate !== 'string')
@@ -498,7 +514,7 @@
498
514
  return buffer;
499
515
  };
500
516
 
501
- Writer.prototype._renderInverted = function(token, context, partials, originalTemplate) {
517
+ Writer.prototype.renderInverted = function renderInverted (token, context, partials, originalTemplate) {
502
518
  var value = context.lookup(token[1]);
503
519
 
504
520
  // Use JavaScript's definition of falsy. Include empty arrays.
@@ -507,7 +523,7 @@
507
523
  return this.renderTokens(token[4], context, partials, originalTemplate);
508
524
  };
509
525
 
510
- Writer.prototype._renderPartial = function(token, context, partials) {
526
+ Writer.prototype.renderPartial = function renderPartial (token, context, partials) {
511
527
  if (!partials) return;
512
528
 
513
529
  var value = isFunction(partials) ? partials(token[1]) : partials[token[1]];
@@ -515,25 +531,25 @@
515
531
  return this.renderTokens(this.parse(value), context, partials, value);
516
532
  };
517
533
 
518
- Writer.prototype._unescapedValue = function(token, context) {
534
+ Writer.prototype.unescapedValue = function unescapedValue (token, context) {
519
535
  var value = context.lookup(token[1]);
520
536
  if (value != null)
521
537
  return value;
522
538
  };
523
539
 
524
- Writer.prototype._escapedValue = function(token, context) {
540
+ Writer.prototype.escapedValue = function escapedValue (token, context) {
525
541
  var value = context.lookup(token[1]);
526
542
  if (value != null)
527
543
  return mustache.escape(value);
528
544
  };
529
545
 
530
- Writer.prototype._rawValue = function(token) {
546
+ Writer.prototype.rawValue = function rawValue (token) {
531
547
  return token[1];
532
548
  };
533
549
 
534
- mustache.name = "mustache.js";
535
- mustache.version = "1.1.0";
536
- mustache.tags = [ "{{", "}}" ];
550
+ mustache.name = 'mustache.js';
551
+ mustache.version = '2.0.0';
552
+ mustache.tags = [ '{{', '}}' ];
537
553
 
538
554
  // All high-level mustache.* functions use this writer.
539
555
  var defaultWriter = new Writer();
@@ -541,7 +557,7 @@
541
557
  /**
542
558
  * Clears all cached templates in the default writer.
543
559
  */
544
- mustache.clearCache = function () {
560
+ mustache.clearCache = function clearCache () {
545
561
  return defaultWriter.clearCache();
546
562
  };
547
563
 
@@ -550,7 +566,7 @@
550
566
  * array of tokens it contains. Doing this ahead of time avoids the need to
551
567
  * parse templates on the fly as they are rendered.
552
568
  */
553
- mustache.parse = function (template, tags) {
569
+ mustache.parse = function parse (template, tags) {
554
570
  return defaultWriter.parse(template, tags);
555
571
  };
556
572
 
@@ -558,12 +574,15 @@
558
574
  * Renders the `template` with the given `view` and `partials` using the
559
575
  * default writer.
560
576
  */
561
- mustache.render = function (template, view, partials) {
577
+ mustache.render = function render (template, view, partials) {
562
578
  return defaultWriter.render(template, view, partials);
563
579
  };
564
580
 
565
- // This is here for backwards compatibility with 0.4.x.
566
- mustache.to_html = function (template, view, partials, send) {
581
+ // This is here for backwards compatibility with 0.4.x.,
582
+ /*eslint-disable */ // eslint wants camel cased function name
583
+ mustache.to_html = function to_html (template, view, partials, send) {
584
+ /*eslint-enable*/
585
+
567
586
  var result = mustache.render(template, view, partials);
568
587
 
569
588
  if (isFunction(send)) {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mustache-js-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Krzysztof Knapik
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-01 00:00:00.000000000 Z
11
+ date: 2015-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties