Skip to content

Commit

Permalink
Add support for embedded vimeo
Browse files Browse the repository at this point in the history
  • Loading branch information
themichaellai committed May 25, 2015
1 parent 2d39dd2 commit 636aadf
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/assets/stylesheets/site/embedded-media.css.sass
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions app/models/post/embedded_media/vimeo_tag.rb
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

0 comments on commit 636aadf

Please sign in to comment.