Skip to content

Commit

Permalink
Merge branch 'features/block-comment'
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Mar 4, 2011
2 parents 7cb7ac3 + a524ef1 commit 33333d0
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 1 deletion.
20 changes: 20 additions & 0 deletions Readme.md
Expand Up @@ -17,6 +17,7 @@
- parse tree manipulation via _filters_
- supports [Express JS](http://expressjs.com) out of the box
- transparent iteration over objects, arrays, and even non-enumerables via `- each`
- block comments
- no tag prefix
- filters
- :sass must have [sass.js](http://github.com/visionmedia/sass.js) installed
Expand Down Expand Up @@ -184,6 +185,25 @@ outputting
<p>foo</p>
<p>bar</p>

### Block Comments

A block comment is the `/` character followed by a block.

body
/
#content
h1 Example

outputting

<body>
<!--
<div id="content">
<h1>Example</h1>
</div>
-->
</body>

### Nesting

ul
Expand Down
13 changes: 13 additions & 0 deletions lib/compiler.js
Expand Up @@ -198,6 +198,19 @@ Compiler.prototype = {
this.buffer('<!--' + utils.escape(comment.val) + '-->');
},

/**
* Visit a `BlockComment`.
*
* @param {Comment} comment
* @api public
*/

visitBlockComment: function(comment){
this.buffer('<!--');
this.visit(comment.block);
this.buffer('-->');
},

/**
* Visit `code`, respecting buffer / escape flags.
* If the code is followed by a block, wrap it in
Expand Down
16 changes: 15 additions & 1 deletion lib/lexer.js
Expand Up @@ -151,6 +151,19 @@ Lexer.prototype = {
? this.tok('outdent')
: this.tok('eos');
},

/**
* Block comment
*/

get blockComment() {
var captures;
if (captures = /^\//.exec(this.input)) {
this.consume(1);
var tok = this.tok('block-comment');
return tok;
}
},

/**
* Comment.
Expand All @@ -161,7 +174,7 @@ Lexer.prototype = {
if (captures = /^ *\/\/(-)?([^\n]+)/.exec(this.input)) {
this.consume(captures[0].length);
var tok = this.tok('comment', captures[2]);
tok.buffer = captures[1] !== '-';
tok.buffer = '-' != captures[1];
return tok;
}
},
Expand Down Expand Up @@ -354,6 +367,7 @@ Lexer.prototype = {
|| this.attrs
|| this.indent
|| this.comment
|| this.blockComment
|| this.text;
}
};
29 changes: 29 additions & 0 deletions lib/nodes/block-comment.js
@@ -0,0 +1,29 @@

/*!
* Jade - nodes - BlockComment
* Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
* MIT Licensed
*/

/**
* Module dependencies.
*/

var Node = require('./node');

/**
* Initialize a `BlockComment` with the given `block`.
*
* @param {Block} block
* @api public
*/

var BlockComment = module.exports = function BlockComment(block) {
this.block = block;
};

/**
* Inherit from `Node`.
*/

BlockComment.prototype.__proto__ = Node.prototype;
1 change: 1 addition & 0 deletions lib/nodes/index.js
Expand Up @@ -13,4 +13,5 @@ exports.Text = require('./text');
exports.Block = require('./block');
exports.Filter = require('./filter');
exports.Comment = require('./comment');
exports.BlockComment = require('./block-comment');
exports.Doctype = require('./doctype');
16 changes: 16 additions & 0 deletions lib/parser.js
Expand Up @@ -161,6 +161,8 @@ Parser.prototype = {
return this.parseFilter();
case 'comment':
return this.parseComment();
case 'block-comment':
return this.parseBlockComment();
case 'text':
return this.parseText();
case 'each':
Expand All @@ -173,6 +175,8 @@ Parser.prototype = {
this.lexer.defer(this.lexer.tok('tag', 'div'));
this.lexer.defer(tok);
return this.parseExpr();
default:
throw new Error('unexpected token "' + this.peek.type + '"');
}
},

Expand Down Expand Up @@ -200,6 +204,18 @@ Parser.prototype = {
}
return node;
},

/**
* block comment
*/

parseBlockComment: function(){
var tok = this.expect('block-comment')
, node = new nodes.BlockComment(this.parseBlock());
node.line = this.line;
return node;
},


/**
* comment
Expand Down

0 comments on commit 33333d0

Please sign in to comment.