diff options
| author | Vijay Dev <vijaydev.cse@gmail.com> | 2015-08-24 06:05:07 +0000 |
|---|---|---|
| committer | Vijay Dev <vijaydev.cse@gmail.com> | 2015-08-24 06:05:07 +0000 |
| commit | 4f252cddc1ee4e28c633a2250335b2fac4d31108 (patch) | |
| tree | 776177555c7039204e23c9c1b7d33b700d366ca3 /actionview/lib/action_view/helpers/text_helper.rb | |
| parent | bc36ffeec05692777f4ece09978a321feed2d818 (diff) | |
| parent | 06818cb9a8cee8c95eaebdd1418e6fcb0da9382e (diff) | |
| download | rails-4f252cddc1ee4e28c633a2250335b2fac4d31108.tar.gz rails-4f252cddc1ee4e28c633a2250335b2fac4d31108.tar.bz2 rails-4f252cddc1ee4e28c633a2250335b2fac4d31108.zip | |
Merge branch 'master' of github.com:rails/rails
Conflicts:
guides/source/security.md
Diffstat (limited to 'actionview/lib/action_view/helpers/text_helper.rb')
| -rw-r--r-- | actionview/lib/action_view/helpers/text_helper.rb | 13 |
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. |
