Skip to content
Browse files

arbre tags without any children should be self-closing, fixes whiny a…

…ssert_selects
  • Loading branch information...
1 parent 72b1db8 commit 71036bfd016dfa676333eff8e1530282662eb19a @jeremyruppel jeremyruppel committed with Ben Marini May 25, 2011
View
5 lib/active_admin/arbre/tag.rb
@@ -85,7 +85,10 @@ def indent(open_tag, child_content, close_tag)
html = ""
- if no_child? || child_is_text?
+ if no_child?
+ # self-closing tag
+ html << spaces << open_tag.sub( />$/, '/>' )
+ elsif child_is_text?
# one line
html << spaces << open_tag << child_content << close_tag
else
View
2 spec/unit/arbre/html/element_spec.rb
@@ -216,7 +216,7 @@
let(:collection){ "hello World" + h1}
it "should return a string" do
- collection.strip.chomp.should == "hello World<h1></h1>"
+ collection.strip.chomp.should == "hello World<h1/>"
end
end
end
View
6 spec/unit/arbre/html/tag_attributes_spec.rb
@@ -15,7 +15,7 @@
it "should render the attributes to html" do
tag.to_html.should == <<-HTML
-<tag id="my_id"></tag>
+<tag id="my_id"/>
HTML
end
@@ -48,13 +48,13 @@
it "should html safe the attribute values" do
tag.set_attribute(:class, "\">bad things!")
tag.to_html.should == <<-HTML
-<tag class="&quot;&gt;bad things!"></tag>
+<tag class="&quot;&gt;bad things!"/>
HTML
end
it "should should escape the attribute names" do
tag.set_attribute(">bad", "things")
tag.to_html.should == <<-HTML
-<tag &gt;bad="things"></tag>
+<tag &gt;bad="things"/>
HTML
end
end
View
25 spec/unit/arbre/html_spec.rb
@@ -69,9 +69,9 @@
end
content.to_html.should == <<-HTML
<div>
- <ul></ul>
+ <ul/>
<li>
- <li></li>
+ <li/>
</li>
</div>
HTML
@@ -86,7 +86,7 @@
content.to_html.should == <<-HTML
<div>
<ul>
- <li></li>
+ <li/>
</ul>
</div>
HTML
@@ -100,7 +100,7 @@
<div>
<span>
<ul>
- <li></li>
+ <li/>
</ul>
</span>
</div>
@@ -117,7 +117,7 @@
content.to_html.should == <<-HTML
<div id="my-tag">
<ul>
- <li></li>
+ <li/>
</ul>
</div>
HTML
@@ -147,6 +147,21 @@
end.children.first.should be_instance_of(Arbre::HTML::TextNode)
end
end
+
+ describe "self-closing nodes" do
+ it "should close tags that do not have any child nodes" do
+ tag = li
+ tag.to_html.should == <<-HTML
+<li/>
+HTML
+ end
+ it "should close tags that have attributes but no child nodes" do
+ tag = meta :"http-equiv" => "Content-type", :content => "text/html; charset=utf-8"
+ tag.to_html.should == <<-HTML
+<meta content="text/html; charset=utf-8" http-equiv="Content-type"/>
+HTML
+ end
+ end
describe "html safe" do
it "should escape the contents" do

0 comments on commit 71036bf

Please sign in to comment.
Something went wrong with that request. Please try again.