Class: Shortcodes::Youtube

Inherits:
Handler
  • Object
show all
Defined in:
lib/shortcodes/youtube.rb

Instance Attribute Summary

Attributes inherited from Handler

#shortcode

Instance Method Summary collapse

Methods inherited from Handler

#attributes, call, #initialize

Constructor Details

This class inherits a constructor from Shortcodes::Handler

Instance Method Details

#heightObject



22
23
24
# File 'lib/shortcodes/youtube.rb', line 22

def height
  attributes.fetch('height', 315)
end

#renderObject



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

#timeObject



17
18
19
20
# File 'lib/shortcodes/youtube.rb', line 17

def time
  t = url[/(t=[0-9msh]+)/]
  t ? "##{t}" : nil
end

#urlObject



6
7
8
9
# File 'lib/shortcodes/youtube.rb', line 6

def url
  # TODO: Provide a better interface for missing url
  url = shortcode.attributes.fetch('url')
end

#widthObject



26
27
28
# File 'lib/shortcodes/youtube.rb', line 26

def width
  attributes.fetch('width', 560)
end

#youtube_idObject



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