Created
July 11, 2011 20:44
-
-
Save shamil614/1076758 to your computer and use it in GitHub Desktop.
Twitter Link Helper
This file contains 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
def twitter_links(txt) | |
match = [] | |
#link @user | |
if match = txt.scan(/@([A-Za-z0-9_]+)/i) | |
match.each do |user| | |
txt.gsub!('@'+user[0], '<a href="http://twitter.com/' + user[0] + '">@' + user[0] + '</a>') | |
end | |
end | |
#link #hash_tags | |
if match = txt.scan(/\B#\w*[a-zA-Z]+\w*/i) | |
match.each do |m| | |
txt.gsub!(m,'<a href="http://twitter.com/search?q='+ m + '">' + m + '</a>') | |
end | |
end | |
txt | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment