Skip to content

Commit

Permalink
html: support [:html, :condcomment, ...]
Browse files Browse the repository at this point in the history
  • Loading branch information
minad committed Aug 23, 2012
1 parent 46cd26a commit e2809e5
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES
@@ -1,6 +1,7 @@
master master


* Set tilt template default_mime_type to text/html * Set tilt template default_mime_type to text/html
* HTML: Support conditional comments [:html, :condcomment, ...]


0.4.0 0.4.0


Expand Down
7 changes: 7 additions & 0 deletions EXPRESSIONS.md
Expand Up @@ -210,6 +210,13 @@ Example:
generates: generates:
<!--comment--> <!--comment-->


### [:html, :condcomment, condition, sexp]

Example:
[:html, :condcomment, 'IE', [:static, 'comment']]
generates:
<!--[if IE]>comment<![endif]-->

### [:html, :tag, identifier, attributes, optional-sexp] ### [:html, :tag, identifier, attributes, optional-sexp]


HTML tag abstraction. Identifier can be a String or a Symbol. If the optional content Sexp is omitted HTML tag abstraction. Identifier can be a String or a Symbol. If the optional content Sexp is omitted
Expand Down
1 change: 1 addition & 0 deletions lib/temple/grammar.rb
Expand Up @@ -29,6 +29,7 @@ module Grammar
# HTML abstraction # HTML abstraction
[:html, :doctype, String] | [:html, :doctype, String] |
[:html, :comment, Expression] | [:html, :comment, Expression] |
[:html, :condcomment, String, Expression]|
[:html, :tag, HTMLIdentifier, Expression, 'Expression?'] | [:html, :tag, HTMLIdentifier, Expression, 'Expression?'] |
[:html, :attrs, 'HTMLAttr*'] | [:html, :attrs, 'HTMLAttr*'] |
HTMLAttr HTMLAttr
Expand Down
4 changes: 4 additions & 0 deletions lib/temple/html/dispatcher.rb
Expand Up @@ -14,6 +14,10 @@ def on_html_comment(content)
[:html, :comment, compile(content)] [:html, :comment, compile(content)]
end end


def on_html_condcomment(condition, content)
[:html, :condcomment, condition, compile(content)]
end

def on_html_tag(name, attrs, content = nil) def on_html_tag(name, attrs, content = nil)
result = [:html, :tag, name, compile(attrs)] result = [:html, :tag, name, compile(attrs)]
content ? (result << compile(content)) : result content ? (result << compile(content)) : result
Expand Down
7 changes: 7 additions & 0 deletions lib/temple/html/fast.rb
Expand Up @@ -65,6 +65,13 @@ def on_html_comment(content)
[:static, '-->']] [:static, '-->']]
end 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) def on_html_tag(name, attrs, content = nil)
name = name.to_s name = name.to_s
closed = !content || (empty_exp?(content) && options[:autoclose].include?(name)) closed = !content || (empty_exp?(content) && options[:autoclose].include?(name))
Expand Down

0 comments on commit e2809e5

Please sign in to comment.