mustache-js-rails 0.0.7 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.

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: fe70b48ee69c0c14080983551dd6aa7b952fd383
4
- data.tar.gz: 768ecd0124ff9327f4e0b93f0feb75736ff17d87
3
+ metadata.gz: 79c7fb99b94ab2a8b73dda4fa42fdc59cbf16d34
4
+ data.tar.gz: 9c2d101179b78ecc1cd6af33d20f9838dccf1c26
5
5
  SHA512:
6
- metadata.gz: 30fdf8b400ad236a6a8eb600458adfdc64140da14c69f432f97f7ec75e0f199d3df4c11127c7e3cfd0d902d6e5979b43d0d3c36786036d7775675097c0b4b2e2
7
- data.tar.gz: 07d3755af7a32608cf07b77af1d1b10647eb5eceecb6e5b135e1c2fc9b4528b5556bbed09522c93ff80d5b05749730b79f16103bb6e7c98502bdb99e216ff2e6
6
+ metadata.gz: d2916426cb9edf9420f261434a08b198a40728d7703cc84604864fe40f8e9196d61250f37aead98ec2f7346a24d2213d915d1a513edcfc717209eda25ccffdbb
7
+ data.tar.gz: 755554a542c19da1c49c7f40ff12ed8b9021c12606c6f48ac8a25b15bd07fb0ac85c396f4974b32c3f2fbd7e459b30ca169139139e60d546473fc8085e2d088a
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">0.8.1</b>
8
+ * mustache.js - <b id="mustache-js-version">0.8.2</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 = "0.0.7"
2
+ VERSION = "0.0.9"
3
3
  end
@@ -5,32 +5,16 @@
5
5
 
6
6
  /*global define: false*/
7
7
 
8
- (function (root, factory) {
8
+ (function (global, factory) {
9
9
  if (typeof exports === "object" && exports) {
10
10
  factory(exports); // CommonJS
11
+ } else if (typeof define === "function" && define.amd) {
12
+ define(['exports'], factory); // AMD
11
13
  } else {
12
- var mustache = {};
13
- factory(mustache);
14
- if (typeof define === "function" && define.amd) {
15
- define(mustache); // AMD
16
- } else {
17
- root.Mustache = mustache; // <script>
18
- }
14
+ factory(global.Mustache = {}); // <script>
19
15
  }
20
16
  }(this, function (mustache) {
21
17
 
22
- // Workaround for https://issues.apache.org/jira/browse/COUCHDB-577
23
- // See https://github.com/janl/mustache.js/issues/189
24
- var RegExp_test = RegExp.prototype.test;
25
- function testRegExp(re, string) {
26
- return RegExp_test.call(re, string);
27
- }
28
-
29
- var nonSpaceRe = /\S/;
30
- function isWhitespace(string) {
31
- return !testRegExp(nonSpaceRe, string);
32
- }
33
-
34
18
  var Object_toString = Object.prototype.toString;
35
19
  var isArray = Array.isArray || function (object) {
36
20
  return Object_toString.call(object) === '[object Array]';
@@ -44,6 +28,18 @@
44
28
  return string.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&");
45
29
  }
46
30
 
31
+ // Workaround for https://issues.apache.org/jira/browse/COUCHDB-577
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);
36
+ }
37
+
38
+ var nonSpaceRe = /\S/;
39
+ function isWhitespace(string) {
40
+ return !testRegExp(nonSpaceRe, string);
41
+ }
42
+
47
43
  var entityMap = {
48
44
  "&": "&amp;",
49
45
  "<": "&lt;",
@@ -59,17 +55,6 @@
59
55
  });
60
56
  }
61
57
 
62
- function escapeTags(tags) {
63
- if (!isArray(tags) || tags.length !== 2) {
64
- throw new Error('Invalid tags: ' + tags);
65
- }
66
-
67
- return [
68
- new RegExp(escapeRegExp(tags[0]) + "\\s*"),
69
- new RegExp("\\s*" + escapeRegExp(tags[1]))
70
- ];
71
- }
72
-
73
58
  var whiteRe = /\s*/;
74
59
  var spaceRe = /\s+/;
75
60
  var equalsRe = /\s*=/;
@@ -99,15 +84,8 @@
99
84
  * which the closing tag for that section begins.
100
85
  */
101
86
  function parseTemplate(template, tags) {
102
- tags = tags || mustache.tags;
103
- template = template || '';
104
-
105
- if (typeof tags === 'string') {
106
- tags = tags.split(spaceRe);
107
- }
108
-
109
- var tagRes = escapeTags(tags);
110
- var scanner = new Scanner(template);
87
+ if (!template)
88
+ return [];
111
89
 
112
90
  var sections = []; // Stack to hold section tokens
113
91
  var tokens = []; // Buffer to hold the tokens
@@ -119,9 +97,8 @@
119
97
  // if there was a {{#tag}} on it and otherwise only space.
120
98
  function stripSpace() {
121
99
  if (hasTag && !nonSpace) {
122
- while (spaces.length) {
100
+ while (spaces.length)
123
101
  delete tokens[spaces.pop()];
124
- }
125
102
  } else {
126
103
  spaces = [];
127
104
  }
@@ -130,14 +107,32 @@
130
107
  nonSpace = false;
131
108
  }
132
109
 
110
+ var openingTagRe, closingTagRe, closingCurlyRe;
111
+ function compileTags(tags) {
112
+ if (typeof tags === 'string')
113
+ tags = tags.split(spaceRe, 2);
114
+
115
+ if (!isArray(tags) || tags.length !== 2)
116
+ throw new Error('Invalid tags: ' + tags);
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]));
121
+ }
122
+
123
+ compileTags(tags || mustache.tags);
124
+
125
+ var scanner = new Scanner(template);
126
+
133
127
  var start, type, value, chr, token, openSection;
