diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-10-18 10:31:21 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-10-18 10:31:21 -0700 |
commit | 19c144f1b3d441d2cc7b227c68b3971f12d42c0c (patch) | |
tree | 4cd482bb1780d383adb88cccd4d1cdbeb3a2cc4a /actionpack/lib | |
parent | ca59ec354ee8ba264120783c9364927a97b90896 (diff) | |
download | rails-19c144f1b3d441d2cc7b227c68b3971f12d42c0c.tar.gz rails-19c144f1b3d441d2cc7b227c68b3971f12d42c0c.tar.bz2 rails-19c144f1b3d441d2cc7b227c68b3971f12d42c0c.zip |
remove strange else block
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_view/helpers/text_helper.rb | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb index 1463c94aa1..e53076c586 100644 --- a/actionpack/lib/action_view/helpers/text_helper.rb +++ b/actionpack/lib/action_view/helpers/text_helper.rb @@ -144,17 +144,15 @@ module ActionView options.reverse_merge!(:radius => 100, :omission => "...") phrase = Regexp.escape(phrase) - if found_pos = text.mb_chars =~ /(#{phrase})/i - start_pos = [ found_pos - options[:radius], 0 ].max - end_pos = [ [ found_pos + phrase.mb_chars.length + options[:radius] - 1, 0].max, text.mb_chars.length ].min + return unless found_pos = text.mb_chars =~ /(#{phrase})/i - prefix = start_pos > 0 ? options[:omission] : "" - postfix = end_pos < text.mb_chars.length - 1 ? options[:omission] : "" + start_pos = [ found_pos - options[:radius], 0 ].max + end_pos = [ [ found_pos + phrase.mb_chars.length + options[:radius] - 1, 0].max, text.mb_chars.length ].min - prefix + text.mb_chars[start_pos..end_pos].strip + postfix - else - nil - end + prefix = start_pos > 0 ? options[:omission] : "" + postfix = end_pos < text.mb_chars.length - 1 ? options[:omission] : "" + + prefix + text.mb_chars[start_pos..end_pos].strip + postfix end # Attempts to pluralize the +singular+ word unless +count+ is 1. If |