-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixing Youtube-bug and stop abusing self
- Loading branch information
1 parent
5959d7c
commit f860fec
Showing
1 changed file
with
16 additions
and
14 deletions.
There are no files selected for viewing
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
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 |