aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/lib
diff options
context:
space:
mode:
authorKasper Timm Hansen <kaspth@gmail.com>2015-08-11 23:30:09 +0200
committerKasper Timm Hansen <kaspth@gmail.com>2015-08-11 23:30:09 +0200
commit73c9e6a7aa7e3d082f969d5f0e5a6a0e2e2e4232 (patch)
treef2d488df3d876f1503cbec7e5776a50147d08a02 /actionview/lib
parentc18f81975c36961b053224c7aad4bce737373601 (diff)
parentcf93c6ae48cad47fda5c864c8b7b232f88bec088 (diff)
downloadrails-73c9e6a7aa7e3d082f969d5f0e5a6a0e2e2e4232.tar.gz
rails-73c9e6a7aa7e3d082f969d5f0e5a6a0e2e2e4232.tar.bz2
rails-73c9e6a7aa7e3d082f969d5f0e5a6a0e2e2e4232.zip
Merge pull request #21086 from bukue/add_break_sequence_option_to_word_wrap
Parametrize break sequence for word_wrap on ActionView Text Helpers
Diffstat (limited to 'actionview/lib')
-rw-r--r--actionview/lib/action_view/helpers/text_helper.rb13
1 files changed, 8 insertions, 5 deletions
diff --git a/actionview/lib/action_view/helpers/text_helper.rb b/actionview/lib/action_view/helpers/text_helper.rb
index 6a3d01667d..432693bc23 100644
--- a/actionview/lib/action_view/helpers/text_helper.rb
+++ b/actionview/lib/action_view/helpers/text_helper.rb
@@ -250,12 +250,15 @@ module ActionView
#
# word_wrap('Once upon a time', line_width: 1)
# # => Once\nupon\na\ntime
- def word_wrap(text, options = {})
- line_width = options.fetch(:line_width, 80)
-
+ #
+ # You can also specify a custom +break_sequence+ ("\n" by default)
+ #
+ # word_wrap('Once upon a time', line_width: 1, break_sequence: "\r\n")
+ # # => Once\r\nupon\r\na\r\ntime
+ def word_wrap(text, line_width: 80, break_sequence: "\n")
text.split("\n").collect! do |line|
- line.length > line_width ? line.gsub(/(.{1,#{line_width}})(\s+|$)/, "\\1\n").strip : line
- end * "\n"
+ line.length > line_width ? line.gsub(/(.{1,#{line_width}})(\s+|$)/, "\\1#{break_sequence}").strip : line
+ end * break_sequence
end
# Returns +text+ transformed into HTML using simple formatting rules.