Class: OpenStax::Content::Fragment::Interactive

Inherits:
Embedded show all
Defined in:
lib/openstax/content/fragment/interactive.rb

Constant Summary collapse

CONTAINER_CSS =

CSS to find interactive containers (anything inside may be replaced with an iframe)

'figure.ost-embed-container, .os-figure:has-descendants("a.os-interactive-link"), figure:has-descendants("a.os-interactive-link")'
'a.os-embed, a.os-interactive-link'
'a'

Constants inherited from Embedded

Embedded::CLASS_ATTRIBUTES, Embedded::LABEL_ATTRIBUTE, Embedded::TAGGED_URL_CSS, Embedded::TITLE_CSS, Embedded::UNTAGGED_URL_CSS

Instance Attribute Summary

Attributes inherited from Embedded

#height, #url, #width

Attributes inherited from Html

#to_html

Attributes inherited from OpenStax::Content::Fragment

#labels, #node_id, #title

Class Method Summary collapse

Methods inherited from Embedded

#blank?, inherited, #initialize

Methods inherited from Html

#append, #as_json, #blank?, #has_css?, #html?, #initialize, #node, #transform_links!

Methods inherited from OpenStax::Content::Fragment

#blank?, #html?, #initialize

Constructor Details

This class inherits a constructor from OpenStax::Content::Fragment::Embedded

Class Method Details

This code is run from lib/openstax/cnx/v1/page.rb during import



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/openstax/content/fragment/interactive.rb', line 16

def self.replace_interactive_links_with_iframes!(node)
  containers = node.css(CONTAINER_CSS, OpenStax::Content::CustomCss.instance)

  containers.each do |container|
    link_node = node.at_css(TAGGED_LINK_CSS) || node.css(UNTAGGED_LINK_CSS).last

    next if link_node.nil?

    # Build iframe based on the link's URL
    iframe = Nokogiri::XML::Node.new('iframe', node.document)
    iframe['title'] = 'Interactive Simulation'
    iframe['src'] = link_node['href']
    iframe['class'] = iframe_classes.join(' ')
    iframe['width'] = default_width
    iframe['height'] = default_height

    # Replace the container with the new iframe
    container.replace(iframe)
  end
end