Skip to content

Commit 4c9d56a

Browse files
Improve documentation for excerpt text helper
Co-authored-by: Jonathan Hefner <[email protected]>
1 parent df2961b commit 4c9d56a

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

actionview/lib/action_view/helpers/text_helper.rb

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,27 @@ def highlight(text, phrases, options = {}, &block)
160160
end.html_safe
161161
end
162162

163-
# Extracts an excerpt from +text+ that matches the first instance of +phrase+.
164-
# The <tt>:radius</tt> option expands the excerpt on each side of the first occurrence of +phrase+ by the number of characters
165-
# defined in <tt>:radius</tt> (which defaults to 100). If the excerpt radius overflows the beginning or end of the +text+,
166-
# then the <tt>:omission</tt> option (which defaults to "...") will be prepended/appended accordingly. Use the
167-
# <tt>:separator</tt> option to choose the delimitation. The resulting string will be stripped in any case. If the +phrase+
168-
# isn't found, +nil+ is returned.
163+
# Extracts the first occurrence of +phrase+ plus surrounding text from
164+
# +text+. An omission marker is prepended / appended if the start / end of
165+
# the result does not coincide with the start / end of +text+. The result
166+
# is always stripped in any case. Returns +nil+ if +phrase+ isn't found.
167+
#
168+
# ==== Options
169+
#
170+
# [+:radius+]
171+
# The number of characters (or tokens — see +:separator+ option) around
172+
# +phrase+ to include in the result. Defaults to 100.
173+
#
174+
# [+:omission+]
175+
# The marker to prepend / append when the start / end of the excerpt
176+
# does not coincide with the start / end of +text+. Defaults to
177+
# <tt>"..."</tt>.
178+
#
179+
# [+:separator+]
180+
# The separator between tokens to count for +:radius+. Defaults to
181+
# <tt>""</tt>, which treats each character as a token.
182+
#
183+
# ==== Examples
169184
#
170185
# excerpt('This is an example', 'an', radius: 5)
171186
# # => "...s is an exam..."

0 commit comments

Comments
 (0)