Skip to content

Instantly share code, notes, and snippets.

@jankeesvw
Created August 30, 2012 13:38
Show Gist options
  • Save jankeesvw/3528706 to your computer and use it in GitHub Desktop.
Save jankeesvw/3528706 to your computer and use it in GitHub Desktop.
<%=
random_tweet = tweets.sample
tweet_text = random_tweet["text"]
#make links clickable
tweet_text.gsub!(/(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/) { |x| "<a href='#{x}'>#{x}</a>" }
#make mentions clickable
tweet_text.gsub!(/@\w+/) { |x| "<a href='http://twitter.com/#{x[1..-1]}'>#{x}</a>" }
#pass it to the view
raw "<em>#{random_tweet["user"]["name"]} <a href='http://twitter.com/#{random_tweet["user"]["screen_name"]}/statuses/#{random_tweet["id"]}'>@#{random_tweet["user"]["screen_name"]}</a> :<br>&ldquo;#{tweet_text}&rdquo;</em>"
%>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment