Skip to content

Commit 01635e9

Browse files
committed
Add support for embedded vimeo
1 parent 26b5b23 commit 01635e9

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

app/assets/stylesheets/site/embedded-media.css.sass

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@
3535
display: block
3636
margin: 0 auto
3737

38+
.embedded-vimeo
39+
iframe
40+
display: block
41+
margin: 0 auto
42+
3843
.embedded-poll
3944
padding: 10px 15px
4045
max-width: 200px
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
class Post
2+
class EmbeddedMedia
3+
class VimeoTag < EmbeddedMedia::Tag
4+
5+
def initialize(_embedded_media, vimeo_id)
6+
@vimeo_id = vimeo_id
7+
end
8+
9+
def self.parse_url(url)
10+
return nil unless url =~ %r[^https?://(?:www\.)?vimeo\.com/]
11+
# https://stackoverflow.com/questions/13286785/get-video-id-from-vimeo-url/13286930#13286930
12+
vimeo_id = /^.*(?:vimeo.com)\/(?:channels\/|channels\/\w+\/|groups\/[^\/]*\/videos\/|video\/|album\/\d+\/video\/|)(\d+)(?:$|\/|\?)/.match(url)[1]
13+
self.new(Post::EmbeddedMedia, vimeo_id)
14+
end
15+
16+
def to_html
17+
content_tag(
18+
:iframe,
19+
nil,
20+
frameborder: 0,
21+
allowfullscreen: true,
22+
width: 606,
23+
height: 455,
24+
src: "//player.vimeo.com/video/#{@vimeo_id}",
25+
allowfullscreen: ''
26+
)
27+
end
28+
29+
def to_s
30+
"{{Vimeo:#{@vimeo_id}}}"
31+
end
32+
end
33+
end
34+
end

0 commit comments

Comments
 (0)