mustache-js-rails 3.0.1 → 3.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6d3a389059cbfd17f2caddb9e1225a24307ad604c79827d332d611ed0b28341b
4
- data.tar.gz: 78ebf3e7d410e4d2f264814db50dd37e19ea1329b5e43d3df442b2156abd880d
3
+ metadata.gz: 8e571a562cb620ea6b136e61db57909e64d8d720934d8eb6aa4a2138955b74e3
4
+ data.tar.gz: 70bcc946012dea4a264c343797f9ce6b7c30052ba7670ed3f0dd3903575a945f
5
5
  SHA512:
6
- metadata.gz: 0c819e72f01a9029f71217d90c4c0172cd55557da81e0e84a870147cbe9acb4d34806f0a4694f2afd19f98c7837e1c889f8b3aee79a0c9c67769749e06fd8d0e
7
- data.tar.gz: 581f85c21a646b0bd3b2b4862a3db0094a61271d891d98e1180ac5feada6033ff40bb34b8f757fa66942995c75aedf4a404b9f40bca7cc083188fc8d6e55dbff
6
+ metadata.gz: 0a4c07e01ba65011acfa8ff2cd366da459a97250212abe4a9f721b57f6ce0d8c5931944e541af7a285c9067076f0fc4e52093a4b286118ca28bfbb7fe0f93b13
7
+ data.tar.gz: 21d41e2e0bfa9869f1b746a8a50f32a0e49f1cfed987787b2667385bc1e9a66c8eaf190f04c761e7efa9877c942174ae7514eda7d16f1035a4760115172012f6
File without changes
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">3.0.1</b>
8
+ * mustache.js - <b id="mustache-js-version">3.1.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 = "3.0.1"
2
+ VERSION = "3.1.0"
3
3
  end
@@ -49,7 +49,7 @@
49
49
  * Safe way of detecting whether or not the given thing is a primitive and
50
50
  * whether it has the given property
51
51
  */
52
- function primitiveHasOwnProperty (primitive, propName) {
52
+ function primitiveHasOwnProperty (primitive, propName) {
53
53
  return (
54
54
  primitive != null
55
55
  && typeof primitive !== 'object'
@@ -114,16 +114,22 @@
114
114
  * Tokens that are the root node of a subtree contain two more elements: 1) an
115
115
  * array of tokens in the subtree and 2) the index in the original template at
116
116
  * which the closing tag for that section begins.
117
+ *
118
+ * Tokens for partials also contain two more elements: 1) a string value of
119
+ * indendation prior to that tag and 2) the index of that tag on that line -
120
+ * eg a value of 2 indicates the partial is the third tag on this line.
117
121
  */
118
122
  function parseTemplate (template, tags) {
119
123
  if (!template)
120
124
  return [];
121
-
125
+ var lineHasNonSpace = false;
122
126
  var sections = []; // Stack to hold section tokens
123
127
  var tokens = []; // Buffer to hold the tokens
124
128
  var spaces = []; // Indices of whitespace tokens on the current line
125
129
  var hasTag = false; // Is there a {{tag}} on the current line?
126
130
  var nonSpace = false; // Is there a non-space char on the current line?
131
+ var indentation = ''; // Tracks indentation for tags that use it
132
+ var tagIndex = 0; // Stores a count of number of tags encountered on a line
127
133
 
128
134
  // Strips all whitespace tokens array for the current line
129
135
  // if there was a {{#tag}} on it and otherwise only space.
@@ -169,16 +175,23 @@
169
175
 
170
176
  if (isWhitespace(chr)) {
171
177
  spaces.push(tokens.length);
178
+ indentation += chr;
172
179
  } else {
173
180
  nonSpace = true;
181
+ lineHasNonSpace = true;
182
+ indentation += ' ';
174
183
  }
175
184
 
176
185
  tokens.push([ 'text', chr, start, start + 1 ]);
177
186
  start += 1;
178
187
 
179
188
  // Check for whitespace on the current line.
180
- if (chr === '\n')
189
+ if (chr === '\n') {
181
190
  stripSpace();
191
+ indentation = '';
192
+ tagIndex = 0;
193
+ lineHasNonSpace = false;
194
+ }
182
195
  }
