Permalink
Browse files

Merge branch 'comments'

  • Loading branch information...
2 parents dc99fea + bc1d8f9 commit a95a377baeff1d77b9d452266ba4766931e78d9b Tj Holowaychuk committed Aug 4, 2010
Showing with 60 additions and 0 deletions.
  1. +15 −0 Readme.md
  2. +17 −0 lib/jade.js
  3. +28 −0 test/jade.test.js
View
@@ -141,6 +141,21 @@ Actually want `#{}` for some reason? escape it!
now we have `<p>#{something}</p>`
+### Comments
+
+Single line comments currently look the same as JavaScript comments,
+aka "//" and must be placed on their own line:
+
+ // just some paragraphs
+ p foo
+ p bar
+
+would output
+
+ <!-- just some paragraphs -->
+ <p>foo</p>
+ <p>bar</p>
+
### Nesting
ul
View
@@ -205,6 +205,11 @@ Parser.prototype = {
}
}
+ // Comment
+ if (captures = /^\/\/([^\n]+)/.exec(this.input)) {
+ return token('comment');
+ }
+
// Tag
if (captures = /^(\w[:\w]*)/.exec(this.input)) {
return token('tag');
@@ -378,6 +383,7 @@ Parser.prototype = {
* | text
* | filter
* | doctype
+ * | comment
* | each block
* | code block?
* | expr newline
@@ -391,6 +397,8 @@ Parser.prototype = {
return this.parseDoctype();
case 'filter':
return this.parseFilter();
+ case 'comment':
+ return this.parseComment();
case 'text':
return "buf.push('" + interpolate(this.advance.val.replace(/'/g, "\\'")) + " ');";
case 'id':
@@ -423,6 +431,15 @@ Parser.prototype = {
},
/**
+ * comment
+ */
+
+ parseComment: function(){
+ var str = this.expect('comment').val;
+ return "buf.push('<!--" + str + " -->')";
+ },
+
+ /**
* doctype
*/
View
@@ -419,6 +419,34 @@ module.exports = {
assert.equal('<p class="user-1"></p>', render('p(class: "user-" + 1)'));
},
+ 'test comments': function(assert){
+ var str = [
+ '// foo',
+ 'p bar'
+ ].join('\n');
+
+ var html = [
+ '<!-- foo -->',
+ '<p>bar</p>'
+ ].join('');
+
+ assert.equal(html, render(str));
+
+ var str = [
+ 'p foo',
+ '// bar',
+ 'p baz'
+ ].join('\n');
+
+ var html = [
+ '<p>foo</p>',
+ '<!-- bar -->',
+ '<p>baz</p>'
+ ].join('');
+
+ assert.equal(html, render(str));
+ },
+
'test code': function(assert){
var str = [
'- var foo = "<script>";',

0 comments on commit a95a377

Please sign in to comment.