class Slaw::Grammars::Tables::Table

Public Instance Methods

to_xml(b, idprefix, i=0) click to toggle source
# File lib/slaw/grammars/tables_nodes.rb, line 5
def to_xml(b, idprefix, i=0)
  cnt = Slaw::Grammars::Counters.counters[idprefix]['table'] += 1

  b.table(eId: "#{idprefix}table_#{cnt}") { |b|
    # we'll gather cells into this row list
    rows = []
    cells = []

    for child in table_body.elements
      if child.is_a? TableCell
        # cell
        cells << child
      else
        # new row marker
        rows << cells unless cells.empty?
        cells = []
      end
    end
    rows << cells unless cells.empty?

    for row in rows
      b.tr { |tr|
        for cell in row
          cell.to_xml(tr, "")
        end
      }
    end
  }
end