Skip to content
This repository has been archived by the owner on Aug 23, 2022. It is now read-only.

Commit

Permalink
Fixing Youtube-bug and stop abusing self
Browse files Browse the repository at this point in the history
  • Loading branch information
kaspergrubbe committed Mar 17, 2013
1 parent 5959d7c commit f860fec
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions lib/embedda.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
class String
def embedda
youtube_replace!
vimeo_replace!
compiled = youtube_replace(self)
compiled = vimeo_replace(compiled)

return compiled
end

private
def youtube_replace!
self.gsub(/[http|https]+:\/\/(?:www\.)?youtube\.com\/watch\?v=([a-zA-Z0-9\-\_]+)\S*/, youtube_player("\\1"))
self.gsub(/<a[^>]*?youtube\.com\/watch\?sv=([a-zA-Z0-9\-\_]+).*?<\/a>/, youtube_player("\\1"))
def youtube_replace(compiled)
compiled.gsub!(/<a[^>]*?youtube\.com\/watch\?v=([a-zA-Z0-9\-\_]+).*?<\/a>/i, youtube_player("\\1"))
compiled.gsub!(/[http|https]+:\/\/(?:www\.)?youtube\.com\/watch\?v=([a-zA-Z0-9\-\_]+)\S*/i, youtube_player("\\1"))

return compiled
end
def youtube_player(token)
return <<-END
<iframe width="560" height="315" src="http://www.youtube.com/embed/#{token}" frameborder="0" allowfullscreen></iframe>
END
"<iframe width=\"560\" height=\"315\" src=\"http://www.youtube.com/embed/#{token}\" frameborder=\"0\" allowfullscreen></iframe>"
end

def vimeo_replace!
self.gsub(/[http|https]+:\/\/(?:www\.)?vimeo\.com\/(\d+)\S*/, vimeo_player("\\1"))
self.gsub(/<a[^>]*?vimeo\.com\/(\d+).*?<\/a>/, vimeo_player("\\1"))
def vimeo_replace(compiled)
compiled.gsub!(/<a[^>]*?vimeo\.com\/(\d+).*?<\/a>/, vimeo_player("\\1"))
compiled.gsub!(/[http|https]+:\/\/(?:www\.)?vimeo\.com\/(\d+)\S*/, vimeo_player("\\1"))

return compiled
end
def vimeo_player(token)
return <<-END
<iframe src="http://player.vimeo.com/video/#{token}" width="500" height="281" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
END
"<iframe src=\"http://player.vimeo.com/video/#{token}\" width=\"500\" height=\"281\" frameborder=\"0\" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>"
end
end

0 comments on commit f860fec

Please sign in to comment.