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



41
42
43
44
45
46
47
48
# File 'lib/jekyll-poly.rb', line 41

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



34
35
36
37
38
39
# File 'lib/jekyll-poly.rb', line 34

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
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 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



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/jekyll-poly.rb', line 50

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