atinypixel (owner)

Revisions

gist: 113077 Download_button fork
public
Public Clone URL: git://gist.github.com/113077.git
Embed All Files: show embed
Passing a block to gsub #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 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