Class: PolyEmbed

Inherits:
Liquid::Tag
  • Object
show all
Defined in:
lib/jekyll-poly.rb

Instance Method Summary collapse

Constructor Details

#initialize(tagName, content, tokens) ⇒ PolyEmbed

Returns a new instance of PolyEmbed.



5
6
7
8
# File 'lib/jekyll-poly.rb', line 5

def initialize(tagName, content, tokens)
  super
  @content = content
end

Instance Method Details

#generate(context, poly_id) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/jekyll-poly.rb', line 21

def generate(context, poly_id)
  tmpl_path = File.join Dir.pwd, "_includes", "poly.html"
  if File.exist? tmpl_path
    generate_from_template context, tmpl_path, poly_id
  else
    generate_iframe poly_id
  end
end

#generate_from_template(context, tmpl_path, poly_id) ⇒ Object



14
15
16
17
18
19
# File 'lib/jekyll-poly.rb', line 14

def generate_from_template(context, tmpl_path, poly_id)
  @poly_id = poly_id
  tmpl = File.read tmpl_path
  site = context.registers[:site]
  tmpl = (Liquid::Template.parse tmpl).render site.site_payload.merge!({"poly_id" => @poly_id})
end

#generate_iframe(poly_id) ⇒ Object



10
11
12
# File 'lib/jekyll-poly.rb', line 10

def generate_iframe(poly_id)
  %Q{<style>.embed-container {  position: relative;  padding-bottom: 56.25%;  height: 0;  overflow: hidden;  max-width: 100%;}.embed-container iframe,.embed-container object,.embed-container embed {  position: absolute;  top: 0;  left: 0;  width: 100%;  height: 100%;}</style><div class=".embed-container"><iframe width="100%" height="480px" src="https://poly.google.com/view/#{ poly_id }/embed" frameborder="0" style="border:none;" allowvr="yes" allow="vr; xr; accelerometer; magnetometer; gyroscope; autoplay;" allowfullscreen mozallowfullscreen="true" webkitallowfullscreen="true" onmousewheel="" ></iframe></div>}
end

#render(context) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/jekyll-poly.rb', line 30

def render(context)
  poly_url = "#{context[@content.strip]}"

  if poly_url[/poly\.google\.com\/view\/([^\?]*)/]
    poly_id = $1
  else
    raise "The URL provided #{ poly_url } does not match a google poly URL"
  end

  generate(context, poly_id)
end