From 636aadff6df6b5a4ceb35ec52f914e0455895d27 Mon Sep 17 00:00:00 2001 From: Michael Lai Date: Sun, 24 May 2015 22:36:19 -0700 Subject: [PATCH] Add support for embedded vimeo --- .../stylesheets/site/embedded-media.css.sass | 5 +++ app/models/post/embedded_media/vimeo_tag.rb | 34 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 app/models/post/embedded_media/vimeo_tag.rb diff --git a/app/assets/stylesheets/site/embedded-media.css.sass b/app/assets/stylesheets/site/embedded-media.css.sass index 15ad5b75..1876c01d 100644 --- a/app/assets/stylesheets/site/embedded-media.css.sass +++ b/app/assets/stylesheets/site/embedded-media.css.sass @@ -35,6 +35,11 @@ display: block margin: 0 auto +.embedded-vimeo + iframe + display: block + margin: 0 auto + .embedded-poll padding: 10px 15px max-width: 200px diff --git a/app/models/post/embedded_media/vimeo_tag.rb b/app/models/post/embedded_media/vimeo_tag.rb new file mode 100644 index 00000000..005d7e40 --- /dev/null +++ b/app/models/post/embedded_media/vimeo_tag.rb @@ -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