Created
November 29, 2010 10:23
-
-
Save paulingham/719794 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 youtube_video(url, text, height, width) | |
altered_text = text.gsub(url,"<iframe title='YouTube video player' class='youtube-player' type='text/html' width='#{width}' height='#{height}' src='#{url}' frameborder='0'></iframe>") | |
end | |
def vimeo_video(url, text, height, width) | |
ident_regexp = /\/[0-9]{3,}/ | |
url_ident = url.scan(ident_regexp).to_s | |
altered_text = text.gsub(url,"<p><iframe title='Vimeo Video Player' src='http://player.vimeo.com/video#{url_ident}' width='#{width}' height='#{height}' frameborder='0'></iframe></p>") | |
end | |
def parse_video(text, height, width) | |
youtube_regexp = /(ht)tp\:\/\/[a-zA-Z0-9\-\.]+\.(com|co.uk|org|net|mil|edu)/i | |
url = text.split.grep(youtube_regexp).to_s | |
if url != "" && url.match("youtube.com") | |
text = youtube_video(url, text, height, width) | |
elsif url != "" && url.match("vimeo.com") | |
text = vimeo_video(url, text, height, width) | |
end | |
return text | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment