Skip to content

Commit 1d604a4

Browse files
Quote example output strings [ci-skip]
This portrays the return values more accurately and, in some cases, fixes syntax highlighting when using the upcoming version of SDoc (thanks to its heuristic for detecting Ruby code vs HTML code).
1 parent dc53bb9 commit 1d604a4

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

actionview/lib/action_view/helpers/text_helper.rb

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -115,25 +115,25 @@ def truncate(text, options = {}, &block)
115115
# for <tt>:sanitize</tt> will turn sanitizing off.
116116
#
117117
# highlight('You searched for: rails', 'rails')
118-
# # => You searched for: <mark>rails</mark>
118+
# # => "You searched for: <mark>rails</mark>"
119119
#
120120
# highlight('You searched for: rails', /for|rails/)
121-
# # => You searched <mark>for</mark>: <mark>rails</mark>
121+
# # => "You searched <mark>for</mark>: <mark>rails</mark>"
122122
#
123123
# highlight('You searched for: ruby, rails, dhh', 'actionpack')
124-
# # => You searched for: ruby, rails, dhh
124+
# # => "You searched for: ruby, rails, dhh"
125125
#
126126
# highlight('You searched for: rails', ['for', 'rails'], highlighter: '<em>\1</em>')
127-
# # => You searched <em>for</em>: <em>rails</em>
127+
# # => "You searched <em>for</em>: <em>rails</em>"
128128
#
129129
# highlight('You searched for: rails', 'rails', highlighter: '<a href="search?q=\1">\1</a>')
130-
# # => You searched for: <a href="search?q=rails">rails</a>
130+
# # => "You searched for: <a href=\"search?q=rails\">rails</a>"
131131
#
132132
# highlight('You searched for: rails', 'rails') { |match| link_to(search_path(q: match, match)) }
133-
# # => You searched for: <a href="search?q=rails">rails</a>
133+
# # => "You searched for: <a href=\"search?q=rails\">rails</a>"
134134
#
135135
# highlight('<a href="javascript:alert(\'no!\')">ruby</a> on rails', 'rails', sanitize: false)
136-
# # => <a href="javascript:alert('no!')">ruby</a> on <mark>rails</mark>
136+
# # => "<a href=\"javascript:alert('no!')\">ruby</a> on <mark>rails</mark>"
137137
def highlight(text, phrases, options = {}, &block)
138138
text = sanitize(text) if options.fetch(:sanitize, true)
139139

@@ -164,22 +164,22 @@ def highlight(text, phrases, options = {}, &block)
164164
# isn't found, +nil+ is returned.
165165
#
166166
# excerpt('This is an example', 'an', radius: 5)
167-
# # => ...s is an exam...
167+
# # => "...s is an exam..."
168168
#
169169
# excerpt('This is an example', 'is', radius: 5)
170-
# # => This is a...
170+
# # => "This is a..."
171171
#
172172
# excerpt('This is an example', 'is')
173-
# # => This is an example
173+
# # => "This is an example"
174174
#
175175
# excerpt('This next thing is an example', 'ex', radius: 2)
176-
# # => ...next...
176+
# # => "...next..."
177177
#
178178
# excerpt('This is also an example', 'an', radius: 8, omission: '<chop> ')
179-
# # => <chop> is also an example
179+
# # => "<chop> is also an example"
180180
#
181181
# excerpt('This is a very beautiful morning', 'very', separator: ' ', radius: 1)
182-
# # => ...a very beautiful...
182+
# # => "...a very beautiful..."
183183
def excerpt(text, phrase, options = {})
184184
return unless text && phrase
185185

@@ -222,19 +222,19 @@ def excerpt(text, phrase, options = {})
222222
# See ActiveSupport::Inflector.pluralize
223223
#
224224
# pluralize(1, 'person')
225-
# # => 1 person
225+
# # => "1 person"
226226
#
227227
# pluralize(2, 'person')
228-
# # => 2 people
228+
# # => "2 people"
229229
#
230230
# pluralize(3, 'person', plural: 'users')
231-
# # => 3 users
231+
# # => "3 users"
232232
#
233233
# pluralize(0, 'person')
234-
# # => 0 people
234+
# # => "0 people"
235235
#
236236
# pluralize(2, 'Person', locale: :de)
237-
# # => 2 Personen
237+
# # => "2 Personen"
238238
def pluralize(count, singular, plural_arg = nil, plural: plural_arg, locale: I18n.locale)
239239
word = if count == 1 || count.to_s.match?(/^1(\.0+)?$/)
240240
singular
@@ -250,21 +250,21 @@ def pluralize(count, singular, plural_arg = nil, plural: plural_arg, locale: I18
250250
# (which is 80 by default).
251251
#
252252
# word_wrap('Once upon a time')
253-
# # => Once upon a time
253+
# # => "Once upon a time"
254254
#
255255
# word_wrap('Once upon a time, in a kingdom called Far Far Away, a king fell ill, and finding a successor to the throne turned out to be more trouble than anyone could have imagined...')
256-
# # => Once upon a time, in a kingdom called Far Far Away, a king fell ill, and finding\na successor to the throne turned out to be more trouble than anyone could have\nimagined...
256+
# # => "Once upon a time, in a kingdom called Far Far Away, a king fell ill, and finding\na successor to the throne turned out to be more trouble than anyone could have\nimagined..."
257257
#
258258
# word_wrap('Once upon a time', line_width: 8)
259-
# # => Once\nupon a\ntime
259+
# # => "Once\nupon a\ntime"
260260
#
261261
# word_wrap('Once upon a time', line_width: 1)
262-
# # => Once\nupon\na\ntime
262+
# # => "Once\nupon\na\ntime"
263263
#
264264
# You can also specify a custom +break_sequence+ ("\n" by default):
265265
#
266266
# word_wrap('Once upon a time', line_width: 1, break_sequence: "\r\n")
267-
# # => Once\r\nupon\r\na\r\ntime
267+
# # => "Once\r\nupon\r\na\r\ntime"
268268
def word_wrap(text, line_width: 80, break_sequence: "\n")
269269
return +"" if text.empty?
270270

0 commit comments

Comments
 (0)