Skip to content

Instantly share code, notes, and snippets.

@jamesu
Created February 23, 2009 18:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesu/69084 to your computer and use it in GitHub Desktop.
Save jamesu/69084 to your computer and use it in GitHub Desktop.
# Allows embedded YouTube videos in EchoWaves.
# Simply replace mark_up in app/helpers/messages_helper.rb with the following
# NOTE: Ignores the rest of the message with the YT url in it, so ideally needs to be merged with the line splitting conversion of url's.
def mark_up(message)
return message.message if message.system_message == true # no markup for system_messages
content = message.message
# Youtube?
yt_video = content.match(/http:\/\/www\.youtube\.com\/watch.*v=([a-zA-Z0-9]*)/)
unless yt_video.nil?
vid_src = "http://www.youtube.com/v/#{yt_video[1]}&hl=en&fs=1"
return "<object width=\"425\" height=\"344\"><param name=\"movie\" value=\"#{vid_src}\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\"#{vid_src}\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"425\" height=\"344\"></embed></object>"
end
# Normal message
parts = content.split "\n"
parts.map {|s| h(s)}.join(" <br/>").gsub(/(http|https|ftp)([^ ]+)/i) {|s| "<a href='#{s}' rel='nofollow'>#{s}</a>"}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment