Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit e2809e5e02dc65bbb267f6cc748cd4e9106773d2 1 parent 46cd26a
Daniel Mendler minad authored
1  CHANGES
View
@@ -1,6 +1,7 @@
master
* Set tilt template default_mime_type to text/html
+ * HTML: Support conditional comments [:html, :condcomment, ...]
0.4.0
7 EXPRESSIONS.md
View
@@ -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
1  lib/temple/grammar.rb
View
@@ -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
4 lib/temple/html/dispatcher.rb
View
@@ -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
7 lib/temple/html/fast.rb
View
@@ -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))
Please sign in to comment.
Something went wrong with that request. Please try again.