Skip to content

Commit 19c144f

Browse files
committed
remove strange else block
1 parent ca59ec3 commit 19c144f

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

actionpack/lib/action_view/helpers/text_helper.rb

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -144,17 +144,15 @@ def excerpt(text, phrase, *args)
144144
options.reverse_merge!(:radius => 100, :omission => "...")
145145

146146
phrase = Regexp.escape(phrase)
147-
if found_pos = text.mb_chars =~ /(#{phrase})/i
148-
start_pos = [ found_pos - options[:radius], 0 ].max
149-
end_pos = [ [ found_pos + phrase.mb_chars.length + options[:radius] - 1, 0].max, text.mb_chars.length ].min
147+
return unless found_pos = text.mb_chars =~ /(#{phrase})/i
150148

151-
prefix = start_pos > 0 ? options[:omission] : ""
152-
postfix = end_pos < text.mb_chars.length - 1 ? options[:omission] : ""
149+
start_pos = [ found_pos - options[:radius], 0 ].max
150+
end_pos = [ [ found_pos + phrase.mb_chars.length + options[:radius] - 1, 0].max, text.mb_chars.length ].min
153151

154-
prefix + text.mb_chars[start_pos..end_pos].strip + postfix
155-
else
156-
nil
157-
end
152+
prefix = start_pos > 0 ? options[:omission] : ""
153+
postfix = end_pos < text.mb_chars.length - 1 ? options[:omission] : ""
154+
155+
prefix + text.mb_chars[start_pos..end_pos].strip + postfix
158156
end
159157

160158
# Attempts to pluralize the +singular+ word unless +count+ is 1. If

0 commit comments

Comments
 (0)