Navigation Menu

Skip to content

Commit

Permalink
Added block comment support
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Mar 4, 2011
1 parent 916724a commit a524ef1
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 0 deletions.
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
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');
14 changes: 14 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 Down Expand Up @@ -202,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 a524ef1

Please sign in to comment.