Skip to content

Commit

Permalink
Revert "Drop support for XHTML flavor tags. HTML 5 supports both"
Browse files Browse the repository at this point in the history
This reverts commit 0327c97.
  • Loading branch information
DAddYE committed Feb 23, 2012
1 parent e4b9e28 commit cdb92a0
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 7 deletions.
4 changes: 2 additions & 2 deletions padrino-helpers/lib/padrino-helpers/format_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ def strip_tags(html)
# @api public
def simple_format(text, options={})
t = options.delete(:tag) || :p
start_tag = tag(t, options)
start_tag = tag(t, options, true)
text = text.to_s.dup
text.gsub!(/\r\n?/, "\n") # \r\n and \r -> \n
text.gsub!(/\n\n+/, "</#{t}>\n\n#{start_tag}") # 2+ newline -> paragraph
text.gsub!(/([^\n]\n)(?=[^\n])/, '\1<br>') # 1 newline -> br
text.gsub!(/([^\n]\n)(?=[^\n])/, '\1<br />') # 1 newline -> br
text.insert 0, start_tag
text << "</#{t}>"
end
Expand Down
4 changes: 2 additions & 2 deletions padrino-helpers/lib/padrino-helpers/tag_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ def input_tag(type, options = {})
# # => <img src="sinatra.jpg" data-nsfw="false" data-geo="34.087 -118.407">
#
# @api public
def tag(name, options = nil)
"<#{name}#{tag_options(options) if options}>"
def tag(name, options = nil, open = false)
"<#{name}#{tag_options(options) if options}#{open ? '>' : ' />'}"
end

private
Expand Down
5 changes: 5 additions & 0 deletions padrino-helpers/test/test_asset_tag_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ def flash
self.class.expects(:asset_stamp).returns(false)
assert_has_tag('img', :src => "/absolute/pic.gif") { image_tag('/absolute/pic.gif') }
end

should "have xhtml convention tag" do
self.class.expects(:asset_stamp).returns(false)
assert_equal image_tag('/absolute/pic.gif'), '<img src="/absolute/pic.gif" />'
end
end

context 'for #stylesheet_link_tag method' do
Expand Down
4 changes: 2 additions & 2 deletions padrino-helpers/test/test_format_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def setup
context 'for #simple_format method' do
should "format simple text into html format" do
actual_text = simple_format("Here is some basic text...\n...with a line break.")
assert_equal "<p>Here is some basic text...\n<br>...with a line break.</p>", actual_text
assert_equal "<p>Here is some basic text...\n<br />...with a line break.</p>", actual_text
end

should "format more text into html format" do
Expand All @@ -31,7 +31,7 @@ def setup
context 'wrapped in a custom tag' do
should "format simple text into html format" do
actual_text = simple_format("Here is some basic text...\n...with a line break.", :tag => :div)
assert_equal "<div>Here is some basic text...\n<br>...with a line break.</div>", actual_text
assert_equal "<div>Here is some basic text...\n<br />...with a line break.</div>", actual_text
end

should "format more text into html format" do
Expand Down
16 changes: 15 additions & 1 deletion padrino-helpers/test/test_tag_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ def app
end

context 'for #tag method' do
should("support tags with no content no attributes") do
assert_has_tag(:br) { tag(:br) }
end

should("support tags with no content with attributes") do
actual_html = tag(:br, :style => 'clear:both', :class => 'yellow')
assert_has_tag(:br, :class => 'yellow', :style=>'clear:both') { actual_html }
end

should "support selected attribute by using 'selected' if true" do
actual_html = tag(:option, :selected => true)
assert_has_tag('option', :selected => 'selected') { actual_html }
Expand All @@ -17,9 +26,14 @@ def app
assert_has_tag(:a, 'data-remote' => 'true', 'data-method' => 'post') { actual_html }
end

should "support open tags" do
actual_html = tag(:p, { :class => 'demo' }, true)
assert_equal "<p class=\"demo\">", actual_html
end

should "escape html" do
actual_html = tag(:br, :class => 'Example "bar"')
assert_equal "<br class=\"Example &quot;bar&quot;\">", actual_html
assert_equal "<br class=\"Example &quot;bar&quot;\" />", actual_html
end
end

Expand Down

0 comments on commit cdb92a0

Please sign in to comment.