class Sablon::HTMLConverter::Table

Builds a table from html table tags

Constants

PROPERTIES

Public Class Methods

new(env, node, properties) click to toggle source
Calls superclass method Sablon::HTMLConverter::Node::new
# File lib/sablon/html/ast.rb, line 295
def initialize(env, node, properties)
  super

  # Process properties
  properties = self.class.process_properties(properties)
  @properties = NodeProperties.table(properties)
  trans_props = transferred_properties

  # Pull out the caption node if it exists and convert it separately.
  # If multiple caption tags are defined, only the first one is kept.
  @caption = node.xpath('./caption').remove
  @caption = nil if @caption.empty?
  if @caption
    cap_side_pat = /caption-side: ?(top|bottom)/
    @cap_side = @caption.attr('style').to_s.match(cap_side_pat).to_a[1]
    node.add_previous_sibling @caption
    @caption = ASTBuilder.html_to_ast(env, @caption, trans_props)[0]
  end

  # convert remaining child nodes and pass on transferrable properties
  @children = ASTBuilder.html_to_ast(env, node.children, trans_props)
  @children = Collection.new(@children)
end

Public Instance Methods

accept(visitor) click to toggle source
Calls superclass method Sablon::HTMLConverter::Node#accept
# File lib/sablon/html/ast.rb, line 330
def accept(visitor)
  super
  @children.accept(visitor)
end
inspect() click to toggle source
# File lib/sablon/html/ast.rb, line 335
def inspect
  if @caption && @cap_side == 'bottom'
    "<Table{#{@properties.inspect}}: #{@children.inspect}, #{@caption.inspect}>"
  elsif @caption
    "<Table{#{@properties.inspect}}: #{@caption.inspect}, #{@children.inspect}>"
  else
    "<Table{#{@properties.inspect}}: #{@children.inspect}>"
  end
end
to_docx() click to toggle source
Calls superclass method Sablon::HTMLConverter::Node#to_docx
# File lib/sablon/html/ast.rb, line 319
def to_docx
  if @caption && @cap_side == 'bottom'
    super('w:tbl') + @caption.to_docx
  elsif @caption
    # caption always goes above table unless explicitly set to "bottom"
    @caption.to_docx + super('w:tbl')
  else
    super('w:tbl')
  end
end

Private Instance Methods

children_to_docx() click to toggle source
# File lib/sablon/html/ast.rb, line 347
def children_to_docx
  @children.to_docx
end