Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit 8ddd15c9131b8b89c862b6cf972f0a0acbc915b0 1 parent 54e1312
Roel van Dijk authored
Showing with 20 additions and 10 deletions.
  1. +20 −10 lib/jrb/helpers/html.rb
30 lib/jrb/helpers/html.rb
View
@@ -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
+ RUBY
+ end
+
+ SELF_CLOSING.each do |element|
+ module_eval <<-RUBY
+ def #{element}(attrs = nil)
+ "<#{element}\#{format_attrs(attrs)}/>".html_safe
end
RUBY
end
@@ -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}"}
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.