@@ -68,17 +68,36 @@ def safe_concat(string)
68
68
output_buffer . respond_to? ( :safe_concat ) ? output_buffer . safe_concat ( string ) : concat ( string )
69
69
end
70
70
71
- # Truncates a given +text+ after a given <tt>:length</tt> if +text+ is longer than <tt> :length</tt>
72
- # (defaults to 30). The last characters will be replaced with the <tt>:omission</tt> (defaults to "...")
73
- # for a total length not exceeding <tt> :length</tt> .
71
+ # Truncates +text+ if it is longer than a specified + :length+. If +text+
72
+ # is truncated, an omission marker will be appended to the result for a
73
+ # total length not exceeding + :length+ .
74
74
#
75
- # Pass a <tt>:separator</tt> to truncate +text+ at a natural break.
75
+ # You can also pass a block to render and append extra content after the
76
+ # omission marker when +text+ is truncated. However, this content _can_
77
+ # cause the total length to exceed +:length+ characters.
76
78
#
77
- # Pass a block if you want to show extra content when the text is truncated.
79
+ # The result will be escaped unless <tt>escape: false</tt> is specified.
80
+ # In any case, the result will be marked HTML-safe. Care should be taken
81
+ # if +text+ might contain HTML tags or entities, because truncation could
82
+ # produce invalid HTML, such as unbalanced or incomplete tags.
78
83
#
79
- # The result is marked as HTML-safe, but it is escaped by default, unless <tt>:escape</tt> is
80
- # +false+. Care should be taken if +text+ contains HTML tags or entities, because truncation
81
- # may produce invalid HTML (such as unbalanced or incomplete tags).
84
+ # ==== Options
85
+ #
86
+ # [+:length+]
87
+ # The maximum number of characters that should be returned, excluding
88
+ # any extra content from the block. Defaults to 30.
89
+ #
90
+ # [+:omission+]
91
+ # The string to append after truncating. Defaults to <tt>"..."</tt>.
92
+ #
93
+ # [+:separator+]
94
+ # A string or regexp used to find a breaking point at which to truncate.
95
+ # By default, truncation can occur at any character in +text+.
96
+ #
97
+ # [+:escape+]
98
+ # Whether to escape the result. Defaults to true.
99
+ #
100
+ # ==== Examples
82
101
#
83
102
# truncate("Once upon a time in a world far far away")
84
103
# # => "Once upon a time in a world..."
0 commit comments