Skip to content

Instantly share code, notes, and snippets.

@tealtan
Last active December 19, 2015 05:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save tealtan/5906712 to your computer and use it in GitHub Desktop.
Save tealtan/5906712 to your computer and use it in GitHub Desktop.
module ApplicationHelper
def combine_highlight(selected_text, surrounding_text)
if surrounding_text.include? selected_text
split_text = surrounding_text.split(selected_text)
content_tag(:p, split_text[0].to_s.html_safe + content_tag(:span, selected_text, class:"selected") + split_text[1].to_s.html_safe)
else
content_tag(:p, surrounding_text, class:"selected")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment