molten-trunk/molten5_withgrid/app/helpers/solutions_helper.rb
# If the specified term is found in the text, then a selection of that text is returned around
# that term.
# Otherwise, just the first AppConstants::SOLUTION_SEARCH_NOTE_LIMIT characters are returned.
If the specified term is found in the text, then a selection of that text is returned around
that term.
Otherwise, just the first AppConstants::SOLUTION_SEARCH_NOTE_LIMIT characters are returned.
If the specified term is found in the text then a selection of that text is returned around that term . Otherwise just the first AppConstants :: SOLUTION_SEARCH_NOTE_LIMIT characters are returned .
def find_and_highlight(text,term)
    return unless text
    begin
    if term and position = text.downcase =~ /#{term.downcase}/
       highlighted = highlight(text.slice( ((start = position - AppConstants::SOLUTION_SEARCH_NOTE_LIMIT/2) < 0 ? 0 : start )..(position + AppConstants::SOLUTION_SEARCH_NOTE_LIMIT/2) ), 
                 term)
       '...' + highlighted + '...'
    else
      truncate(text, AppConstants::SOLUTION_SEARCH_NOTE_LIMIT)
    end
    rescue  RegexpError 
      truncate(text, AppConstants::SOLUTION_SEARCH_NOTE_LIMIT)
    end
  end
def find_and_highlight ( text , term ) return unless text begin if term and position = text . downcase =~ / #{ term . downcase } / highlighted = highlight ( text . slice ( ( ( start = position - AppConstants :: SOLUTION_SEARCH_NOTE_LIMIT / 2 ) < 0 ? 0 : start ) .. ( position + AppConstants :: SOLUTION_SEARCH_NOTE_LIMIT / 2 ) ) , term ) '...' + highlighted + '...' else truncate ( text , AppConstants :: SOLUTION_SEARCH_NOTE_LIMIT ) end rescue RegexpError truncate ( text , AppConstants :: SOLUTION_SEARCH_NOTE_LIMIT ) end end
If the specified term is found in the text, then a selection of that text is returned around
that term.
If the specified term is found in the text then a selection of that text is returned around that term .
text
term