-
Notifications
You must be signed in to change notification settings - Fork 5
/
video_embed.rb
40 lines (31 loc) · 1.05 KB
/
video_embed.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
module Jekyll
class VideoEmbed < Liquid::Tag
Syntax = /^\s*([^\s]+)(\s+(\d+)\s+(\d+)\s*)?/
Hosts = {
"ted" => ->(id) { "https://embed-ssl.ted.com/talks/#{id}.html" },
"ustream" => ->(id) { "https://ustream.tv/embed/#{id}" },
"vimeo" => ->(id) { "https://player.vimeo.com/video/#{id}" },
"youtube" => ->(id) { "https://youtube.com/embed/#{id}" }
}
def initialize(tag_name, markup, tokens)
super
if markup =~ Syntax then
@host = Hosts[tag_name]
@id = $1
if $2.nil? then
@width = 640
@height = 360
else
@width = $2.to_i
@height = $3.to_i
end
else
raise "No video ID provided in the \"#{tag_name}\" tag"
end
end
def render(context)
"<iframe width=\"#{@width}\" height=\"#{@height}\" src=\"#{@host.call(@id)}\" frameborder=\"0\" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>"
end
Hosts.each_key { |key| Liquid::Template.register_tag key, self }
end
end