Permalink
Browse files

Render attributes for empty tags

  • Loading branch information...
1 parent 5904cd1 commit afd53a5e091698b957070b14cb1d740a55df4add Joe Fiorini committed Jan 15, 2010
Showing with 11 additions and 6 deletions.
  1. +9 −6 lib/totally_tabular/html_helper.rb
  2. +2 −0 spec/lib/totally_tabular/html_helper_spec.rb
@@ -5,14 +5,17 @@ class HtmlHelper
def tag(tag, content="", attributes={})
case tag.to_s
when EMPTY_TAG
- "<%s>" % tag
+ "<%s%s>" % [tag, attrs(attributes)]
when /^\w+$/
- if attributes.any?
- attr_string =
- attr_string = ' %s' % attributes.map { |attr| '%s="%s"' % attr }.join(" ")
- end
- "<%s%s>%s</%s>" % [tag, attr_string, content, tag]
+ "<%s%s>%s</%s>" % [tag, attrs(attributes), content, tag]
end
end
+
+ private
+
+ def attrs(attributes)
+ return "" if attributes.empty?
+ attr_string = ' %s' % attributes.map { |attr| '%s="%s"' % attr }.join(" ")
+ end
end
end
@@ -43,5 +43,7 @@
end
it "renders empty tags with attributes" do
+ src = "http://www.asite.com/images/my_image.jpg"
+ @helper.tag(:img, "", :src => src).should =~ /src=\"#{src}\"/
end
end

0 comments on commit afd53a5

Please sign in to comment.