# File lib/action_view/helpers/text_helper.rb, line 44 def excerpt(text, phrase, radius = 100, excerpt_string = "...") if text.nil? || phrase.nil? then return end phrase = Regexp.escape(phrase) if found_pos = text =~ /(#{phrase})/i start_pos = [ found_pos - radius, 0 ].max end_pos = [ found_pos + phrase.length + radius, text.length ].min prefix = start_pos > 0 ? excerpt_string : "" postfix = end_pos < text.length ? excerpt_string : "" prefix + text[start_pos..end_pos].strip + postfix else nil end end