mustache-js-rails 2.3.0.1 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +1 -1
- data/README.md +1 -1
- data/Rakefile +1 -2
- data/lib/mustache-js-rails/version.rb +1 -1
- data/vendor/assets/javascripts/mustache.js +73 -21
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d3a389059cbfd17f2caddb9e1225a24307ad604c79827d332d611ed0b28341b
|
4
|
+
data.tar.gz: 78ebf3e7d410e4d2f264814db50dd37e19ea1329b5e43d3df442b2156abd880d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c819e72f01a9029f71217d90c4c0172cd55557da81e0e84a870147cbe9acb4d34806f0a4694f2afd19f98c7837e1c889f8b3aee79a0c9c67769749e06fd8d0e
|
7
|
+
data.tar.gz: 581f85c21a646b0bd3b2b4862a3db0094a61271d891d98e1180ac5feada6033ff40bb34b8f757fa66942995c75aedf4a404b9f40bca7cc083188fc8d6e55dbff
|
data/MIT-LICENSE
CHANGED
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">
|
8
|
+
* mustache.js - <b id="mustache-js-version">3.0.1</b>
|
9
9
|
* jQuery mustache - <b id="jquery-mustache-js-version">0.2.8</b>
|
10
10
|
|
11
11
|
### Installation
|
data/Rakefile
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
#!/usr/bin/env rake
|
2
|
-
require 'bundler/setup'
|
3
2
|
require 'bundler/gem_tasks'
|
4
3
|
|
5
4
|
task :update do
|
@@ -15,7 +14,7 @@ task :update do
|
|
15
14
|
end
|
16
15
|
|
17
16
|
puts 'Updating source files...'
|
18
|
-
`git submodule
|
17
|
+
`git submodule update --recursive --remote`
|
19
18
|
|
20
19
|
puts 'Copying source js files...'
|
21
20
|
FileUtils.cp('mustache.js/mustache.js', js_dir)
|
@@ -45,6 +45,19 @@
|
|
45
45
|
return obj != null && typeof obj === 'object' && (propName in obj);
|
46
46
|
}
|
47
47
|
|
48
|
+
/**
|
49
|
+
* Safe way of detecting whether or not the given thing is a primitive and
|
50
|
+
* whether it has the given property
|
51
|
+
*/
|
52
|
+
function primitiveHasOwnProperty (primitive, propName) {
|
53
|
+
return (
|
54
|
+
primitive != null
|
55
|
+
&& typeof primitive !== 'object'
|
56
|
+
&& primitive.hasOwnProperty
|
57
|
+
&& primitive.hasOwnProperty(propName)
|
58
|
+
);
|
59
|
+
}
|
60
|
+
|
48
61
|
// Workaround for https://issues.apache.org/jira/browse/COUCHDB-577
|
49
62
|
// See https://github.com/janl/mustache.js/issues/189
|
50
63
|
var regExpTest = RegExp.prototype.test;
|
@@ -377,11 +390,11 @@
|
|
377
390
|
if (cache.hasOwnProperty(name)) {
|
378
391
|
value = cache[name];
|
379
392
|
} else {
|
380
|
-
var context = this, names, index, lookupHit = false;
|
393
|
+
var context = this, intermediateValue, names, index, lookupHit = false;
|
381
394
|
|
382
395
|
while (context) {
|
383
396
|
if (name.indexOf('.') > 0) {
|
384
|
-
|
397
|
+
intermediateValue = context.view;
|
385
398
|
names = name.split('.');
|
386
399
|
index = 0;
|
387
400
|
|
@@ -395,20 +408,51 @@
|
|
395
408
|
*
|
396
409
|
* This is specially necessary for when the value has been set to
|
397
410
|
* `undefined` and we want to avoid looking up parent contexts.
|
411
|
+
*
|
412
|
+
* In the case where dot notation is used, we consider the lookup
|
413
|
+
* to be successful even if the last "object" in the path is
|
414
|
+
* not actually an object but a primitive (e.g., a string, or an
|
415
|
+
* integer), because it is sometimes useful to access a property
|
416
|
+
* of an autoboxed primitive, such as the length of a string.
|
398
417
|
**/
|
399
|
-
while (
|
418
|
+
while (intermediateValue != null && index < names.length) {
|
400
419
|
if (index === names.length - 1)
|
401
|
-
lookupHit =
|
420
|
+
lookupHit = (
|
421
|
+
hasProperty(intermediateValue, names[index])
|
422
|
+
|| primitiveHasOwnProperty(intermediateValue, names[index])
|
423
|
+
);
|
402
424
|
|
403
|
-
|
425
|
+
intermediateValue = intermediateValue[names[index++]];
|
404
426
|
}
|
405
427
|
} else {
|
406
|
-
|
428
|
+
intermediateValue = context.view[name];
|
429
|
+
|
430
|
+
/**
|
431
|
+
* Only checking against `hasProperty`, which always returns `false` if
|
432
|
+
* `context.view` is not an object. Deliberately omitting the check
|
433
|
+
* against `primitiveHasOwnProperty` if dot notation is not used.
|
434
|
+
*
|
435
|
+
* Consider this example:
|
436
|
+
* ```
|
437
|
+
* Mustache.render("The length of a football field is {{#length}}{{length}}{{/length}}.", {length: "100 yards"})
|
438
|
+
* ```
|
439
|
+
*
|
440
|
+
* If we were to check also against `primitiveHasOwnProperty`, as we do
|
441
|
+
* in the dot notation case, then render call would return:
|
442
|
+
*
|
443
|
+
* "The length of a football field is 9."
|
444
|
+
*
|
445
|
+
* rather than the expected:
|
446
|
+
*
|
447
|
+
* "The length of a football field is 100 yards."
|
448
|
+
**/
|
407
449
|
lookupHit = hasProperty(context.view, name);
|
408
450
|
}
|
409
451
|
|
410
|
-
if (lookupHit)
|
452
|
+
if (lookupHit) {
|
453
|
+
value = intermediateValue;
|
411
454
|
break;
|
455
|
+
}
|
412
456
|
|
413
457
|
context = context.parent;
|
414
458
|
}
|
@@ -439,15 +483,17 @@
|
|
439
483
|
};
|
440
484
|
|
441
485
|
/**
|
442
|
-
* Parses and caches the given `template`
|
486
|
+
* Parses and caches the given `template` according to the given `tags` or
|
487
|
+
* `mustache.tags` if `tags` is omitted, and returns the array of tokens
|
443
488
|
* that is generated from the parse.
|
444
489
|
*/
|
445
490
|
Writer.prototype.parse = function parse (template, tags) {
|
446
491
|
var cache = this.cache;
|
447
|
-
var
|
492
|
+
var cacheKey = template + ':' + (tags || mustache.tags).join(':');
|
493
|
+
var tokens = cache[cacheKey];
|
448
494
|
|
449
495
|
if (tokens == null)
|
450
|
-
tokens = cache[
|
496
|
+
tokens = cache[cacheKey] = parseTemplate(template, tags);
|
451
497
|
|
452
498
|
return tokens;
|
453
499
|
};
|
@@ -460,11 +506,15 @@
|
|
460
506
|
* names and templates of partials that are used in the template. It may
|
461
507
|
* also be a function that is used to load partial templates on the fly
|
462
508
|
* that takes a single argument: the name of the partial.
|
509
|
+
*
|
510
|
+
* If the optional `tags` argument is given here it must be an array with two
|
511
|
+
* string values: the opening and closing tags used in the template (e.g.
|
512
|
+
* [ "<%", "%>" ]). The default is to mustache.tags.
|
463
513
|
*/
|
464
|
-
Writer.prototype.render = function render (template, view, partials) {
|
465
|
-
var tokens = this.parse(template);
|
514
|
+
Writer.prototype.render = function render (template, view, partials, tags) {
|
515
|
+
var tokens = this.parse(template, tags);
|
466
516
|
var context = (view instanceof Context) ? view : new Context(view);
|
467
|
-
return this.renderTokens(tokens, context, partials, template);
|
517
|
+
return this.renderTokens(tokens, context, partials, template, tags);
|
468
518
|
};
|
469
519
|
|
470
520
|
/**
|
@@ -476,7 +526,7 @@
|
|
476
526
|
* If the template doesn't use higher-order sections, this argument may
|
477
527
|
* be omitted.
|
478
528
|
*/
|
479
|
-
Writer.prototype.renderTokens = function renderTokens (tokens, context, partials, originalTemplate) {
|
529
|
+
Writer.prototype.renderTokens = function renderTokens (tokens, context, partials, originalTemplate, tags) {
|
480
530
|
var buffer = '';
|
481
531
|
|
482
532
|
var token, symbol, value;
|
@@ -487,7 +537,7 @@
|
|
487
537
|
|
488
538
|
if (symbol === '#') value = this.renderSection(token, context, partials, originalTemplate);
|
489
539
|
else if (symbol === '^') value = this.renderInverted(token, context, partials, originalTemplate);
|
490
|
-
else if (symbol === '>') value = this.renderPartial(token, context, partials,
|
540
|
+
else if (symbol === '>') value = this.renderPartial(token, context, partials, tags);
|
491
541
|
else if (symbol === '&') value = this.unescapedValue(token, context);
|
492
542
|
else if (symbol === 'name') value = this.escapedValue(token, context);
|
493
543
|
else if (symbol === 'text') value = this.rawValue(token);
|
@@ -542,12 +592,12 @@
|
|
542
592
|
return this.renderTokens(token[4], context, partials, originalTemplate);
|
543
593
|
};
|
544
594
|
|
545
|
-
Writer.prototype.renderPartial = function renderPartial (token, context, partials) {
|
595
|
+
Writer.prototype.renderPartial = function renderPartial (token, context, partials, tags) {
|
546
596
|
if (!partials) return;
|
547
597
|
|
548
598
|
var value = isFunction(partials) ? partials(token[1]) : partials[token[1]];
|
549
599
|
if (value != null)
|
550
|
-
return this.renderTokens(this.parse(value), context, partials, value);
|
600
|
+
return this.renderTokens(this.parse(value, tags), context, partials, value);
|
551
601
|
};
|
552
602
|
|
553
603
|
Writer.prototype.unescapedValue = function unescapedValue (token, context) {
|
@@ -567,7 +617,7 @@
|
|
567
617
|
};
|
568
618
|
|
569
619
|
mustache.name = 'mustache.js';
|
570
|
-
mustache.version = '
|
620
|
+
mustache.version = '3.0.1';
|
571
621
|
mustache.tags = [ '{{', '}}' ];
|
572
622
|
|
573
623
|
// All high-level mustache.* functions use this writer.
|
@@ -591,16 +641,18 @@
|
|
591
641
|
|
592
642
|
/**
|
593
643
|
* Renders the `template` with the given `view` and `partials` using the
|
594
|
-
* default writer.
|
644
|
+
* default writer. If the optional `tags` argument is given here it must be an
|
645
|
+
* array with two string values: the opening and closing tags used in the
|
646
|
+
* template (e.g. [ "<%", "%>" ]). The default is to mustache.tags.
|
595
647
|
*/
|
596
|
-
mustache.render = function render (template, view, partials) {
|
648
|
+
mustache.render = function render (template, view, partials, tags) {
|
597
649
|
if (typeof template !== 'string') {
|
598
650
|
throw new TypeError('Invalid template! Template should be a "string" ' +
|
599
651
|
'but "' + typeStr(template) + '" was given as the first ' +
|
600
652
|
'argument for mustache#render(template, view, partials)');
|
601
653
|
}
|
602
654
|
|
603
|
-
return defaultWriter.render(template, view, partials);
|
655
|
+
return defaultWriter.render(template, view, partials, tags);
|
604
656
|
};
|
605
657
|
|
606
658
|
// This is here for backwards compatibility with 0.4.x.,
|
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:
|
4
|
+
version: 3.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Krzysztof Knapik
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -68,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
68
|
version: '0'
|
69
69
|
requirements: []
|
70
70
|
rubyforge_project: mustache-js-rails
|
71
|
-
rubygems_version: 2.7.
|
71
|
+
rubygems_version: 2.7.7
|
72
72
|
signing_key:
|
73
73
|
specification_version: 4
|
74
74
|
summary: mustache.js and jQuery.mustache.js for Rails 3.1+ asset pipeline
|