Skip to content

Instantly share code, notes, and snippets.

@atinypixel
Created May 17, 2009 18:08
Show Gist options
  • Save atinypixel/113077 to your computer and use it in GitHub Desktop.
Save atinypixel/113077 to your computer and use it in GitHub Desktop.
# Simple example
# Regex is between these -> \\ and my replacement string is in single quotes
def change_p_tags_to_divs(content)
content.gsub(\<.*?(p)>\, 'div')
end
# Complex example
# This (real) example puts `@tags` in a hyperlink, finds a path (if any) and then spits out the result.
def highlight_at_tags(content)
content.gsub(/@(\w+)/m) do |w|
ws = Workspace.find_by_name("#{$1}")
%{<a class="at_tag" href="\"><span class="at_symbol">@</span><span>#{$1}</span></a>}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment