Browse files

html: support [:html, :condcomment, ...]

  • Loading branch information...
1 parent 46cd26a commit e2809e5e02dc65bbb267f6cc748cd4e9106773d2 @minad minad committed Aug 23, 2012
Showing with 20 additions and 0 deletions.
  1. +1 −0 CHANGES
  2. +7 −0 EXPRESSIONS.md
  3. +1 −0 lib/temple/grammar.rb
  4. +4 −0 lib/temple/html/dispatcher.rb
  5. +7 −0 lib/temple/html/fast.rb
View
1 CHANGES
@@ -1,6 +1,7 @@
master
* Set tilt template default_mime_type to text/html
+ * HTML: Support conditional comments [:html, :condcomment, ...]
0.4.0
View
7 EXPRESSIONS.md
@@ -210,6 +210,13 @@ Example:
generates:
<!--comment-->
+### [:html, :condcomment, condition, sexp]
+
+Example:
+ [:html, :condcomment, 'IE', [:static, 'comment']]
+generates:
+ <!--[if IE]>comment<![endif]-->
+
### [:html, :tag, identifier, attributes, optional-sexp]
HTML tag abstraction. Identifier can be a String or a Symbol. If the optional content Sexp is omitted
View
1 lib/temple/grammar.rb
@@ -29,6 +29,7 @@ module Grammar
# HTML abstraction
[:html, :doctype, String] |
[:html, :comment, Expression] |
+ [:html, :condcomment, String, Expression]|
[:html, :tag, HTMLIdentifier, Expression, 'Expression?'] |
[:html, :attrs, 'HTMLAttr*'] |
HTMLAttr
View
4 lib/temple/html/dispatcher.rb
@@ -14,6 +14,10 @@ def on_html_comment(content)
[:html, :comment, compile(content)]
end
+ def on_html_condcomment(condition, content)
+ [:html, :condcomment, condition, compile(content)]
+ end
+
def on_html_tag(name, attrs, content = nil)
result = [:html, :tag, name, compile(attrs)]
content ? (result << compile(content)) : result
View
7 lib/temple/html/fast.rb
@@ -65,6 +65,13 @@ def on_html_comment(content)
[:static, '-->']]
end
+ def on_html_condcomment(condition, content)
+ on_html_comment [:multi,
+ [:static, "[#{condition}]>"],
+ content,
+ [:static, '<![endif]']]
+ end
+
def on_html_tag(name, attrs, content = nil)
name = name.to_s
closed = !content || (empty_exp?(content) && options[:autoclose].include?(name))

0 comments on commit e2809e5

Please sign in to comment.