Skip to content

Instantly share code, notes, and snippets.

@benhamill
Created January 16, 2011 03:31
Show Gist options
  • Save benhamill/781525 to your computer and use it in GitHub Desktop.
Save benhamill/781525 to your computer and use it in GitHub Desktop.
def link_to url, text, options={}
valid_options = [:class, :id]
attributes = %Q{href="#{url}"}
valid_options.each do |option|
attributes = %Q{#{attributes} #{option.to_s}="#{options[option]}"} if options[option]
end
"<a #{attributes}>#{text}</a>"
end
def tweet_linkify text
text.gsub(/(http:\/\/[a-zA-Z0-9_\-\/\.\?\&]+)/, link_to($1, $1)).gsub(/\@([a-zA-Z0-9_\-]+)/, %Q{@#{link_to("http://twitter.com/#{$1}", $1)}})
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment