class Docxi::Word::Contents::Table

Attributes

options[RW]
rows[RW]

Public Class Methods

new(options={}) { |self| ... } click to toggle source
# File lib/docxi/word/contents/table.rb, line 8
def initialize(options={})
  @options = options
  @rows = []

  if block_given?
    yield self
  else

  end
end

Public Instance Methods

render(xml) click to toggle source
# File lib/docxi/word/contents/table.rb, line 26
def render(xml)
  xml['w'].tbl do
    xml['w'].tblPr do
      xml['w'].tblStyle( 'w:val' => options[:style] ) if options[:style]
      xml['w'].tblW( 'w:w' => options[:width], 'w:type' => "auto" ) if options[:width]
      xml['w'].jc( 'w:val' => options[:align] ) if options[:align]
      xml['w'].tblInd( 'w:w' => options[:iwidth], 'w:type' => "dxa" ) if options[:iwidth]
      xml['w'].tblLook( 'w:val' => "04A0", 'w:firstRow' => 1, 'w:lastRow' => 0, 'w:firstColumn' => 1, 'w:lastColumn' => 0, 'w:noHBand' => 0, 'w:noVBand' => 1 )
      if @options[:borders]
        xml['w'].tblBorders do
          @options[:borders].each do |k, v|
            if v.nil?
              xml['w'].send(k, 'w:val' => "none", 'w:sz' => "0", 'w:space' => "0", 'w:color' => "auto" )
            else
              xml['w'].send(k, 'w:val' => "none", 'w:sz' => v, 'w:space' => "0", 'w:color' => "auto" )
            end
          end
        end
      end
      if @options[:padding]
        xml['w'].tblCellMar do
          xml['w'].top( 'w:w' => "288", 'w:type' => "dxa" )
          xml['w'].left( 'w:w' => "573", 'w:type' => "dxa" )
          xml['w'].bottom( 'w:w' => "288", 'w:type' => "dxa" )
          xml['w'].right( 'w:w' => "573", 'w:type' => "dxa" )
        end
      end

    end
    xml['w'].tblGrid do
      if options[:columns_width]
        options[:columns_width].each do |width|
          xml['w'].gridCol( 'w:w' => width.to_i * 14.92 )
        end
      end
    end
    @rows.each do |row|
      row.render(xml)
    end
  end
end
tr(options={}, &block) click to toggle source
# File lib/docxi/word/contents/table.rb, line 19
def tr(options={}, &block)
  options = @options.merge(options)
  row = TableRow.new(options, &block)
  @rows << row
  row
end