mirror of
https://github.com/github/rails.git
synced 2026-01-29 16:28:09 -05:00
simple_format helper doesn't choke on nil. Closes #6644.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5561 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
*SVN*
|
||||
|
||||
* simple_format helper doesn't choke on nil. #6644 [jerry426]
|
||||
|
||||
* Update to Prototype 1.5.0_rc2 [5550] which makes it work in Opera again [Thomas Fuchs]
|
||||
|
||||
* Reuse named route helper module between Routing reloads. Use remove_method to delete named route methods after each load. Since the module is never collected, this fixes a significant memory leak. [Nicholas Seckar]
|
||||
|
||||
@@ -154,12 +154,10 @@ module ActionView
|
||||
# considered as a linebreak and a <tt><br /></tt> tag is appended. This
|
||||
# method does not remove the newlines from the +text+.
|
||||
def simple_format(text)
|
||||
text = text.gsub(/(\r\n|\n|\r)/, "\n") # lets make them newlines crossplatform
|
||||
text.gsub!(/\n\n+/, "\n\n") # zap dupes
|
||||
text.gsub!(/\n\n/, '</p>\0<p>') # turn two newlines into paragraph
|
||||
text.gsub!(/([^\n])(\n)(?=[^\n])/, '\1\2<br />') # turn single newline into <br />
|
||||
|
||||
content_tag("p", text)
|
||||
content_tag 'p', text.to_s.
|
||||
gsub(/\r\n?/, "\n"). # \r\n and \r -> \n
|
||||
gsub(/\n\n+/, "</p>\n\n<p>"). # 2+ newline -> paragraph
|
||||
gsub(/([^\n]\n)(?=[^\n])/, '\1<br />') # 1 newline -> br
|
||||
end
|
||||
|
||||
# Turns all urls and email addresses into clickable links. The +link+ parameter
|
||||
|
||||
@@ -11,17 +11,21 @@ class TextHelperTest < Test::Unit::TestCase
|
||||
# a view is rendered. The cycle helper depends on this behavior.
|
||||
@_cycles = nil if (defined? @_cycles)
|
||||
end
|
||||
|
||||
|
||||
def test_simple_format
|
||||
assert_equal "<p></p>", simple_format(nil)
|
||||
|
||||
assert_equal "<p>crazy\n<br /> cross\n<br /> platform linebreaks</p>", simple_format("crazy\r\n cross\r platform linebreaks")
|
||||
assert_equal "<p>A paragraph</p>\n\n<p>and another one!</p>", simple_format("A paragraph\n\nand another one!")
|
||||
assert_equal "<p>A paragraph\n<br /> With a newline</p>", simple_format("A paragraph\n With a newline")
|
||||
|
||||
text = "A\nB\nC\nD"
|
||||
|
||||
text = "A\nB\nC\nD".freeze
|
||||
assert_equal "<p>A\n<br />B\n<br />C\n<br />D</p>", simple_format(text)
|
||||
assert_equal text, "A\nB\nC\nD"
|
||||
|
||||
text = "A\r\n \nB\n\n\r\n\t\nC\nD".freeze
|
||||
assert_equal "<p>A\n<br /> \n<br />B</p>\n\n<p>\t\n<br />C\n<br />D</p>", simple_format(text)
|
||||
end
|
||||
|
||||
|
||||
def test_truncate
|
||||
assert_equal "Hello World!", truncate("Hello World!", 12)
|
||||
assert_equal "Hello Wor...", truncate("Hello World!!", 12)
|
||||
|
||||
Reference in New Issue
Block a user