Added TextHelper#word_wrap(text, line_length = 80) #1449 [tuxie@dekadance.se]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1465 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
David Heinemeier Hansson 2005-06-21 07:16:11 +00:00
parent e59bfc8519
commit c608ebeade
3 changed files with 11 additions and 0 deletions

View File

@ -1,5 +1,7 @@
*SVN* *SVN*
* Added TextHelper#word_wrap(text, line_length = 80) #1449 [tuxie@dekadance.se]
* Added a fall-through action for form_remote_tag that'll be used in case Javascript is unavailable #1459 [Scott Barron]. Example: * Added a fall-through action for form_remote_tag that'll be used in case Javascript is unavailable #1459 [Scott Barron]. Example:
form_remote_tag :html => { :action => url_for(:controller => "some", :action => "place") } form_remote_tag :html => { :action => url_for(:controller => "some", :action => "place") }

View File

@ -65,6 +65,11 @@ module ActionView
end end
end end
# Word wrap long lines to line_width.
def word_wrap(text, line_width = 80)
text.gsub(/\n/, "\n\n").gsub(/(.{1,#{line_width}})(\s+|$)/, "\\1\n").strip
end
begin begin
require "redcloth" require "redcloth"

View File

@ -67,6 +67,10 @@ class TextHelperTest < Test::Unit::TestCase
assert_equal("...iful morning", excerpt("This is a beautiful morning", "morning", 5)) assert_equal("...iful morning", excerpt("This is a beautiful morning", "morning", 5))
assert_nil excerpt("This is a beautiful morning", "day") assert_nil excerpt("This is a beautiful morning", "day")
end end
def test_word_wrap
assert_equal("my very very\nvery long\nstring", word_wrap("my very very very long string", 15))
end
def test_pluralization def test_pluralization
assert_equal("1 count", pluralize(1, "count")) assert_equal("1 count", pluralize(1, "count"))