diff --git a/actionview/lib/action_view/helpers/text_helper.rb b/actionview/lib/action_view/helpers/text_helper.rb index ccfaf17803a9d..c7e7f4c5fb917 100644 --- a/actionview/lib/action_view/helpers/text_helper.rb +++ b/actionview/lib/action_view/helpers/text_helper.rb @@ -115,25 +115,25 @@ def truncate(text, options = {}, &block) # for :sanitize will turn sanitizing off. # # highlight('You searched for: rails', 'rails') - # # => You searched for: rails + # # => "You searched for: rails" # # highlight('You searched for: rails', /for|rails/) - # # => You searched for: rails + # # => "You searched for: rails" # # highlight('You searched for: ruby, rails, dhh', 'actionpack') - # # => You searched for: ruby, rails, dhh + # # => "You searched for: ruby, rails, dhh" # # highlight('You searched for: rails', ['for', 'rails'], highlighter: '\1') - # # => You searched for: rails + # # => "You searched for: rails" # # highlight('You searched for: rails', 'rails', highlighter: '\1') - # # => You searched for: rails + # # => "You searched for: rails" # # highlight('You searched for: rails', 'rails') { |match| link_to(search_path(q: match, match)) } - # # => You searched for: rails + # # => "You searched for: rails" # # highlight('ruby on rails', 'rails', sanitize: false) - # # => ruby on rails + # # => "ruby on rails" def highlight(text, phrases, options = {}, &block) text = sanitize(text) if options.fetch(:sanitize, true) @@ -164,22 +164,22 @@ def highlight(text, phrases, options = {}, &block) # isn't found, +nil+ is returned. # # excerpt('This is an example', 'an', radius: 5) - # # => ...s is an exam... + # # => "...s is an exam..." # # excerpt('This is an example', 'is', radius: 5) - # # => This is a... + # # => "This is a..." # # excerpt('This is an example', 'is') - # # => This is an example + # # => "This is an example" # # excerpt('This next thing is an example', 'ex', radius: 2) - # # => ...next... + # # => "...next..." # # excerpt('This is also an example', 'an', radius: 8, omission: ' ') - # # => is also an example + # # => " is also an example" # # excerpt('This is a very beautiful morning', 'very', separator: ' ', radius: 1) - # # => ...a very beautiful... + # # => "...a very beautiful..." def excerpt(text, phrase, options = {}) return unless text && phrase @@ -222,19 +222,19 @@ def excerpt(text, phrase, options = {}) # See ActiveSupport::Inflector.pluralize # # pluralize(1, 'person') - # # => 1 person + # # => "1 person" # # pluralize(2, 'person') - # # => 2 people + # # => "2 people" # # pluralize(3, 'person', plural: 'users') - # # => 3 users + # # => "3 users" # # pluralize(0, 'person') - # # => 0 people + # # => "0 people" # # pluralize(2, 'Person', locale: :de) - # # => 2 Personen + # # => "2 Personen" def pluralize(count, singular, plural_arg = nil, plural: plural_arg, locale: I18n.locale) word = if count == 1 || count.to_s.match?(/^1(\.0+)?$/) singular @@ -250,21 +250,21 @@ def pluralize(count, singular, plural_arg = nil, plural: plural_arg, locale: I18 # (which is 80 by default). # # word_wrap('Once upon a time') - # # => Once upon a time + # # => "Once upon a time" # # word_wrap('Once upon a time, in a kingdom called Far Far Away, a king fell ill, and finding a successor to the throne turned out to be more trouble than anyone could have imagined...') - # # => Once upon a time, in a kingdom called Far Far Away, a king fell ill, and finding\na successor to the throne turned out to be more trouble than anyone could have\nimagined... + # # => "Once upon a time, in a kingdom called Far Far Away, a king fell ill, and finding\na successor to the throne turned out to be more trouble than anyone could have\nimagined..." # # word_wrap('Once upon a time', line_width: 8) - # # => Once\nupon a\ntime + # # => "Once\nupon a\ntime" # # word_wrap('Once upon a time', line_width: 1) - # # => Once\nupon\na\ntime + # # => "Once\nupon\na\ntime" # # 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 + # # => "Once\r\nupon\r\na\r\ntime" def word_wrap(text, line_width: 80, break_sequence: "\n") return +"" if text.empty?