Sha256: 4a8381bc0eca351cd582db526bcae7eb48e0e2b44b4cf0e8b7cc211c969e2365

Contents?: true

Size: 1.92 KB

Versions: 10

Compression:

Stored size: 1.92 KB

Contents

module Asciidoctor
  module Standoc
    module Table
      def table_attrs(node)
        keep_attrs(node).merge( id: Utils::anchor_or_uuid(node),
          headerrows: node.attr("headerrows"),
          unnumbered: node.option?("unnumbered") ? "true" : nil,
          number: node.attr("number"),
          subsequence: node.attr("subsequence"),
          alt: node.attr("alt"),
          summary: node.attr("summary"),
          width: node.attr("width"),
        )
      end

      def table(node)
        @table_fn_number = "a"
        noko do |xml|
          xml.table **attr_code(table_attrs(node)) do |xml_table|
            table_name(node, xml_table)
            %i(head body foot).reject do |tblsec|
              node.rows[tblsec].empty?
            end
            table_head_body_and_foot node, xml_table
          end
        end
      end

      private

      def table_name(node, xml_table)
        if node.title?
          xml_table.name do |n|
            n << node.title
          end
        end
      end

      def table_cell1(cell, thd)
        if cell.style == :asciidoc
          thd << cell.content
        else
          thd << cell.text
        end
      end

      def table_cell(c, xml_tr, tblsec)
        cell_attributes = { id: c.id, colspan: c.colspan,
                            rowspan: c.rowspan, align: c.attr("halign") }
        cell_tag = "td"
        cell_tag = "th" if tblsec == :head || c.style == :header
        xml_tr.send cell_tag, **attr_code(cell_attributes) do |thd|
          table_cell1(c, thd)
        end
      end

      def table_head_body_and_foot(node, xml)
        %i(head body foot).reject { |s| node.rows[s].empty? }.each do |s|
          xml.send "t#{s}" do |xml_tblsec|
            node.rows[s].each do |row|
              xml_tblsec.tr do |xml_tr|
                row.each { |cell| table_cell(cell, xml_tr, s) }
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 9 versions & 2 rubygems

Version Path
metanorma-standoc-1.5.2 lib/asciidoctor/standoc/table.rb
metanorma-standoc-1.5.1 lib/asciidoctor/standoc/table.rb
metanorma-cli-1.3.4 gems/ruby/2.6.0/gems/metanorma-standoc-1.4.4/lib/asciidoctor/standoc/table.rb
metanorma-cli-1.3.4 gems/ruby/2.6.0/gems/metanorma-standoc-1.5.0/lib/asciidoctor/standoc/table.rb
metanorma-standoc-1.5.0 lib/asciidoctor/standoc/table.rb
metanorma-cli-1.3.3.1 gems/ruby/2.6.0/gems/metanorma-standoc-1.4.4/lib/asciidoctor/standoc/table.rb
metanorma-standoc-1.4.4 lib/asciidoctor/standoc/table.rb
metanorma-standoc-1.4.3 lib/asciidoctor/standoc/table.rb
metanorma-standoc-1.4.2 lib/asciidoctor/standoc/table.rb
metanorma-standoc-1.4.1 lib/asciidoctor/standoc/table.rb