class Rabbit::RT2RabbitVisitor

Public Class Methods

new(rd_visitor) click to toggle source
# File lib/rabbit/parser/rd/rt/rt2rabbit-lib.rb, line 9
def initialize(rd_visitor)
  @rd_visitor = rd_visitor
end

Public Instance Methods

visit(parsed) click to toggle source
# File lib/rabbit/parser/rd/rt/rt2rabbit-lib.rb, line 13
def visit(parsed)
  @rt = parsed
  @header = @rt.header
  @body = @rt.body
  @caption = @rt.config['caption']

  process
end

Private Instance Methods

each_cell(ary) { |x| ... } click to toggle source
# File lib/rabbit/parser/rd/rt/rt2rabbit-lib.rb, line 62
def each_cell(ary)
  ary.each do |x|
    if x.is_a?(RT::RTCell)
      yield x
    end
  end
end
process() click to toggle source
# File lib/rabbit/parser/rd/rt/rt2rabbit-lib.rb, line 23
def process
  props = {
    "caption" => @caption
  }
  table = Element::Table.new(props)
  process_header(table)
  process_body(table)
  table
end
process_block(table, targets, block_class, cell_class) click to toggle source
# File lib/rabbit/parser/rd/rt/rt2rabbit-lib.rb, line 33
def process_block(table, targets, block_class, cell_class)
  return if targets.empty?
  block = block_class.new
  targets.each do |r|
    row = Element::TableRow.new
    each_cell(r) do |c|
      tree = ::RD::RDTree.new("=begin\n#{c.value}\n=end\n")
      if tree.root.children.empty?
        elements = []
      else
        elements = tree.root.children[0].accept(@rd_visitor).elements
      end
      cell = cell_class.new(elements)
      setup_text_align(cell, c.align)
      row << cell
    end
    block << row
  end
  table << block
end
process_body(table) click to toggle source
# File lib/rabbit/parser/rd/rt/rt2rabbit-lib.rb, line 58
def process_body(table)
  process_block(table, @body, Element::TableBody, Element::TableCell)
end
process_header(table) click to toggle source
# File lib/rabbit/parser/rd/rt/rt2rabbit-lib.rb, line 54
def process_header(table)
  process_block(table, @header, Element::TableHead, Element::TableHeader)
end
setup_text_align(target, align) click to toggle source
# File lib/rabbit/parser/rd/rt/rt2rabbit-lib.rb, line 70
def setup_text_align(target, align)
  case align
  when :center
    def target.default_align
      Pango::Alignment::CENTER
    end
  when :right
    def target.default_align
      Pango::Alignment::RIGHT
    end
  else
    def target.default_align
      Pango::Alignment::LEFT
    end
  end
  target.align = target.default_align
end