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