Created
May 17, 2009 18:08
-
-
Save atinypixel/113077 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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