Sha256: 14b7ea04e2aff9713a614667cb538a567f740354eb1455a35f2c74559335b9b0

Contents?: true

Size: 1.29 KB

Versions: 10

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

module DocTemplate
  module Tags
    class ExpandTag < TableTag
      BREAK_TAG_NAME = 'break'
      TAG_NAME = 'expand'
      TEMPLATES = { default: 'expand.html.erb',
                    gdoc: 'gdoc/expand.html.erb' }.freeze

      def parse_table(table)
        params = { subject: (@opts[:metadata].try(:[], 'subject').presence || 'ela').downcase }
        params[:content], params[:content_hidden] = fetch_content table

        parsed_template = parse_template params, template_name(@opts)
        @content = parse_nested(parsed_template, @opts)
        replace_tag table
      end

      private

      def fetch_content(node)
        broken = false
        content_visible = []
        content_hidden = []

        # iterates over all child nodes looking for break tag
        node.at_xpath('.//tr[2]/td').children.each do |child|
          (broken = true) && next if child.text.index("[#{BREAK_TAG_NAME}]")

          child.remove_attribute('class')
          child.children.each { |x| x.remove_attribute('class') }
          broken ? content_hidden.push(child) : content_visible.push(child)
        end

        [content_visible.map(&:to_html).join, content_hidden.map(&:to_html).join]
      end
    end
  end

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

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
lcms-engine-0.5.5 lib/doc_template/tags/expand_tag.rb
lcms-engine-0.5.4 lib/doc_template/tags/expand_tag.rb
lcms-engine-0.5.3 lib/doc_template/tags/expand_tag.rb
lcms-engine-0.5.2 lib/doc_template/tags/expand_tag.rb
lcms-engine-0.5.1 lib/doc_template/tags/expand_tag.rb
lcms-engine-0.5.0 lib/doc_template/tags/expand_tag.rb
lcms-engine-0.4.2 lib/doc_template/tags/expand_tag.rb
lcms-engine-0.4.1 lib/doc_template/tags/expand_tag.rb
lcms-engine-0.4.0 lib/doc_template/tags/expand_tag.rb
lcms-engine-0.3.1 lib/doc_template/tags/expand_tag.rb