183
196
  }
184
197
 
@@ -210,7 +223,12 @@
210
223
  if (!scanner.scan(closingTagRe))
211
224
  throw new Error('Unclosed tag at ' + scanner.pos);
212
225
 
213
- token = [ type, value, start, scanner.pos ];
226
+ if (type == '>') {
227
+ token = [ type, value, start, scanner.pos, indentation, tagIndex, lineHasNonSpace ];
228
+ } else {
229
+ token = [ type, value, start, scanner.pos ];
230
+ }
231
+ tagIndex++;
214
232
  tokens.push(token);
215
233
 
216
234
  if (type === '#' || type === '^') {
@@ -232,6 +250,8 @@
232
250
  }
233
251
  }
234
252
 
253
+ stripSpace();
254
+
235
255
  // Make sure there are no open sections when we're done.
236
256
  openSection = sections.pop();
237
257
 
@@ -418,7 +438,7 @@
418
438
  while (intermediateValue != null && index < names.length) {
419
439
  if (index === names.length - 1)
420
440
  lookupHit = (
421
- hasProperty(intermediateValue, names[index])
441
+ hasProperty(intermediateValue, names[index])
422
442
  || primitiveHasOwnProperty(intermediateValue, names[index])
423
443
  );
424
444
 
@@ -592,12 +612,31 @@
592
612
  return this.renderTokens(token[4], context, partials, originalTemplate);
593
613
  };
594
614
 
615
+ Writer.prototype.indentPartial = function indentPartial (partial, indentation, lineHasNonSpace) {
616
+ var filteredIndentation = indentation.replace(/[^ \t]/g, '');
617
+ var partialByNl = partial.split('\n');
618
+ for (var i = 0; i < partialByNl.length; i++) {
619
+ if (partialByNl[i].length && (i > 0 || !lineHasNonSpace)) {
620
+ partialByNl[i] = filteredIndentation + partialByNl[i];
621
+ }
622
+ }
623
+ return partialByNl.join('\n');
624
+ };
625
+
595
626
  Writer.prototype.renderPartial = function renderPartial (token, context, partials, tags) {
596
627
  if (!partials) return;
597
628
 
598
629
  var value = isFunction(partials) ? partials(token[1]) : partials[token[1]];
599
- if (value != null)
600
- return this.renderTokens(this.parse(value, tags), context, partials, value);
630
+ if (value != null) {
631
+ var lineHasNonSpace = token[6];
632
+ var tagIndex = token[5];
633
+ var indentation = token[4];
634
+ var indentedValue = value;
635
+ if (tagIndex == 0 && indentation) {
636
+ indentedValue = this.indentPartial(value, indentation, lineHasNonSpace);
637
+ }
638
+ return this.renderTokens(this.parse(indentedValue, tags), context, partials, indentedValue);
639
+ }
601
640
  };
602
641
 
603
642
  Writer.prototype.unescapedValue = function unescapedValue (token, context) {
@@ -617,7 +656,7 @@
617
656
  };
618
657
 
619
658
  mustache.name = 'mustache.js';
620
- mustache.version = '3.0.1';
659
+ mustache.version = '3.1.0';
621
660
  mustache.tags = [ '{{', '}}' ];
622
661
 
623
662
  // All high-level mustache.* functions use this writer.
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: 3.0.1
4
+ version: 3.1.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: 2019-01-02 00:00:00.000000000 Z
11
+ date: 2019-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -17,9 +17,6 @@ dependencies:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.1'
20
- - - "<"
21
- - !ruby/object:Gem::Version
22
- version: '6'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
@@ -27,12 +24,21 @@ dependencies:
27
24
  - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '3.1'
30
- - - "<"
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
31
32
  - !ruby/object:Gem::Version
