Class: Booky::Layout::Base::Table

Inherits:
Element
  • Object
show all
Includes:
Helpers
Defined in:
lib/booky/layout/base/table.rb

Constant Summary collapse

OPTIONS =
{
  :align => :left,
  :size => 12
}

Instance Attribute Summary

Attributes inherited from Element

#ast, #document, #index, #options

Instance Method Summary collapse

Methods included from Helpers

#add_to_toc, #is_first_rendering?, #update_levels

Methods inherited from Element

#initialize, #method_missing, #next_option, #previous_option

Constructor Details

This class inherits a constructor from Booky::Layout::Element

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Booky::Layout::Element

Instance Method Details

#create_headingObject



14
15
16
17
18
19
20
21
# File 'lib/booky/layout/base/table.rb', line 14

def create_heading
  return unless @options[:title]
  
  fill_color Booky::Layout::Base::COLORS[1]
  text @options[:title], OPTIONS
  fill_color Booky::Layout::Base::COLORS[0]
  move_down 0.5.cm
end

#start_new_page_if_neededObject



10
11
12
# File 'lib/booky/layout/base/table.rb', line 10

def start_new_page_if_needed
  start_new_page if cursor < (bounds.bottom + 4.cm)
end

#to_prawnObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/booky/layout/base/table.rb', line 23

def to_prawn
  start_new_page_if_needed
  
  data = @options[:rows].map do |row|
    is_first   = row == @options[:rows].first
    is_last    = row == @options[:rows].last
    is_header  = is_first and @options[:header]
    
    row.map do |cell|
      make_cell(
        :content        => cell[:text],
        :size           => 10, 
        :font_style     => is_header ? :normal : :italic, 
        :border_width   => 1, 
        :borders        => is_last ? [] : [:bottom]
      )
    end
  end
  
  create_heading
  
  table(data,
    :header => @options[:header],
    :width => bounds.width,
    :row_colors => ['FFFFFF', Booky::Layout::Base::COLORS[3]],
    :cell_style => { 
      :inline_format => true, 
      :border_color => Booky::Layout::Base::COLORS[2], 
      :border_width => 0.5
    }
  )
  move_down 1.cm
end