Class: OpenStax::Content::Fragment::Interactive
- Inherits:
-
Embedded
- Object
- OpenStax::Content::Fragment
- Html
- Embedded
- OpenStax::Content::Fragment::Interactive
- 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")'
- TAGGED_LINK_CSS =
CSS to find links to be embedded inside containers
'a.os-embed, a.os-interactive-link'
- UNTAGGED_LINK_CSS =
'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
Attributes inherited from Html
Attributes inherited from OpenStax::Content::Fragment
Class Method Summary collapse
-
.replace_interactive_links_with_iframes!(node) ⇒ Object
This code is run from lib/openstax/cnx/v1/page.rb during import.
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
Constructor Details
This class inherits a constructor from OpenStax::Content::Fragment::Embedded
Class Method Details
.replace_interactive_links_with_iframes!(node) ⇒ Object
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 |