-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2d39dd2
commit 636aadf
Showing
2 changed files
with
39 additions
and
0 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
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
class Post | ||
class EmbeddedMedia | ||
class VimeoTag < EmbeddedMedia::Tag | ||
|
||
def initialize(_embedded_media, vimeo_id) | ||
@vimeo_id = vimeo_id | ||
end | ||
|
||
def self.parse_url(url) | ||
return nil unless url =~ %r[^https?://(?:www\.)?vimeo\.com/] | ||
# https://stackoverflow.com/questions/13286785/get-video-id-from-vimeo-url/13286930#13286930 | ||
vimeo_id = /^.*(?:vimeo.com)\/(?:channels\/|channels\/\w+\/|groups\/[^\/]*\/videos\/|video\/|album\/\d+\/video\/|)(\d+)(?:$|\/|\?)/.match(url)[1] | ||
self.new(Post::EmbeddedMedia, vimeo_id) | ||
end | ||
|
||
def to_html | ||
content_tag( | ||
:iframe, | ||
nil, | ||
frameborder: 0, | ||
allowfullscreen: true, | ||
width: 606, | ||
height: 455, | ||
src: "//player.vimeo.com/video/#{@vimeo_id}", | ||
allowfullscreen: '' | ||
) | ||
end | ||
|
||
def to_s | ||
"{{Vimeo:#{@vimeo_id}}}" | ||
end | ||
end | ||
end | ||
end |