Permalink
Browse files

Can render class

  • Loading branch information...
1 parent 896a53b commit 211c097aa055bb4ec711f2b00c5b4d9cf88d1da9 Joe Fiorini committed Jan 15, 2010
Showing with 14 additions and 2 deletions.
  1. +6 −2 lib/totally_tabular/html_helper.rb
  2. +8 −0 spec/lib/totally_tabular/html_helper_spec.rb
@@ -1,14 +1,18 @@
module TotallyTabular
class HtmlHelper
- def tag(tag, content="")
+ def tag(tag, content="", attributes={})
case tag.to_s
when "br"
"<br>"
when "input"
"<input>"
when /^\w+$/
- "<%s>%s</%s>" % [tag, content, tag]
+ if attributes.any?
+ css_class = attributes[:class]
+ attr_string = ' class="%s"' % css_class
+ end
+ "<%s%s>%s</%s>" % [tag, attr_string, content, tag]
else
""
end
@@ -32,4 +32,12 @@
it "returns a tag with content" do
@helper.tag(:strong, "blah").should == "<strong>blah</strong>"
end
+
+ it "returns empty if tag is invalid" do
+ @helper.tag("blah diddy").should == ""
+ end
+
+ it "renders with a class specified" do
+ @helper.tag(:strong, "blah", :class => "diddy").should =~ /class=\"diddy\"/
+ end
end

0 comments on commit 211c097

Please sign in to comment.