Class: Twirly::Helpers::Youtube

Inherits:
Liquid::Tag
  • Object
show all
Defined in:
lib/twirly/helpers/youtube.rb

Overview

Exposes a tag for liquid templates with the following syntax

youtube width height value %

Instance Method Summary collapse

Constructor Details

#initialize(name, variables, tokens) ⇒ Youtube

Returns a new instance of Youtube.



8
9
10
11
# File 'lib/twirly/helpers/youtube.rb', line 8

def initialize(name, variables, tokens)
  super
  _parse_variables(variables)
end

Instance Method Details

#_parse_variables(variables) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/twirly/helpers/youtube.rb', line 23

def _parse_variables(variables)
  parsed_variables = variables.split(' ')
  if parsed_variables.size == 3
    @width  = parsed_variables[0]
    @height = parsed_variables[1]
    @id     = parsed_variables[2]
  else
    @id     = parsed_variables.first
    @width  = 320
    @height = 280
  end
end

#render(context) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/twirly/helpers/youtube.rb', line 13

def render(context)
  "  <div class=\"embed-video-container\">\n    <iframe width=\"\#{@width}\" height=\"\#{@height}\"\n            src=\"https://www.youtube.com/embed/\#{@id}\">\n    </iframe>\n  </div>\n  VIDEO\nend\n".strip_heredoc.strip