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)

  self.width = parent.av_width
  
  @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.



33
34
35
# File 'lib/table.rb', line 33

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.



33
34
35
# File 'lib/table.rb', line 33

def repeat_header_on_each_page
  @repeat_header_on_each_page
end

Instance Method Details

#align_cell_in_rowObject



35
36
37
38
39
40
41
# File 'lib/table.rb', line 35

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



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

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

#calculate_minimal_heightObject



43
44
45
# File 'lib/table.rb', line 43

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


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

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

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



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

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

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



47
48
49
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
# File 'lib/table.rb', line 47

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



88
89
90
# File 'lib/table.rb', line 88

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

#width=(value) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/table.rb', line 25

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

  super
end