class DocTemplate::Tables::Section

Constants

FAKE_SECTION_TITLE
HEADER_LABEL
HTML_VALUE_FIELDS
MATERIALS_KEY

Public Instance Methods

parse(fragment, *args) click to toggle source
# File lib/doc_template/tables/section.rb, line 11
def parse(fragment, *args)
  section_tables = fragment.xpath(xpath_meta_headers, XpathFunctions.new)

  # # Allows to handle ELA as Math:: inject fake section
  return fake_section(fragment) if section_tables.empty? && args.extract_options![:force_inject]

  [].tap do |result|
    section_tables.each do |el|
      table = el.ancestors('table').first
      data = fetch table

      value = data['section-title'].parameterize
      table.replace section_placeholder(value)

      data = fetch_materials data, MATERIALS_KEY

      result << data
    end
  end
end

Private Instance Methods

fake_section(fragment) click to toggle source
# File lib/doc_template/tables/section.rb, line 34
def fake_section(fragment)
  if fragment.children.empty?
    fragment.add_child Nokogiri::HTML.fragment(section_placeholder(FAKE_SECTION_TITLE))
  else
    fragment.children.first.before section_placeholder(FAKE_SECTION_TITLE)
  end
  [{ 'section-title' => FAKE_SECTION_TITLE }]
end
section_placeholder(value) click to toggle source
# File lib/doc_template/tables/section.rb, line 43
def section_placeholder(value)
  "<p><span>[#{::DocTemplate::Tags::ActivityMetadataSectionTag::TAG_NAME}: #{value}]</span></p>"
end