Class: Qti::V1::Models::Base

Inherits:
Models::Base show all
Defined in:
lib/qti/v1/models/base.rb

Instance Attribute Summary

Attributes inherited from Models::Base

#doc, #manifest, #package_root, #path, #resource

Instance Method Summary collapse

Methods inherited from Models::Base

#css_with_single_check, from_path!, #initialize, #parse_html, #parse_xml, #preprocess_xml_doc, #raise_unsupported, #remap_href_path, #sanitize_content!, #xpath_with_single_check

Constructor Details

This class inherits a constructor from Qti::Models::Base

Instance Method Details

#qti_versionObject



7
8
9
# File 'lib/qti/v1/models/base.rb', line 7

def qti_version
  1
end

#return_inner_content!(node) ⇒ Object



11
12
13
14
15
# File 'lib/qti/v1/models/base.rb', line 11

def return_inner_content!(node)
  return CGI.unescapeHTML(node.inner_html).html_safe if html_node?(node)
  return node.text if text_node?(node)
  node.inner_html
end

#sanitize_attributes(html) ⇒ Object



17
18
19
20
21
# File 'lib/qti/v1/models/base.rb', line 17

def sanitize_attributes(html)
  node = Nokogiri::HTML.fragment(html)
  sanitize_attributes_by_node(node)
  node.to_html
end

#sanitize_attributes_by_node(node) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/qti/v1/models/base.rb', line 23

def sanitize_attributes_by_node(node)
  node.attribute_nodes.each do |a|
    matches = a.value.match(CANVAS_BLANK_REGEX) || []
    a.value = a.value.gsub!('[', '[').gsub!(']', ']') if matches.length.positive?
  end
  node.children.each { |c| sanitize_attributes_by_node(c) }
end