diff options
Diffstat (limited to 'actionpack/lib/action_view/helpers')
-rw-r--r-- | actionpack/lib/action_view/helpers/text_helper.rb | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb index 41423d4e2e..860c1de6af 100644 --- a/actionpack/lib/action_view/helpers/text_helper.rb +++ b/actionpack/lib/action_view/helpers/text_helper.rb @@ -1,4 +1,5 @@ require 'active_support/core_ext/object/blank' +require 'active_support/core_ext/string/filters' require 'action_view/helpers/tag_helper' module ActionView @@ -42,7 +43,7 @@ module ActionView # ==== Examples # # truncate("Once upon a time in a world far far away") - # # => Once upon a time in a world... + # # => Once upon a time in a worl... # # truncate("Once upon a time in a world far far away", :separator => ' ') # # => Once upon a time in a world... @@ -50,9 +51,6 @@ module ActionView # truncate("Once upon a time in a world far far away", :length => 14) # # => Once upon a... # - # truncate("And they found that many people were sleeping better.", :length => 25, "(clipped)") - # # => And they found t(clipped) - # # truncate("And they found that many people were sleeping better.", :omission => "... (continued)", :length => 25) # # => And they f... (continued) # @@ -73,14 +71,10 @@ module ActionView options[:length] = args[0] || 30 options[:omission] = args[1] || "..." end - options.reverse_merge!(:length => 30, :omission => "...") - if text - l = options[:length] - options[:omission].mb_chars.length - chars = text.mb_chars - stop = options[:separator] ? (chars.rindex(options[:separator].mb_chars, l) || l) : l - (chars.length > options[:length] ? chars[0...stop] + options[:omission] : text).to_s - end + options.reverse_merge!(:length => 30) + + text.truncate(options.delete(:length), options) if text end # Highlights one or more +phrases+ everywhere in +text+ by inserting it into |