Sha256: 32853d7c9d255011469f6c42876ddce2c92ddb38695322761be3d78011295304

Contents?: true

Size: 1.11 KB

Versions: 16

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true

module DocTemplate
  module Tags
    class VocabularyTag < TableTag
      TAG_NAME = 'vocabulary'
      TEMPLATE = 'vocabulary.html.erb'

      def parse_table(table)
        params = { sections: fetch_content(table) }
        parsed_content = parse_template params, TEMPLATE
        @content = parse_nested parsed_content, @opts
        replace_tag table
      end

      private

      def fetch_content(node)
        [].tap do |result|
          # omit the first row
          cur_section = nil
          node.xpath('.//tr[position() > 1]').each do |tr|
            if (td_header = tr.at_xpath "./td[@colspan = '2']")
              result << cur_section if cur_section.present?
              cur_section = { title: td_header.text }
            elsif cur_section.present?
              cur_section[:words] ||= []
              cur_section[:words] << { name: tr.at_xpath('./td[1]').text, definition: tr.at_xpath('./td[2]').text }
            end
          end
          result << cur_section
        end
      end
    end
  end

  Template.register_tag(Tags::VocabularyTag::TAG_NAME, Tags::VocabularyTag)
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
lcms-engine-0.5.5 lib/doc_template/tags/vocabulary_tag.rb
lcms-engine-0.5.4 lib/doc_template/tags/vocabulary_tag.rb
lcms-engine-0.5.3 lib/doc_template/tags/vocabulary_tag.rb
lcms-engine-0.5.2 lib/doc_template/tags/vocabulary_tag.rb
lcms-engine-0.5.1 lib/doc_template/tags/vocabulary_tag.rb
lcms-engine-0.5.0 lib/doc_template/tags/vocabulary_tag.rb
lcms-engine-0.4.2 lib/doc_template/tags/vocabulary_tag.rb
lcms-engine-0.4.1 lib/doc_template/tags/vocabulary_tag.rb
lcms-engine-0.4.0 lib/doc_template/tags/vocabulary_tag.rb
lcms-engine-0.3.1 lib/doc_template/tags/vocabulary_tag.rb
lcms-engine-0.1.4 lib/doc_template/tags/vocabulary_tag.rb
lcms-engine-0.3.0 lib/doc_template/tags/vocabulary_tag.rb
lcms-engine-0.1.3 lib/doc_template/tags/vocabulary_tag.rb
lcms-engine-0.2.0 lib/doc_template/tags/vocabulary_tag.rb
lcms-engine-0.1.2 lib/doc_template/tags/vocabulary_tag.rb
lcms-engine-0.1.0 lib/doc_template/tags/vocabulary_tag.rb