class OpenStax::Content::Fragment::Interactive
Constants
- CONTAINER_CSS
CSS to find interactive containers (anything inside may be replaced with an iframe)
- TAGGED_LINK_CSS
CSS to find links to be embedded inside containers
- UNTAGGED_LINK_CSS
Public Class Methods
replace_interactive_links_with_iframes!(node)
click to toggle source
This code is run from lib/openstax/cnx/v1/page.rb during import
# 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