def excerpt(text, phrase, *args)
return unless text && phrase
options = args.extract_options!
unless args.empty?
ActiveSupport::Deprecation.warn "Calling excerpt with radius and omission as arguments is deprecated. " \
"Please call with :radius => #{args[0]}#{", :omission => '#{args[1]}'" if args[1]} instead.", caller
options[:radius] = args[0] || 100
options[:omission] = args[1] || "..."
end
options.reverse_merge!(:radius => 100, :omission => "...")
phrase = Regexp.escape(phrase)
return unless 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
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