Permalink
Browse files

Merge branch 'arbre-closing-tags' into update-rspec

  • Loading branch information...
2 parents 7432a15 + ccf2847 commit 23b5f83a66d3d95e97df2753afbc289ef344987d @jeremyruppel jeremyruppel committed May 26, 2011
View
17 lib/active_admin/arbre/tag.rb
@@ -85,12 +85,13 @@ def indent(open_tag, child_content, close_tag)
html = ""
- 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
+ if no_child? || child_is_text?
+ if self_closing_tag?
+ html << spaces << open_tag.sub( />$/, '/>' )
+ else
+ # one line
+ html << spaces << open_tag << child_content << close_tag
+ end
else
# multiple lines
html << spaces << open_tag << "\n"
@@ -103,6 +104,10 @@ def indent(open_tag, child_content, close_tag)
html
end
+ def self_closing_tag?
+ %w|meta link|.include?(tag_name)
+ end
+
def no_child?
children.empty?
end
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/>"
+ collection.strip.chomp.should == "hello World<h1></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 id="my_id"></tag>
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 class="&quot;&gt;bad things!"></tag>
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 &gt;bad="things"></tag>
HTML
end
end
View
30 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,18 +147,24 @@
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
+ it "should not self-close script tags" do
+ tag = script :type => 'text/javascript'
+ tag.to_html.should == <<-HTML
+<script type="text/javascript"></script>
+HTML
+ end
+ it "should self-close meta tags" do
+ tag = meta :content => "text/html; charset=utf-8"
tag.to_html.should == <<-HTML
-<li/>
+<meta content="text/html; charset=utf-8\"/>
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"
+ it "should self-close link tags" do
+ tag = link :rel => "stylesheet"
tag.to_html.should == <<-HTML
-<meta http-equiv="Content-type" content="text/html; charset=utf-8\"/>
+<link rel="stylesheet"/>
HTML
end
end

0 comments on commit 23b5f83

Please sign in to comment.