jade-js-source 0.16.2 → 0.17.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.
Files changed (2) hide show
  1. data/lib/jade_js/jade.js +211 -11
  2. metadata +5 -3
data/lib/jade_js/jade.js CHANGED
@@ -71,7 +71,7 @@ var nodes = require('./nodes')
71
71
  var arr = [];
72
72
  for (var key in obj) {
73
73
  if (obj.hasOwnProperty(key)) {
74
- arr.push(obj);
74
+ arr.push(key);
75
75
  }
76
76
  }
77
77
  return arr;
@@ -205,6 +205,39 @@ Compiler.prototype = {
205
205
  return this['visit' + name](node);
206
206
  },
207
207
 
208
+ /**
209
+ * Visit case `node`.
210
+ *
211
+ * @param {Literal} node
212
+ * @api public
213
+ */
214
+
215
+ visitCase: function(node){
216
+ var _ = this.withinCase;
217
+ this.withinCase = true;
218
+ this.buf.push('switch (' + node.expr + '){');
219
+ this.visit(node.block);
220
+ this.buf.push('}');
221
+ this.withinCase = _;
222
+ },
223
+
224
+ /**
225
+ * Visit when `node`.
226
+ *
227
+ * @param {Literal} node
228
+ * @api public
229
+ */
230
+
231
+ visitWhen: function(node){
232
+ if ('default' == node.expr) {
233
+ this.buf.push('default:');
234
+ } else {
235
+ this.buf.push('case ' + node.expr + ':');
236
+ }
237
+ this.visit(node.block);
238
+ this.buf.push(' break;');
239
+ },
240
+
208
241
  /**
209
242
  * Visit literal `node`.
210
243
  *
@@ -386,8 +419,8 @@ Compiler.prototype = {
386
419
 
387
420
  visitBlockComment: function(comment){
388
421
  if (!comment.buffer) return;
389
- if (0 == comment.val.indexOf('if')) {
390
- this.buffer('<!--[' + comment.val + ']>');
422
+ if (0 == comment.val.trim().indexOf('if')) {
423
+ this.buffer('<!--[' + comment.val.trim() + ']>');
391
424
  this.visit(comment.block);
392
425
  this.buffer('<![endif]-->');
393
426
  } else {
@@ -681,7 +714,7 @@ var Parser = require('./parser')
681
714
  * Library version.
682
715
  */
683
716
 
684
- exports.version = '0.16.1';
717
+ exports.version = '0.17.0';
685
718
 
686
719
  /**
687
720
  * Expose self closing tags.
@@ -863,6 +896,36 @@ exports.render = function(str, options, fn){
863
896
  fn(err);
864
897
  }
865
898
  };
899
+
900
+ /**
901
+ * Render a Jade file at the given `path` and callback `fn(err, str)`.
902
+ *
903
+ * @param {String} path
904
+ * @param {Object|Function} options or callback
905
+ * @param {Function} fn
906
+ * @api public
907
+ */
908
+
909
+ exports.renderFile = function(path, options, fn){
910
+ var key = path + ':string';
911
+
912
+ if ('function' == typeof options) {
913
+ fn = options, options = {};
914
+ }
915
+
916
+ options.filename = path;
917
+ var str = options.cache
918
+ ? exports.cache[key] || (exports.cache[key] = fs.readFileSync(path, 'utf8'))
919
+ : fs.readFileSync(path, 'utf8');
920
+
921
+ exports.render(str, options, fn);
922
+ };
923
+
924
+ /**
925
+ * Express support.
926
+ */
927
+
928
+ exports.__express = exports.renderFile;
866
929
  }); // module: jade.js
867
930
 
