Permalink
Browse files

Added TextHelper#word_wrap(text, line_length = 80) #1449 [tuxie@dekad…

…ance.se]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1465 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent e59bfc8 commit c608ebeade50d3e87e750486e4949e8c3bdf1549 @dhh dhh committed Jun 21, 2005
View
@@ -1,5 +1,7 @@
*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:
form_remote_tag :html => { :action => url_for(:controller => "some", :action => "place") }
@@ -65,6 +65,11 @@ def pluralize(count, singular, plural = nil)
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
require "redcloth"
@@ -67,6 +67,10 @@ def test_excerpt
assert_equal("...iful morning", excerpt("This is a beautiful morning", "morning", 5))
assert_nil excerpt("This is a beautiful morning", "day")
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
assert_equal("1 count", pluralize(1, "count"))

0 comments on commit c608ebe

Please sign in to comment.