32
- version: '6'
33
- description: "\n mustache.js (https://github.com/janl/mustache.js)\n and jQuery.mustache.js
34
- (https://github.com/jonnyreeves/jquery-Mustache)\n for Rails 3.1+ asset pipeline\n
35
- \ "
33
+ version: '10.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.5'
41
+ description:
36
42
  email:
37
43
  - knapo@knapo.net
38
44
  executables: []
@@ -40,9 +46,8 @@ extensions: []
40
46
  extra_rdoc_files: []
41
47
  files:
42
48
  - Gemfile
43
- - MIT-LICENSE
49
+ - LICENSE
44
50
  - README.md
45
- - Rakefile
46
51
  - lib/mustache-js-rails.rb
47
52
  - lib/mustache-js-rails/engine.rb
48
53
  - lib/mustache-js-rails/version.rb
@@ -51,7 +56,9 @@ files:
51
56
  homepage: https://github.com/knapo/mustache-js-rails
52
57
  licenses:
53
58
  - MIT
54
- metadata: {}
59
+ metadata:
60
+ homepage_uri: https://github.com/knapo/mustache-js-rails
61
+ source_code_uri: https://github.com/knapo/mustache-js-rails
55
62
  post_install_message:
56
63
  rdoc_options: []
57
64
  require_paths:
@@ -60,16 +67,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
60
67
  requirements:
61
68
  - - ">="
62
69
  - !ruby/object:Gem::Version
63
- version: '0'
70
+ version: 2.0.0
64
71
  required_rubygems_version: !ruby/object:Gem::Requirement
65
72
  requirements:
66
73
  - - ">="
67
74
  - !ruby/object:Gem::Version
68
75
  version: '0'
69
76
  requirements: []
70
- rubyforge_project: mustache-js-rails
71
- rubygems_version: 2.7.7
77
+ rubygems_version: 3.0.6
72
78
  signing_key:
73
79
  specification_version: 4
74
- summary: mustache.js and jQuery.mustache.js for Rails 3.1+ asset pipeline
80
+ summary: jQuery Colorbox integration for Rails 3.1+ asset pipeline
75
81
  test_files: []
data/Rakefile DELETED
@@ -1,32 +0,0 @@
1
- #!/usr/bin/env rake
2
- require 'bundler/gem_tasks'
3
-
4
- task :update do
5
- Dir['*.gem'].each{ |f| FileUtils.rm(f) }
6
-
7
- js_dir = 'vendor/assets/javascripts'
8
- css_dir = 'vendor/assets/stylesheets'
9
- img_dir = 'vendor/assets/images'
10
- [js_dir, css_dir, img_dir].each do |dir|
11
- FileUtils.rm_r(dir)
12
- FileUtils.mkdir(dir)
13
- FileUtils.touch(File.join(dir, '.gitkeep'))
14
- end
15
-
16
- puts 'Updating source files...'
17
- `git submodule update --recursive --remote`
18
-
19
- puts 'Copying source js files...'
20
- FileUtils.cp('mustache.js/mustache.js', js_dir)
21
- FileUtils.cp('jquery.mustache.js/jquery.mustache.js', js_dir)
22
-
23
- puts 'Updating version...'
24
- mustache_js_version = File.read('mustache.js/mustache.js.nuspec').match(/<version>([\.\d]+)<\/version>/)[1]
25
- jquery_mustache_js_version = File.read('jquery.mustache.js/jquery.mustache.js').match(/jQuery Mustache - v([\.\d]+)/)[1]
26
- puts "Current mustache.js version is: #{mustache_js_version}"
27
- puts "Current jquery.mustache.js version is: #{jquery_mustache_js_version}"
28
- readme = File.read('README.md')
29
- readme = readme.gsub(/(?<=<b id="mustache-js-version">)[\d\.]+(?=<\/b>)/, mustache_js_version)
30
- readme = readme.gsub(/(?<=<b id="jquery-mustache-js-version">)[\d\.]+(?=<\/b>)/, jquery_mustache_js_version)
31
- File.open('README.md','w') { |f| f.write(readme) }
32
- end