868
931
  require.register("lexer.js", function(module, exports, require){
@@ -1132,17 +1195,41 @@ Lexer.prototype = {
1132
1195
  return this.scan(/^include +([^\n]+)/, 'include');
1133
1196
  },
1134
1197
 
1198
+ /**
1199
+ * Case.
1200
+ */
1201
+
1202
+ case: function() {
1203
+ return this.scan(/^case +([^\n]+)/, 'case');
1204
+ },
1205
+
1206
+ /**
1207
+ * When.
1208
+ */
1209
+
1210
+ when: function() {
1211
+ return this.scan(/^when +([^:\n]+)/, 'when');
1212
+ },
1213
+
1214
+ /**
1215
+ * Default.
1216
+ */
1217
+
1218
+ default: function() {
1219
+ return this.scan(/^default */, 'default');
1220
+ },
1221
+
1135
1222
  /**
1136
1223
  * Assignment.
1137
1224
  */
1138
1225
 
1139
1226
  assignment: function() {
1140
1227
  var captures;
1141
- if (captures = /^(\w+) += *([^\n]+)/.exec(this.input)) {
1228
+ if (captures = /^(\w+) += *([^;\n]+)( *;? *)/.exec(this.input)) {
1142
1229
  this.consume(captures[0].length);
1143
1230
  var name = captures[1]
1144
1231
  , val = captures[2];
1145
- return this.tok('code', 'var ' + name + ' = (' + val + ')');
1232
+ return this.tok('code', 'var ' + name + ' = (' + val + ');');
1146
1233
  }
1147
1234
  },
1148
1235
 
@@ -1152,7 +1239,7 @@ Lexer.prototype = {
1152
1239
 
1153
1240
  mixin: function(){
1154
1241
  var captures;
1155
- if (captures = /^mixin +([-\w]+)(?:\(([^\)]+)\))?/.exec(this.input)) {
1242
+ if (captures = /^mixin +([-\w]+)(?:\((.*)\))?/.exec(this.input)) {
1156
1243
  this.consume(captures[0].length);
1157
1244
  var tok = this.tok('mixin', captures[1]);
1158
1245
  tok.args = captures[2];
@@ -1475,6 +1562,9 @@ Lexer.prototype = {
1475
1562
  || this.eos()
1476
1563
  || this.pipelessText()
1477
1564
  || this.doctype()
1565
+ || this.case()
1566
+ || this.when()
1567
+ || this.default()
1478
1568
  || this.extends()
1479
1569
  || this.block()
1480
1570
  || this.include()
@@ -1638,6 +1728,57 @@ Block.prototype.lastBlock = function(){
1638
1728
 
1639
1729
  }); // module: nodes/block.js
1640
1730
 
1731
+ require.register("nodes/case.js", function(module, exports, require){
1732
+
1733
+ /*!
1734
+ * Jade - nodes - Case
1735
+ * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
1736
+ * MIT Licensed
1737
+ */
1738
+
1739
+ /**
1740
+ * Module dependencies.
1741
+ */
1742
+
1743
+ var Node = require('./node');
1744
+
1745
+ /**
1746
+ * Initialize a new `Case` with `expr`.
1747
+ *
1748
+ * @param {String} expr
1749
+ * @api public
1750
+ */
1751
+
1752
+ var Case = exports = module.exports = function Case(expr, block){
1753
+ this.expr = expr;
1754
+ this.block = block;
1755
+ };
1756
+
1757
+ /**
1758
+ * Inherit from `Node`.
1759
+ */
1760
+
1761
+ Case.prototype = new Node;
1762
+ Case.prototype.constructor = Case;
1763
+
1764
+
1765
+ var When = exports.When = function When(expr, block){
1766
+ this.expr = expr;
1767
+ this.block = block;
1768
+ this.debug = false;
1769
+ };
1770
+
1771
+ /**
1772
+ * Inherit from `Node`.
1773
+ */
1774
+
1775
+ When.prototype = new Node;
1776
+ When.prototype.constructor = When;
1777
+
1778
+
1779
+
1780
+ }); // module: nodes/case.js
1781
+
1641
1782
  require.register("nodes/code.js", function(module, exports, require){
1642
1783
 
1643
1784
  /*!
@@ -1841,6 +1982,7 @@ exports.Node = require('./node');
1841
1982
  exports.Tag = require('./tag');
1842
1983
  exports.Code = require('./code');
1843
1984
  exports.Each = require('./each');
1985
+ exports.Case = require('./case');
1844
1986
  exports.Text = require('./text');
1845
1987
  exports.Block = require('./block');
1846
1988
  exports.Mixin = require('./mixin');
@@ -1874,7 +2016,9 @@ var Node = require('./node');
1874
2016
  */
1875
2017
 
1876
2018
  var Literal = module.exports = function Literal(str) {
1877
- this.str = str;
2019
+ this.str = str
2020
+ .replace(/\n/g, "\\n")
2021
+ .replace(/'/g, "\\'");
1878
2022
  };
1879
2023
 
1880
2024
  /**
@@ -2271,6 +2415,12 @@ Parser.prototype = {
2271
2415
  return this.parseMixin();
2272
2416
  case 'block':
2273
2417
  return this.parseBlock();
2418
+ case 'case':
2419
+ return this.parseCase();
2420
+ case 'when':
2421
+ return this.parseWhen();
2422
+ case 'default':
2423
+ return this.parseDefault();
2274
2424
  case 'extends':
2275
2425
  return this.parseExtends();
2276
2426
  case 'include':
@@ -2308,7 +2458,51 @@ Parser.prototype = {
2308
2458
  node.line = this.line();
2309
2459
  return node;
2310
2460
  },
2461
+
2462
+ /**
2463
+ * ':' expr
2464
+ * | block
2465
+ */
2466
+
2467
+ parseBlockExpansion: function(){
2468
+ if (':' == this.peek().type) {
2469
+ this.advance();
2470
+ return new nodes.Block(this.parseExpr());
2471
+ } else {
2472
+ return this.block();
2473
+ }
2474
+ },
2475
+
2476
+ /**
2477
+ * case
2478
+ */
2479
+
2480
+ parseCase: function(){
2481
+ var val = this.expect('case').val
2482
+ , node = new nodes.Case(val);
2483
+ node.line = this.line();
2484
+ node.block = this.block();
2485
+ return node;
2486
+ },
2487
+
2488
+ /**
2489
+ * when
2490
+ */
2491
+
2492
+ parseWhen: function(){
2493
+ var val = this.expect('when').val
2494
+ return new nodes.Case.When(val, this.parseBlockExpansion());
2495
+ },
2311
2496
 
2497
+ /**
2498
+ * default
2499
+ */
2500
+
2501
+ parseDefault: function(){
2502
+ this.expect('default');
2503
+ return new nodes.Case.When('default', this.parseBlockExpansion());
2504
+ },
2505
+
2312
2506
  /**
2313
2507
  * code
2314
2508
  */
@@ -2398,8 +2592,9 @@ Parser.prototype = {
2398
2592
 
2399
2593
  parseEach: function(){
2400
2594
  var tok = this.expect('each')
2401
- , node = new nodes.Each(tok.code, tok.val, tok.key, this.block());
2595
+ , node = new nodes.Each(tok.code, tok.val, tok.key);
2402
2596
  node.line = this.line();
2597
+ node.block = this.block();
2403
2598
  return node;
2404
2599
  },
2405
2600
 
@@ -2461,14 +2656,19 @@ Parser.prototype = {
2461
2656
  if (!this.filename)
2462
2657
  throw new Error('the "filename" option is required to use includes');
2463
2658
 
2659
+ // no extension
2660
+ if (!~basename(path).indexOf('.')) {
2661
+ path += '.jade';
2662
+ }
2663
+
2464
2664
  // non-jade
2465
- if (~basename(path).indexOf('.')) {
2665
+ if ('.jade' != path.substr(-5)) {
2466
2666
  var path = join(dir, path)
2467
2667
  , str = fs.readFileSync(path, 'utf8');
2468
2668
  return new nodes.Literal(str);
2469
2669
  }
2470
2670
 
2471
- var path = join(dir, path + '.jade')
2671
+ var path = join(dir, path)
2472
2672
  , str = fs.readFileSync(path, 'utf8')
2473
2673
  , parser = new Parser(str, path, this.options);
2474
2674
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jade-js-source
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.2
4
+ version: 0.17.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,8 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-10-07 00:00:00.000000000Z
13
+ date: 2011-11-16 00:00:00.000000000 -05:00
14
+ default_executable:
14
15
  dependencies: []
15
16
  description: ! " Jade is a high performance template engine heavily influenced
16
17
  by Haml \n and implemented with JavaScript for node.\n"
@@ -22,6 +23,7 @@ files:
22
23
  - lib/jade_js/jade.js
23
24
  - lib/jade_js/runtime.js
24
25
  - lib/jade_js/source.rb
26
+ has_rdoc: true
25
27
  homepage: https://github.com/visionmedia/jade
26
28
  licenses: []
27
29
  post_install_message:
@@ -42,7 +44,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
42
44
  version: '0'
43
45
  requirements: []
44
46
  rubyforge_project: jade-js-source
45
- rubygems_version: 1.8.10
47
+ rubygems_version: 1.6.2
46
48
  signing_key:
47
49
  specification_version: 3
48
50
  summary: Jade - template engine