Class: PDFGen::Table

Inherits:
BaseRegion show all
Defined in:
lib/table.rb

Direct Known Subclasses

SmartTable

Instance Attribute Summary collapse

Attributes inherited from BaseRegion

#parent

Attributes included from BaseAttributes

#background_color, #border_bottom, #border_color, #border_left, #border_right, #border_style, #border_top, #border_width, #height, #is_breakable, #pad_bottom, #pad_left, #pad_right, #pad_top, #page_pad_top, #width

Instance Method Summary collapse

Methods inherited from BaseRegion

#check_fit_in_height, #document, #minimal_height, #set_properties, #value

Methods included from BaseAttributes

#av_width, #border=, #border_params, #breakable?, included, #paddings=, #var_init

Methods included from BaseAttributes::ClassMethods

#common_setter

Constructor Details

#initialize(parent) ⇒ Table

Returns a new instance of Table.



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/table.rb', line 10

def initialize(parent)
  super(parent)
  @is_breakable = true
  @title = Div.new(self)
  @header = Div.new(self)
  @body = Div.new(self)
  @footer = Div.new(self)
  
  init_width(parent)
  
  @repeat_header_on_each_page = false
  @repeat_footer_on_each_page = false
end

Instance Attribute Details

Returns the value of attribute repeat_footer_on_each_page.



36
37
38
# File 'lib/table.rb', line 36

def repeat_footer_on_each_page
  @repeat_footer_on_each_page
end

#repeat_header_on_each_pageObject

Returns the value of attribute repeat_header_on_each_page.



36
37
38
# File 'lib/table.rb', line 36

def repeat_header_on_each_page
  @repeat_header_on_each_page
end

Instance Method Details

#align_cell_in_rowObject



38
39
40
41
42
43
44
# File 'lib/table.rb', line 38

def align_cell_in_row
  [@header,@body,@footer].each do |container|
    container.regions.each do |row|
      row.vertical_align = true if row.respond_to?(:vertical_align)
    end
  end
end

#body(style = nil, &initialization_block) ⇒ Object



99
100
101
# File 'lib/table.rb', line 99

def body(style = nil, &initialization_block)
  access_region(@body, style, &initialization_block)
end

#calculate_minimal_heightObject



46
47
48
# File 'lib/table.rb', line 46

def calculate_minimal_height
  [@title,@header,@body,@footer].inject(0){ |height, region| height + region.height }
end


103
104
105
# File 'lib/table.rb', line 103

def footer(style = nil, &initialization_block)
  access_region(@footer, style, &initialization_block)
end

#header(style = nil, &initialization_block) ⇒ Object



95
96
97
# File 'lib/table.rb', line 95

def header(style = nil, &initialization_block)
  access_region(@header, style, &initialization_block)
end

#init_width(parent) ⇒ Object



24
25
26
# File 'lib/table.rb', line 24

def init_width(parent)
  self.width = parent.width - parent.pad_left - parent.pad_right
end

#render(pos, av_height, test = false) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/table.rb', line 50

def render(pos, av_height, test=false)
  align_cell_in_row
  super
  
  pos_x, pos_y = pos
  title_height = @title.render([pos_x, pos_y], pos_y, true)
  header_height = @header.render([pos_x, pos_y], pos_y, true)

  if (title_height[0] + header_height[0]) > av_height
    return [0, false]
  end

  title_status = @title.render([pos_x, pos_y], pos_y)
  pos_y -= title_status[0]
  @header.reset_count_rendered_regions if @repeat_header_on_each_page
  header_status = @header.render([pos_x, pos_y], pos_y)
  pos_y -= header_status[0]

  status = @body.render([pos_x, pos_y], pos_y)
  pos_y -= status[0]

  footer_height = @footer.render([pos_x, pos_y], pos_y, true)
  if footer_height[0] > pos[1]
    return [av_height-pos_y, false]
  end

  if status[1]
    footer_status = @footer.render([pos_x, pos_y], pos_y)
  else
    if @repeat_footer_on_each_page
      footer_status = @footer.render([pos_x, pos_y], pos_y)

      @footer.reset_count_rendered_regions
    end
  end
  pos_y -= footer_status[0] if footer_status

  [av_height-pos_y, status[1] && footer_status[1]]
end

#title(style = nil, &initialization_block) ⇒ Object



91
92
93
# File 'lib/table.rb', line 91

def title(style = nil, &initialization_block)
  access_region(@title, style, &initialization_block)
end

#width=(value) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/table.rb', line 28

def width=(value)
  [@title,@header,@body,@footer].each do |region|
    region.width = value
  end

  super
end