Class: PDFGen::Table
- Inherits:
-
BaseRegion
- Object
- BaseRegion
- PDFGen::Table
- Defined in:
- lib/table.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#repeat_footer_on_each_page ⇒ Object
Returns the value of attribute repeat_footer_on_each_page.
-
#repeat_header_on_each_page ⇒ Object
Returns the value of attribute repeat_header_on_each_page.
Attributes inherited from BaseRegion
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
- #align_cell_in_row ⇒ Object
- #body(style = nil, &initialization_block) ⇒ Object
- #calculate_minimal_height ⇒ Object
- #footer(style = nil, &initialization_block) ⇒ Object
- #header(style = nil, &initialization_block) ⇒ Object
- #init_width(parent) ⇒ Object
-
#initialize(parent) ⇒ Table
constructor
A new instance of Table.
- #render(pos, av_height, test = false) ⇒ Object
- #title(style = nil, &initialization_block) ⇒ Object
- #width=(value) ⇒ Object
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
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) = Div.new(self) init_width(parent) @repeat_header_on_each_page = false = false end |
Instance Attribute Details
#repeat_footer_on_each_page ⇒ Object
Returns the value of attribute repeat_footer_on_each_page.
36 37 38 |
# File 'lib/table.rb', line 36 def end |
#repeat_header_on_each_page ⇒ Object
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_row ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/table.rb', line 38 def align_cell_in_row [@header,@body,].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_height ⇒ Object
46 47 48 |
# File 'lib/table.rb', line 46 def calculate_minimal_height [@title,@header,@body,].inject(0){ |height, region| height + region.height } end |
#footer(style = nil, &initialization_block) ⇒ Object
103 104 105 |
# File 'lib/table.rb', line 103 def (style = nil, &initialization_block) access_region(, 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] = .render([pos_x, pos_y], pos_y, true) if [0] > pos[1] return [av_height-pos_y, false] end if status[1] = .render([pos_x, pos_y], pos_y) else if = .render([pos_x, pos_y], pos_y) .reset_count_rendered_regions end end pos_y -= [0] if [av_height-pos_y, status[1] && [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,].each do |region| region.width = value end super end |