Sha256: a6ef6a133413a1ad3bad078cf4011f39c7dac06f4c87e1c9b81a19158d8146f8

Contents?: true

Size: 1.81 KB

Versions: 13

Compression:

Stored size: 1.81 KB

Contents

# frozen_string_literal: true

module DocTemplate
  module Tables
    class Activity < Base
      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'

      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

      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
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
lcms-engine-0.5.5 lib/doc_template/tables/activity.rb
lcms-engine-0.5.4 lib/doc_template/tables/activity.rb
lcms-engine-0.5.3 lib/doc_template/tables/activity.rb
lcms-engine-0.5.2 lib/doc_template/tables/activity.rb
lcms-engine-0.5.1 lib/doc_template/tables/activity.rb
lcms-engine-0.5.0 lib/doc_template/tables/activity.rb
lcms-engine-0.4.2 lib/doc_template/tables/activity.rb
lcms-engine-0.4.1 lib/doc_template/tables/activity.rb
lcms-engine-0.4.0 lib/doc_template/tables/activity.rb
lcms-engine-0.3.1 lib/doc_template/tables/activity.rb
lcms-engine-0.1.4 lib/doc_template/tables/activity.rb
lcms-engine-0.3.0 lib/doc_template/tables/activity.rb
lcms-engine-0.1.3 lib/doc_template/tables/activity.rb