Module: Prawn::Table::Interface
- Defined in:
- lib/barkest_core/extensions/prawn_table_extensions.rb
Overview
Improvements made to the Prawn::Table::Interface module.
Instance Method Summary collapse
- #barkest_core_original_make_table ⇒ Object
- #barkest_core_original_table ⇒ Object
-
#make_table(data, options = {}, &block) ⇒ Object
This is the same as #table except the table is not rendered after construction.
-
#table(data, options = {}, &block) ⇒ Object
An overridden version of the table method allowing for more powerful options and dynamic data.
-
#table_builder(options = {}, &block) ⇒ Object
Uses a TableBuilder to construct a table and then renders the results to the PDF.
-
#table_pair(label, value, shared_attribs = {}) ⇒ Object
Generates an array containing a label cell and a value cell.
Instance Method Details
#barkest_core_original_make_table ⇒ Object
87 |
# File 'lib/barkest_core/extensions/prawn_table_extensions.rb', line 87 alias :barkest_core_original_make_table :make_table |
#barkest_core_original_table ⇒ Object
58 |
# File 'lib/barkest_core/extensions/prawn_table_extensions.rb', line 58 alias :barkest_core_original_table :table |
#make_table(data, options = {}, &block) ⇒ Object
This is the same as #table except the table is not rendered after construction.
92 93 94 95 96 97 |
# File 'lib/barkest_core/extensions/prawn_table_extensions.rb', line 92 def make_table(data, = {}, &block) = () data = preprocess_table_data(data) Prawn::Table.new(data, self, , &block) end |
#table(data, options = {}, &block) ⇒ Object
An overridden version of the table method allowing for more powerful options and dynamic data.
The data
gains the ability to receive values from a linked object. Much like form helpers, if you specify :name for a cell value, and there is a linked object, the linked object will be searched for a :name attribute. If that exists, then the value of the attribute is used, otherwise the symbol is converted to a string and that value is used.
The options
hash gains :column_ratios and :width_ratio keys that automatically set the :column_widths and :width keys based on the current bounding box.
{ :column_rations => [ 5, 25, 10, 10 ], :width_ratio => 50 }
A potential weakness would be that the :column_ratios are a percentage of the maximum width, not the table width. In the example above, the table is 50% of the maximum width and the column widths add up to 50%.
After the table is constructed, it is rendered to the PDF.
78 79 80 81 82 83 84 85 |
# File 'lib/barkest_core/extensions/prawn_table_extensions.rb', line 78 def table(data, = {}, &block) = () data = preprocess_table_data(data) t = Prawn::Table.new(data, self, , &block) t.draw t end |
#table_builder(options = {}, &block) ⇒ Object
Uses a TableBuilder to construct a table and then renders the results to the PDF.
102 103 104 105 106 |
# File 'lib/barkest_core/extensions/prawn_table_extensions.rb', line 102 def table_builder( = {}, &block) t = BarkestCore::PdfTableBuilder.new(self, , &block).to_table t.draw t end |
#table_pair(label, value, shared_attribs = {}) ⇒ Object
Generates an array containing a label cell and a value cell.
The label cell has a bold font, the value cell does not. Both cells inherit the shared_attribs.
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/barkest_core/extensions/prawn_table_extensions.rb', line 114 def table_pair(label, value, shared_attribs = {}) bold_label = ({ bold_label: true }.merge(shared_attribs))[:bold_label] shared_attribs.except!(:bold_label) label = preprocess_table_data(label) value = preprocess_table_data(value) label = shared_attribs.merge(label.is_a?(Hash) ? label : { content: label }) value = shared_attribs.merge(value.is_a?(Hash) ? value : { content: value }) if bold_label label = label.merge({ font_style: :bold }) end [ label, value ] end |