1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Fixed TextHelper#word_wrap for multiline strings with extra carrier returns (closes #8663) [seth]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7562 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
David Heinemeier Hansson 2007-09-22 18:21:54 +00:00
parent 286bd9b9f0
commit 9686dcdb5b
3 changed files with 9 additions and 1 deletions

View file

@ -1,5 +1,7 @@
*SVN*
* Fixed TextHelper#word_wrap for multiline strings with extra carrier returns #8663 [seth]
* Fixed that setting the :host option in url_for would automatically turn off :only_path (since :host would otherwise not be shown) #9586 [Bounga]
* Added FormHelper#label #8641 [jcoglan]

View file

@ -161,7 +161,9 @@ module ActionView
# word_wrap('Once upon a time', 1)
# # => Once\nupon\na\ntime
def word_wrap(text, line_width = 80)
text.gsub(/\n/, "\n\n").gsub(/(.{1,#{line_width}})(\s+|$)/, "\\1\n").strip
text.split("\n").collect do |line|
line.length > line_width ? line.gsub(/(.{1,#{line_width}})(\s+|$)/, "\\1\n").strip : line
end * "\n"
end
begin

View file

@ -120,6 +120,10 @@ class TextHelperTest < Test::Unit::TestCase
assert_equal("my very very\nvery long\nstring", word_wrap("my very very very long string", 15))
end
def test_word_wrap_with_extra_newlines
assert_equal("my very very\nvery long\nstring\n\nwith another\nline", word_wrap("my very very very long string\n\nwith another line", 15))
end
def test_pluralization
assert_equal("1 count", pluralize(1, "count"))
assert_equal("2 counts", pluralize(2, "count"))