Class: Shortcodes::Youtube
Instance Attribute Summary
Attributes inherited from Handler
#shortcode
Instance Method Summary
collapse
Methods inherited from Handler
#attributes, call, #initialize
Instance Method Details
#height ⇒ Object
22
23
24
|
# File 'lib/shortcodes/youtube.rb', line 22
def height
attributes.fetch('height', 315)
end
|
#render ⇒ Object
30
31
32
|
# File 'lib/shortcodes/youtube.rb', line 30
def render
%Q{<iframe width="#{width}" height="#{height}" src="//www.youtube.com/embed/#{youtube_id}#{time}" frameborder="0" allowfullscreen></iframe>}
end
|
#time ⇒ Object
17
18
19
20
|
# File 'lib/shortcodes/youtube.rb', line 17
def time
t = url[/(t=[0-9msh]+)/]
t ? "##{t}" : nil
end
|
#url ⇒ Object
6
7
8
9
|
# File 'lib/shortcodes/youtube.rb', line 6
def url
url = shortcode.attributes.fetch('url')
end
|
#width ⇒ Object
26
27
28
|
# File 'lib/shortcodes/youtube.rb', line 26
def width
attributes.fetch('width', 560)
end
|
#youtube_id ⇒ Object
11
12
13
14
15
|
# File 'lib/shortcodes/youtube.rb', line 11
def youtube_id
match = url.match(/(v=|youtu.be\/)([a-zA-Z0-9_-]{11}+)/)
match ? match[2] : nil
end
|