diff options
author | Xavier Noria <fxn@hashref.com> | 2010-06-02 01:34:39 +0200 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2010-06-02 01:35:04 +0200 |
commit | 315e8952dfbaecd4d5175ea4d0fd95611cad9e01 (patch) | |
tree | f410483bd9c86aaab689c2645e7cd7fcc1052dc3 /activesupport/lib/active_support/core_ext/string | |
parent | 5a0d73f17ce5590b1246d90ef54b6c6234f0fd0e (diff) | |
download | rails-315e8952dfbaecd4d5175ea4d0fd95611cad9e01.tar.gz rails-315e8952dfbaecd4d5175ea4d0fd95611cad9e01.tar.bz2 rails-315e8952dfbaecd4d5175ea4d0fd95611cad9e01.zip |
revises the documentation of String#truncate and the truncate helper
Diffstat (limited to 'activesupport/lib/active_support/core_ext/string')
-rw-r--r-- | activesupport/lib/active_support/core_ext/string/filters.rb | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/activesupport/lib/active_support/core_ext/string/filters.rb b/activesupport/lib/active_support/core_ext/string/filters.rb index cdd86a836f..e15a1df9c9 100644 --- a/activesupport/lib/active_support/core_ext/string/filters.rb +++ b/activesupport/lib/active_support/core_ext/string/filters.rb @@ -20,25 +20,21 @@ class String self end - # Truncates a given +text+ after a given <tt>length</tt> if +text+ is longer than <tt>length</tt>. - # The last characters will be replaced with the <tt>:omission</tt> (defaults to "...") - # for a total length not exceeding <tt>:length</tt>. + # Truncates a given +text+ after a given <tt>length</tt> if +text+ is longer than <tt>length</tt>: # - # Pass a <tt>:separator</tt> to truncate +text+ at a natural break. + # "Once upon a time in a world far far away".truncate(27) + # # => "Once upon a time in a wo..." # - # ==== Examples + # The last characters will be replaced with the <tt>:omission</tt> string (defaults to "...") + # for a total length not exceeding <tt>:length</tt>: # - # "Once upon a time in a world far far away".truncate(30) - # # => Once upon a time in a worl... + # "Once upon a time in a world far far away".truncate(27, :separator => ' ') + # # => "Once upon a time in a..." # - # "Once upon a time in a world far far away".truncate(30, :separator => ' ') - # # => Once upon a time in a world... - # - # "Once upon a time in a world far far away".truncate(14) - # # => Once upon a... + # Pass a <tt>:separator</tt> to truncate +text+ at a natural break: # # "And they found that many people were sleeping better.".truncate(25, :omission => "... (continued)") - # # => And they f... (continued) + # # => "And they f... (continued)" def truncate(length, options = {}) text = self.dup options[:omission] ||= "..." |