134
128
  while (!scanner.eos()) {
135
129
  start = scanner.pos;
136
130
 
137
131
  // Match any text between tags.
138
- value = scanner.scanUntil(tagRes[0]);
132
+ value = scanner.scanUntil(openingTagRe);
133
+
139
134
  if (value) {
140
- for (var i = 0, len = value.length; i < len; ++i) {
135
+ for (var i = 0, valueLength = value.length; i < valueLength; ++i) {
141
136
  chr = value.charAt(i);
142
137
 
143
138
  if (isWhitespace(chr)) {
@@ -146,18 +141,19 @@
146
141
  nonSpace = true;
147
142
  }
148
143
 
149
- tokens.push(['text', chr, start, start + 1]);
144
+ tokens.push([ 'text', chr, start, start + 1 ]);
150
145
  start += 1;
151
146
 
152
147
  // Check for whitespace on the current line.
153
- if (chr === '\n') {
148
+ if (chr === '\n')
154
149
  stripSpace();
155
- }
156
150
  }
157
151
  }
158
152
 
159
153
  // Match the opening tag.
160
- if (!scanner.scan(tagRes[0])) break;
154
+ if (!scanner.scan(openingTagRe))
155
+ break;
156
+
161
157
  hasTag = true;
162
158
 
163
159
  // Get the tag type.
@@ -168,20 +164,19 @@
168
164
  if (type === '=') {
169
165
  value = scanner.scanUntil(equalsRe);
170
166
  scanner.scan(equalsRe);
171
- scanner.scanUntil(tagRes[1]);
167
+ scanner.scanUntil(closingTagRe);
172
168
  } else if (type === '{') {
173
- value = scanner.scanUntil(new RegExp('\\s*' + escapeRegExp('}' + tags[1])));
169
+ value = scanner.scanUntil(closingCurlyRe);
174
170
  scanner.scan(curlyRe);
175
- scanner.scanUntil(tagRes[1]);
171
+ scanner.scanUntil(closingTagRe);
176
172
  type = '&';
177
173
  } else {
178
- value = scanner.scanUntil(tagRes[1]);
174
+ value = scanner.scanUntil(closingTagRe);
179
175
  }
180
176
 
181
177
  // Match the closing tag.
182
- if (!scanner.scan(tagRes[1])) {
178
+ if (!scanner.scan(closingTagRe))
183
179
  throw new Error('Unclosed tag at ' + scanner.pos);
184
- }
185
180
 
186
181
  token = [ type, value, start, scanner.pos ];
187
182
  tokens.push(token);
@@ -192,25 +187,24 @@
192
187
  // Check section nesting.
193
188
  openSection = sections.pop();
194
189
 
195
- if (!openSection) {
190
+ if (!openSection)
196
191
  throw new Error('Unopened section "' + value + '" at ' + start);
197
- }
198
- if (openSection[1] !== value) {
192
+
193
+ if (openSection[1] !== value)
199
194
  throw new Error('Unclosed section "' + openSection[1] + '" at ' + start);
200
- }
201
195
  } else if (type === 'name' || type === '{' || type === '&') {
202
196
  nonSpace = true;
203
197
  } else if (type === '=') {
204
198
  // Set the tags for the next time around.
205
- tagRes = escapeTags(tags = value.split(spaceRe));
199
+ compileTags(value);
206
200
  }
207
201
  }
