Class: Foliokit::Overlay::OverlayWebview

Inherits:
OverlayBase show all
Defined in:
lib/foliokit/overlay/overlay_webview.rb

Instance Attribute Summary

Attributes inherited from OverlayBase

#section_index, #state

Instance Method Summary collapse

Methods inherited from OverlayBase

element_base, #initialize, #stateful?

Methods included from Modules::Element

#initialize

Constructor Details

This class inherits a constructor from Foliokit::Overlay::OverlayBase

Instance Method Details

#export(document, options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/foliokit/overlay/overlay_webview.rb', line 11

def export(document, options = {})
  node = super(document, options)
  node["touchable"] = true
  node["data-type"] = "iframe"
  uri = Addressable::URI.parse(web_view_url)

  # Handle simple iframe embeds
  if uri.relative?
    file = package.dir.file(uri.to_s)
    return nil unless file.exists?

    elements = Nokogiri::HTML(file.read).css("body > *")
    if elements.count == 1 and elements.first.name == "iframe"
      uri = Addressable::URI.parse(elements.first["src"])
      uri.query = "referrer=WebView"
    end
  end

  # Process embed type
  if uri.absolute?
    if uri.host =~ /(youtube)/
      node["data-type"] = "youtube"
    end
  else
    file = package.dir.file(uri.to_s)
    return nil unless file.exists?

    html_dir_path = file.dir.relative_path(package.dir)
    html_dir_hash = Digest::MD5.hexdigest(html_dir_path)
    html_dir = package.root.dir("html").dir(html_dir_hash)
    unless html_dir.exists?
      puts "-- creating html dir"
      file.dir.copy(html_dir)
    end
    html_file = html_dir.file(file.name)
    uri = Addressable::URI.parse(html_file.relative_path(package.root))
    uri.query = "referrer=WebView"
  end

  # Set source
  node["data-src"] = uri.to_s

  node
end

#tagnameObject



7
8
9
# File 'lib/foliokit/overlay/overlay_webview.rb', line 7

def tagname
  "div"
end