Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Update truncate documentation / examples to more clearly demonstrate …

…its actual behavior

[#3016 state:committed]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
  • Loading branch information...
commit 618771beb57e623e05f70fd31f3bdb0c04318017 1 parent df745ed
@stevestmartin stevestmartin authored jeremy committed
Showing with 10 additions and 8 deletions.
  1. +10 −8 actionpack/lib/action_view/helpers/text_helper.rb
View
18 actionpack/lib/action_view/helpers/text_helper.rb
@@ -33,13 +33,15 @@ def concat(string, unused_binding = nil)
end
# Truncates a given +text+ after a given <tt>:length</tt> if +text+ is longer than <tt>:length</tt>
- # (defaults to 30). The last characters will be replaced with the <tt>:omission</tt> (defaults to "...").
+ # (defaults to 30). The last characters will be replaced with the <tt>:omission</tt> (defaults to "...")
+ # for a total length not exceeding <tt>:length</tt>.
+ #
# Pass a <tt>:separator</tt> to truncate +text+ at a natural break.
#
# ==== Examples
#
# truncate("Once upon a time in a world far far away")
- # # => Once upon a time in a world f...
+ # # => Once upon a time in a world...
#
# truncate("Once upon a time in a world far far away", :separator => ' ')
# # => Once upon a time in a world...
@@ -48,19 +50,19 @@ def concat(string, unused_binding = nil)
# # => Once upon a...
#
# truncate("And they found that many people were sleeping better.", :length => 25, "(clipped)")
- # # => And they found that many (clipped)
+ # # => And they found t(clipped)
#
- # truncate("And they found that many people were sleeping better.", :omission => "... (continued)", :length => 15)
- # # => And they found... (continued)
+ # truncate("And they found that many people were sleeping better.", :omission => "... (continued)", :length => 25)
+ # # => And they f... (continued)
#
# You can still use <tt>truncate</tt> with the old API that accepts the
# +length+ as its optional second and the +ellipsis+ as its
# optional third parameter:
# truncate("Once upon a time in a world far far away", 14)
- # # => Once upon a time in a world f...
+ # # => Once upon a...
#
- # truncate("And they found that many people were sleeping better.", 15, "... (continued)")
- # # => And they found... (continued)
+ # truncate("And they found that many people were sleeping better.", 25, "... (continued)")
+ # # => And they f... (continued)
def truncate(text, *args)
options = args.extract_options!
unless args.empty?
Please sign in to comment.
Something went wrong with that request. Please try again.