Class: DocTemplate::Tables::Activity

Inherits:
Base
  • Object
show all
Defined in:
lib/doc_template/tables/activity.rb

Constant Summary collapse

HEADER_LABEL =
'activity-metadata'
HTML_VALUE_FIELDS =
%w(about-the-activity-student about-the-activity-teacher activity-metacognition
activity-guidance alert class-configuration-student reading-purpose).freeze
MATERIALS_KEY =
'materials'

Constants inherited from Base

Base::SPLIT_REGEX

Instance Attribute Summary

Attributes inherited from Base

#data, #errors

Instance Method Summary collapse

Methods inherited from Base

#collect_and_render_tags, #fetch_materials, #initialize, parse, #parse_in_context, #table_exist?

Constructor Details

This class inherits a constructor from DocTemplate::Tables::Base

Instance Method Details

#parse(fragment, *args) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/doc_template/tables/activity.rb', line 11

def parse(fragment, *args)
  template_type = args.extract_options![:template_type].presence || 'core'
  idx = 0
  [].tap do |result|
    fragment.xpath(xpath_meta_headers, XpathFunctions.new).each do |el|
      table = el.ancestors('table').first
      data = fetch table

      data = process_title(data)

      # Places activity type tags
      if data['activity-title'].present?
        idx += 1
        # we define the tag value as an unique(-ish) anchor, so we can retrieve this activity
        # info later (check toc_helpers#find_by_anchor). Used for building the sections TOC
        value = "#{idx}-#{template_type}-l2-#{data['activity-title']}".parameterize
        data['idx'] = idx
        data['anchor'] = value
        header = "<p><span>[#{::DocTemplate::Tags::ActivityMetadataTypeTag::TAG_NAME}: #{value}]</span></p>"
        table.add_next_sibling header
      end

      table.remove
      data = fetch_materials data, MATERIALS_KEY

      result << data
    end
  end
end

#process_title(data) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/doc_template/tables/activity.rb', line 41

def process_title(data)
  # Allows to handle ELA as Math:
  # - inject `section-title` to link to fake section
  # - substitute activity title
  data['section-title'] ||= Tables::Section::FAKE_SECTION_TITLE
  data['activity-title'] ||= data['number']
  data
end