require 'rabbit/element/text-container-element' require 'rabbit/element/container-element' require 'rabbit/element/block-element' module Rabbit module Element class Table include ContainerElement include BlockElement attr_reader :caption def initialize(prop={}) super() %w(caption).each do |name| instance_variable_set("@#{name}", prop[name]) end end def head elements.find {|e| e.is_a?(TableHead)} end def body elements.find {|e| e.is_a?(TableBody)} end alias container_text text def text result = '' result << "#{@caption}\n" if @caption result << super result end def to_rd result = "# RT\n" result << "caption = #{@caption}\n" if @caption result << "\n" result << container_text result.gsub(/^/, " ") end def to_html(generator) caption = nil caption = "#{@caption}\n" if @caption "\n#{caption}#{super}\n
" end end class TableHead include ContainerElement include BlockElement def text "#{super}\n" end def to_html(generator) "\n#{super}\n" end end class TableBody include ContainerElement include BlockElement def to_html(generator) "\n#{super}\n" end end class TableRow include ContainerElement include BlockElement def text super.gsub(/\n/, ", ") end def to_rd text end def to_html(generator) "\n#{super}\n" end end class TableHeader include TextContainerElement def to_html(generator) "#{super}" end end class TableCell include TextContainerElement def to_html(generator) "#{super}" end end end end