208
202
 
209
203
  // Make sure there are no open sections when we're done.
210
204
  openSection = sections.pop();
211
- if (openSection) {
205
+
206
+ if (openSection)
212
207
  throw new Error('Unclosed section "' + openSection[1] + '" at ' + scanner.pos);
213
- }
214
208
 
215
209
  return nestTokens(squashTokens(tokens));
216
210
  }
@@ -223,7 +217,7 @@
223
217
  var squashedTokens = [];
224
218
 
225
219
  var token, lastToken;
226
- for (var i = 0, len = tokens.length; i < len; ++i) {
220
+ for (var i = 0, numTokens = tokens.length; i < numTokens; ++i) {
227
221
  token = tokens[i];
228
222
 
229
223
  if (token) {
@@ -252,7 +246,7 @@
252
246
  var sections = [];
253
247
 
254
248
  var token, section;
255
- for (var i = 0, len = tokens.length; i < len; ++i) {
249
+ for (var i = 0, numTokens = tokens.length; i < numTokens; ++i) {
256
250
  token = tokens[i];
257
251
 
258
252
  switch (token[0]) {
@@ -299,14 +293,15 @@
299
293
  Scanner.prototype.scan = function (re) {
300
294
  var match = this.tail.match(re);
301
295
 
302
- if (match && match.index === 0) {
303
- var string = match[0];
304
- this.tail = this.tail.substring(string.length);
305
- this.pos += string.length;
306
- return string;
307
- }
296
+ if (!match || match.index !== 0)
297
+ return '';
308
298
 
309
- return "";
299
+ var string = match[0];
300
+
301
+ this.tail = this.tail.substring(string.length);
302
+ this.pos += string.length;
303
+
304
+ return string;
310
305
  };
311
306
 
312
307
  /**
@@ -357,35 +352,37 @@
357
352
  * up the context hierarchy if the value is absent in this context's view.
358
353
  */
359
354
  Context.prototype.lookup = function (name) {
355
+ var cache = this.cache;
356
+
360
357
  var value;
361
- if (name in this.cache) {
362
- value = this.cache[name];
358
+ if (name in cache) {
359
+ value = cache[name];
363
360
  } else {
364
- var context = this;
361
+ var context = this, names, index;
365
362
 
366
363
  while (context) {
367
364
  if (name.indexOf('.') > 0) {
368
365
  value = context.view;
366
+ names = name.split('.');
367
+ index = 0;
369
368
 
370
- var names = name.split('.'), i = 0;
371
- while (value != null && i < names.length) {
372
- value = value[names[i++]];
373
- }
369
+ while (value != null && index < names.length)
370
+ value = value[names[index++]];
374
371
  } else {
375
372
  value = context.view[name];
376
373
  }
377
374
 
378
- if (value != null) break;
375
+ if (value != null)
376
+ break;
379
377
 
380
378
  context = context.parent;
381
379
  }
382
380
 
383
- this.cache[name] = value;
381
+ cache[name] = value;
384
382
  }
385
383
 
386
- if (isFunction(value)) {
384
+ if (isFunction(value))
387
385
  value = value.call(this.view);
388
- }
389
386
 
390
387
  return value;
391
388
  };
@@ -414,9 +411,8 @@
414
411
  var cache = this.cache;
415
412
  var tokens = cache[template];
416
413
 
417
- if (tokens == null) {
414
+ if (tokens == null)
418
415
  tokens = cache[template] = parseTemplate(template, tags);
419
- }
420
416
 
421
417
  return tokens;
422
418
  };
@@ -456,29 +452,31 @@
456
452
  }
457
453
 
458
454
  var token, value;
459
- for (var i = 0, len = tokens.length; i < len; ++i) {
455
+ for (var i = 0, numTokens = tokens.length; i < numTokens; ++i) {
460
456
  token = tokens[i];
461
457
 
462
458
  switch (token[0]) {
463
459
  case '#':
464
460
  value = context.lookup(token[1]);
465
- if (!value) continue;
461
+
462
+ if (!value)
463
+ continue;
466
464
 
467
465
  if (isArray(value)) {
468
- for (var j = 0, jlen = value.length; j < jlen; ++j) {
466
+ for (var j = 0, valueLength = value.length; j < valueLength; ++j) {
469
467
  buffer += this.renderTokens(token[4], context.push(value[j]), partials, originalTemplate);
470
468
  }
471
469
  } else if (typeof value === 'object' || typeof value === 'string') {
472
470
  buffer += this.renderTokens(token[4], context.push(value), partials, originalTemplate);
473
471
  } else if (isFunction(value)) {
474
- if (typeof originalTemplate !== 'string') {
472
+ if (typeof originalTemplate !== 'string')
475
473
  throw new Error('Cannot use higher-order sections without the original template');
476
- }
477
474
 
478
475
  // Extract the portion of the original template that the section contains.
479
476
  value = value.call(context.view, originalTemplate.slice(token[3], token[5]), subRender);
480
477
 
481
- if (value != null) buffer += value;
478
+ if (value != null)
479
+ buffer += value;
482
480
  } else {
483
481
  buffer += this.renderTokens(token[4], context, partials, originalTemplate);
484
482
  }
@@ -489,23 +487,33 @@
489
487
 
490
488
  // Use JavaScript's definition of falsy. Include empty arrays.
491
489
  // See https://github.com/janl/mustache.js/issues/186
492
- if (!value || (isArray(value) && value.length === 0)) {
490
+ if (!value || (isArray(value) && value.length === 0))
493
491
  buffer += this.renderTokens(token[4], context, partials, originalTemplate);
494
- }
495
492
 
496
493
  break;
497
494
  case '>':
498
- if (!partials) continue;
495
+ if (!partials)
496
+ continue;
497
+
499
498
  value = isFunction(partials) ? partials(token[1]) : partials[token[1]];
500
- if (value != null) buffer += this.renderTokens(this.parse(value), context, partials, value);
499
+
500
+ if (value != null)
501
+ buffer += this.renderTokens(this.parse(value), context, partials, value);
502
+
501
503
  break;
502
504
  case '&':
503
505
  value = context.lookup(token[1]);
504
- if (value != null) buffer += value;
506
+
507
+ if (value != null)
508
+ buffer += value;
509
+
505
510
  break;
506
511
  case 'name':
507
512
  value = context.lookup(token[1]);
508
- if (value != null) buffer += mustache.escape(value);
513
+
514
+ if (value != null)
515
+ buffer += mustache.escape(value);
516
+
509
517
  break;
510
518
  case 'text':
511
519
  buffer += token[1];
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: 0.0.7
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Krzysztof Knapik
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-12 00:00:00.000000000 Z
11
+ date: 2014-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -17,6 +17,9 @@ dependencies:
17
17
  - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.1'
20
+ - - <=
21
+ - !ruby/object:Gem::Version
22
+ version: '5.0'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -24,8 +27,11 @@ dependencies:
24
27
  - - '>='
25
28
  - !ruby/object:Gem::Version
26
29
  version: '3.1'
27
- description: "\n mustache.js (https://github.com/janl/mustache.js) \n and jQuery.mustache.js
28
- (https://github.com/jonnyreeves/jquery-Mustache) \n for Rails 3.1+ asset pipeline\n
30
+ - - <=
31
+ - !ruby/object:Gem::Version
32
+ version: '5.0'
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
29
35
  \ "
30
36
  email:
31
37
  - knapo@knapo.net