class JekyllVideoTag::Tag
Public Class Methods
new(tag_name, input, tokens)
click to toggle source
Calls superclass method
# File lib/jekyll_video_tag.rb, line 3 def initialize(tag_name, input, tokens) super @url = input.slice!(/[^ ]+/) @options = parse_options(input) end
Public Instance Methods
render(context)
click to toggle source
# File lib/jekyll_video_tag.rb, line 9 def render(context) %(<div class="video-container" style="#{container_style(@options)}">#{video_iframe(@url)}</div>) end
Private Instance Methods
container_style(options)
click to toggle source
# File lib/jekyll_video_tag.rb, line 19 def container_style(options) "padding-bottom: #{height_as_percentage_of_width(options['width'], options['height'])}%" end
height_as_percentage_of_width(width, height)
click to toggle source
# File lib/jekyll_video_tag.rb, line 27 def height_as_percentage_of_width(width, height) (height.to_f / width.to_f) * 100 end
parse_options(input)
click to toggle source
# File lib/jekyll_video_tag.rb, line 23 def parse_options(input) Hash[input.strip.split(' ').map { |option| option.split('=') }] end
video_iframe(url)
click to toggle source
# File lib/jekyll_video_tag.rb, line 15 def video_iframe(url) %(<iframe src="#{url}" frameborder="0" allowfullscreen></iframe>) end