Permalink
Browse files

Adding Haml comments and HTML comments!

  • Loading branch information...
1 parent 23e2260 commit d1b5f7d4c81e70fc1d74b47facd2ad412a347908 @aaronblohowiak aaronblohowiak committed May 7, 2011
Showing with 46 additions and 3 deletions.
  1. +9 −2 README.markdown
  2. +20 −0 lib/haml.js
  3. +14 −0 test/comments.haml
  4. +2 −0 test/comments.html
  5. +1 −1 test/raw_complex.html
View
@@ -157,13 +157,20 @@ Please see test/raw_complex.haml for more details and examples.
## Comments
-Just use the new Executable blocks with JavaScript comments.
+Comments that will **not** appear in the compiled JS function nor the output begin with `-#`
+
+ -# This is a comment
+ - # This is a syntax error because of the extraneous space between the - and #.
+
+If you want to have comments that will be in the compiled JS function but *NOT* the final HTML output:
- /*
here we can have a comment that will not be output. Since executable-JS is block-level,
we can have as much comment as we want, and it will not be output to html */
-These comments **will** appear in the source of the function returned by Haml.compile, but will not appear as html comments. If you precompile your templates and share them with the browser, then your minifier should strip out comments for you.
+If you want an HTML comment that **WILL** be in the final HTML, begin with `/`
+
+
## Code interpolation
View
@@ -272,6 +272,26 @@ var Haml;
}
},
+ // silent-comments
+ {
+ name: "silent-comments",
+ regexp: /^(\s*)-#\s*(.*)\s*$/i,
+ process: function () {
+ return '""';
+ }
+ },
+
+ //html-comments
+ {
+ name: "silent-comments",
+ regexp: /^(\s*)\/\s*(.*)\s*$/i,
+ process: function () {
+ this.contents.unshift(this.matches[2]);
+
+ return '"<!--'+this.contents.join('\\n')+'-->"';
+ }
+ },
+
// raw js
{
name: "raw",
View
@@ -0,0 +1,14 @@
+-# should not be displayed
+.display-this
+-# will be hidden
+ Will also be hidden
+ So comments
+ Are block-level
+- var a=2
+=a
+-# Ensure that executable JS blocks still work
+- /* this will be in the compiled function,
+ but not in the final HTML
+ */
+/ This should be a Haml comment
+ and it should be in the resulting html
View
@@ -0,0 +1,2 @@
+<div class="display-this"></div>2<!--This should be a Haml comment
+and it should be in the resulting html-->
View
@@ -1 +1 @@
-<div>1</div><div>2</div><div>3</div><h1>Woah!</h1>2<br /><div class="count">1</div><div class="count">2</div><div class="item"><b>Hi</b><span class="length">2</span></div><div class="item"><b>World</b><span class="length">5</span></div>
+<div>1</div><div>2</div><div>3</div><h1>Woah!</h1>2<br /><div class="count">1</div><div class="count">2</div><div class="item"><b>Hi</b><span class="length">2</span></div><div class="item"><b>World</b><span class="length">5</span></div>

0 comments on commit d1b5f7d

Please sign in to comment.