mustachejs-rails 0.7.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 261849b7cde04e47f0e4cdb9f618c1983119eb29
4
+ data.tar.gz: 9c8df312fa1c187a99ff193c4c4ede273eca347a
5
+ SHA512:
6
+ metadata.gz: cd1c7cf447c12ebf8ec8bc0bb8850efd384bf7c5e25a61b9d55b2c2296301d6eb6a912a4c703e25c6f7912aaffe7052514be4cd8695bba794d3019855a96aa5e
7
+ data.tar.gz: 5c0919257f04c57544863c1353b456cff98f95c8fd5f5206b62b2d613e673a872ee97cf35195067db14ee66335a6baa561ba3f65486f3616291384769e7fcd26
@@ -1,5 +1,5 @@
1
1
  module Mustachejs
2
2
  module Rails
3
- VERSION = "0.7.1"
3
+ VERSION = "0.7.2"
4
4
  end
5
5
  end
@@ -16,4 +16,6 @@ Gem::Specification.new do |gem|
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ["lib"]
19
+
20
+ gem.add_development_dependency "rake"
19
21
  end
@@ -5,22 +5,20 @@
5
5
 
6
6
  /*global define: false*/
7
7
 
8
- var Mustache;
9
-
10
- (function (exports) {
11
- if (typeof module !== "undefined" && module.exports) {
12
- module.exports = exports; // CommonJS
13
- } else if (typeof define === "function") {
14
- define(exports); // AMD
8
+ (function (root, factory) {
9
+ if (typeof exports === "object" && exports) {
10
+ module.exports = factory; // CommonJS
11
+ } else if (typeof define === "function" && define.amd) {
12
+ define(factory); // AMD
15
13
  } else {
16
- Mustache = exports; // <script>
14
+ root.Mustache = factory; // <script>
17
15
  }
18
- }((function () {
16
+ }(this, (function () {
19
17
 
20
18
  var exports = {};
21
19
 
22
20
  exports.name = "mustache.js";
23
- exports.version = "0.7.1";
21
+ exports.version = "0.7.2";
24
22
  exports.tags = ["{{", "}}"];
25
23
 
26
24
  exports.Scanner = Scanner;
@@ -301,24 +299,6 @@ var Mustache;
301
299
  return exports.escape(this._name(name, context));
302
300
  };
303
301
 
304
- /**
305
- * Calculates the bounds of the section represented by the given `token` in
306
- * the original template by drilling down into nested sections to find the
307
- * last token that is part of that section. Returns an array of [start, end].
308
- */
309
- function sectionBounds(token) {
310
- var start = token[3];
311
- var end = start;
312
-
313
- var tokens;
314
- while ((tokens = token[4]) && tokens.length) {
315
- token = tokens[tokens.length - 1];
316
- end = token[3];
317
- }
318
-
319
- return [start, end];
320
- }
321
-
322
302
  /**
323
303
  * Low-level function that compiles the given `tokens` into a function
324
304
  * that accepts three arguments: a Writer, a Context, and the template.
@@ -346,7 +326,7 @@ var Mustache;
346
326
 
347
327
  switch (token[0]) {
348
328
  case "#":
349
- sectionText = template.slice.apply(template, sectionBounds(token));
329
+ sectionText = template.slice(token[3], token[5]);
350
330
  buffer += writer._section(token[1], context, sectionText, subRender(i, token[4], template));
351
331
  break;
352
332
  case "^":
@@ -373,55 +353,35 @@ var Mustache;
373
353
 
374
354
  /**
375
355
  * Forms the given array of `tokens` into a nested tree structure where
376
- * tokens that represent a section have a fifth item: an array that contains
377
- * all tokens in that section.
356
+ * tokens that represent a section have two additional items: 1) an array of
357
+ * all tokens that appear in that section and 2) the index in the original
358
+ * template that represents the end of that section.
378
359
  */
379
360
  function nestTokens(tokens) {
380
361
  var tree = [];
381
362
  var collector = tree;
382
363
  var sections = [];
383
- var token, section;
384
364
 
385
- for (var i = 0; i < tokens.length; ++i) {
365
+ var token;
366
+ for (var i = 0, len = tokens.length; i < len; ++i) {
386
367
  token = tokens[i];
387
-
388
368
  switch (token[0]) {
389
- case "#":
390
- case "^":
391
- token[4] = [];
369
+ case '#':
370
+ case '^':
392
371
  sections.push(token);
393
372
  collector.push(token);
394
- collector = token[4];
373
+ collector = token[4] = [];
395
374
  break;
396
- case "/":
397
- if (sections.length === 0) {
398
- throw new Error("Unopened section: " + token[1]);
399
- }
400
-
401
- section = sections.pop();
402
-
403
- if (section[1] !== token[1]) {
404
- throw new Error("Unclosed section: " + section[1]);
405
- }
406
-
407
- if (sections.length > 0) {
408
- collector = sections[sections.length - 1][4];
409
- } else {
410
- collector = tree;
411
- }
375
+ case '/':
376
+ var section = sections.pop();
377
+ section[5] = token[2];
378
+ collector = sections.length > 0 ? sections[sections.length - 1][4] : tree;
412
379
  break;
413
380
  default:
414
381
  collector.push(token);
415
382
  }
416
383
  }
417
384
 
418
- // Make sure there were no open sections when we're done.
419
- section = sections.pop();
420
-
421
- if (section) {
422
- throw new Error("Unclosed section: " + section[1]);
423
- }
424
-
425
385
  return tree;
426
386
  }
427
387
 
@@ -430,12 +390,12 @@ var Mustache;
430
390
  * to a single token.
431
391
  */
432
392
  function squashTokens(tokens) {
433
- var token, lastToken, squashedTokens = [];
393
+ var squashedTokens = [];
434
394
 
435
- for (var i = 0; i < tokens.length; ++i) {
395
+ var token, lastToken;
396
+ for (var i = 0, len = tokens.length; i < len; ++i) {
436
397
  token = tokens[i];
437
-
438
- if (lastToken && lastToken[0] === "text" && token[0] === "text") {
398
+ if (token[0] === 'text' && lastToken && lastToken[0] === 'text') {
439
399
  lastToken[1] += token[1];
440
400
  lastToken[3] = token[3];
441
401
  } else {
@@ -448,10 +408,6 @@ var Mustache;
448
408
  }
449
409
 
450
410
  function escapeTags(tags) {
451
- if (tags.length !== 2) {
452
- throw new Error("Invalid tags: " + tags.join(" "));
453
- }
454
-
455
411
  return [
456
412
  new RegExp(escapeRe(tags[0]) + "\\s*"),
457
413
  new RegExp("\\s*" + escapeRe(tags[1]))
@@ -468,13 +424,19 @@ var Mustache;
468
424
  template = template || '';
469
425
  tags = tags || exports.tags;
470
426
 
427
+ if (typeof tags === 'string') tags = tags.split(spaceRe);
428
+ if (tags.length !== 2) {
429
+ throw new Error('Invalid tags: ' + tags.join(', '));
430
+ }
431
+
471
432
  var tagRes = escapeTags(tags);
472
433
  var scanner = new Scanner(template);
473
434
 
474
- var tokens = [], // Buffer to hold the tokens
475
- spaces = [], // Indices of whitespace tokens on the current line
476
- hasTag = false, // Is there a {{tag}} on the current line?
477
- nonSpace = false; // Is there a non-space char on the current line?
435
+ var sections = []; // Stack to hold section tokens
436
+ var tokens = []; // Buffer to hold the tokens
437
+ var spaces = []; // Indices of whitespace tokens on the current line
438
+ var hasTag = false; // Is there a {{tag}} on the current line?
439
+ var nonSpace = false; // Is there a non-space char on the current line?
478
440
 
479
441
  // Strips all whitespace tokens array for the current line
480
442
  // if there was a {{#tag}} on it and otherwise only space.
@@ -492,7 +454,6 @@ var Mustache;
492
454
  }
493
455
 
494
456
  var start, type, value, chr;
495
-
496
457
  while (!scanner.eos()) {
497
458
  start = scanner.pos;
498
459
  value = scanner.scanUntil(tagRes[0]);
@@ -546,25 +507,48 @@ var Mustache;
546
507
 
547
508
  // Match the closing tag.
548
509
  if (!scanner.scan(tagRes[1])) {
549
- throw new Error("Unclosed tag at " + scanner.pos);
510
+ throw new Error('Unclosed tag at ' + scanner.pos);
550
511
  }
551
512
 
552
- tokens.push([type, value, start, scanner.pos]);
513
+ // Check section nesting.
514
+ if (type === '/') {
515
+ if (sections.length === 0) {
516
+ throw new Error('Unopened section "' + value + '" at ' + start);
517
+ }
553
518
 
554
- if (type === "name" || type === "{" || type === "&") {
555
- nonSpace = true;
519
+ var section = sections.pop();
520
+
521
+ if (section[1] !== value) {
522
+ throw new Error('Unclosed section "' + section[1] + '" at ' + start);
523
+ }
556
524
  }
557
525
 
558
- // Set the tags for the next time around.
559
- if (type === "=") {
526
+ var token = [type, value, start, scanner.pos];
527
+ tokens.push(token);
528
+
529
+ if (type === '#' || type === '^') {
530
+ sections.push(token);
531
+ } else if (type === "name" || type === "{" || type === "&") {
532
+ nonSpace = true;
533
+ } else if (type === "=") {
534
+ // Set the tags for the next time around.
560
535
  tags = value.split(spaceRe);
536
+
537
+ if (tags.length !== 2) {
538
+ throw new Error('Invalid tags at ' + start + ': ' + tags.join(', '));
539
+ }
540
+
561
541
  tagRes = escapeTags(tags);
562
542
  }
563
543
  }
564
544
 
565
- tokens = squashTokens(tokens);
545
+ // Make sure there are no open sections when we're done.
546
+ var section = sections.pop();
547
+ if (section) {
548
+ throw new Error('Unclosed section "' + section[1] + '" at ' + scanner.pos);
549
+ }
566
550
 
567
- return nestTokens(tokens);
551
+ return nestTokens(squashTokens(tokens));
568
552
  };
569
553
 
570
554
  // The high-level clearCache, compile, compilePartial, and render functions
metadata CHANGED
@@ -1,16 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mustachejs-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
5
- prerelease:
4
+ version: 0.7.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Simon COURTOIS
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-12-15 00:00:00.000000000 Z
13
- dependencies: []
11
+ date: 2013-11-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
14
27
  description: This gem provides mustache.js for your Rails 3 application.
15
28
  email:
16
29
  - scourtois@cubyx.fr
@@ -30,32 +43,25 @@ files:
30
43
  - vendor/assets/javascripts/mustache.js
31
44
  homepage: http://github.com/simonc/mustachejs-rails
32
45
  licenses: []
46
+ metadata: {}
33
47
  post_install_message:
34
48
  rdoc_options: []
35
49
  require_paths:
36
50
  - lib
37
51
  required_ruby_version: !ruby/object:Gem::Requirement
38
- none: false
39
52
  requirements:
40
- - - ! '>='
53
+ - - '>='
41
54
  - !ruby/object:Gem::Version
42
55
  version: '0'
43
- segments:
44
- - 0
45
- hash: -2278858652052863131
46
56
  required_rubygems_version: !ruby/object:Gem::Requirement
47
- none: false
48
57
  requirements:
49
- - - ! '>='
58
+ - - '>='
50
59
  - !ruby/object:Gem::Version
51
60
  version: '0'
52
- segments:
53
- - 0
54
- hash: -2278858652052863131
55
61
  requirements: []
56
62
  rubyforge_project:
57
- rubygems_version: 1.8.23
63
+ rubygems_version: 2.1.0
58
64
  signing_key:
59
- specification_version: 3
65
+ specification_version: 4
60
66
  summary: Use mustache.js with Rails 3
61
67
  test_files: []