Browse files

Removed self-closing tags in separate collection, fixed format_attrs.

  • Loading branch information...
1 parent 54e1312 commit 8ddd15c9131b8b89c862b6cf972f0a0acbc915b0 Roel van Dijk committed Mar 29, 2011
Showing with 20 additions and 10 deletions.
  1. +20 −10 lib/jrb/helpers/html.rb
30 lib/jrb/helpers/html.rb
@@ -1,21 +1,31 @@
module JRB
module HTML
- ELEMENTS = %w{a abbr address area article aside audio b base bdi bdo
- blockquote body br button canvas caption cite code col colgroup command
+ ELEMENTS = %w{a abbr address article aside audio b bdi bdo
+ blockquote body canvas caption cite code colgroup command
datalist dd del details dfn div dl dt em embed fieldset figcaption
- figure footer form h1 h2 h3 h4 h5 h6 head header hgroup hr html i iframe
- img input ins kbd keygen label legend li link map mark menu meta meter
- nav noscript object ol optgroup option output p param pre progress q rp
+ figure footer form h1 h2 h3 h4 h5 h6 head header hgroup html i iframe
+ ins kbd keygen legend li map mark menu meter
+ nav noscript ol optgroup option output p pre progress q rp
rt ruby s samp script section select small source span strong style sub
summary sup table tbody td textarea tfoot th thead time title tr track
- ul var video wbr}
+ ul var video wbr} #label object button
+ SELF_CLOSING = %w{area base br col hr img link meta param} # input
ELEMENTS.each do |element|
module_eval <<-RUBY
def #{element}(attrs = nil)
- self << "<#{element}\#{format_attrs(attrs)}>".html_safe
- self << yield if block_given?
- self << "</#{element}>".html_safe
+ "<#{element}\#{format_attrs(attrs)}>".html_safe +
+ (yield if block_given?) +
+ "</#{element}>".html_safe
+ end
+ end
+ SELF_CLOSING.each do |element|
+ module_eval <<-RUBY
+ def #{element}(attrs = nil)
+ "<#{element}\#{format_attrs(attrs)}/>".html_safe
@@ -24,7 +34,7 @@ def #{element}(attrs = nil)
def format_attrs(attrs)
return if attrs.nil?
- attrs.each_with_object("") do |name, value, str|
+ attrs.each_with_object("") do |(name, value), str|
str << %Q{ #{name}="#{value}"}

0 comments on commit 8ddd15c

Please sign in to comment.