Class: Booky::Layout::Base::Tof

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

Constant Summary collapse

OPTIONS =
{
  :align => :right,
  :size => 24
}

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



10
11
12
13
14
15
16
# File 'lib/booky/layout/base/tof.rb', line 10

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

#create_tofObject



18
19
20
21
22
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
56
57
58
# File 'lib/booky/layout/base/tof.rb', line 18

def create_tof
  tof_data = Booky::Layout.config.tof.map do |entry|
    
    # Cells
    id = make_cell(
      :content        => "<link anchor='page#{entry[:page]}'>#{entry[:id]}.</link>",
      :size           => 14, 
      :font_style     => :italic, 
      :border_width   => 1, 
      :borders        => [:bottom]
    )
    text = make_cell(
      :content        => entry[:text], 
      :size           => 12,
      :align          => :justify,
      :font_style     => :normal, 
      :border_width   => 1, 
      :borders        => [:bottom]
    )
    page = make_cell(
      :content        => "<link anchor='page#{entry[:page]}'>Page #{entry[:page]}</link>", 
      :align          => :right,
      :font_style     => :italic,
      :border_width   => 1, 
      :borders        => [:bottom]
    )
    
    [id, text, page]
  end
  
  # Table
  table(tof_data, 
    :width => bounds.width, 
    :column_widths => { 1 => 330 }, 
    :cell_style => { 
      :inline_format => true, 
      :border_color => Booky::Layout::Base::COLORS[2], 
      :border_width => 0.5
    }
  )
end

#to_prawnObject



61
62
63
64
65
66
67
68
69
70
# File 'lib/booky/layout/base/tof.rb', line 61

def to_prawn
  start_new_page
  
  Booky::Layout.config.current_chapter = 0
  update_levels(0)
  add_to_toc(0)
  
  create_heading
  create_tof
end