class Proforma::PrawnRenderer::TableRenderer
This class understands how to ender a Proforma::Modeling::Table component.
Public Instance Methods
render(table)
click to toggle source
# File lib/proforma/prawn_renderer/table_renderer.rb, line 16 def render(table) prototype_row = table.header.rows.first column_widths = prototype_row ? make_column_widths(prototype_row) : {} pdf.table( make_all_rows(table), column_widths: column_widths, width: total_width ) end
Private Instance Methods
body_cell_style()
click to toggle source
# File lib/proforma/prawn_renderer/table_renderer.rb, line 69 def body_cell_style @body_cell_style ||= cell_style.merge( borders: %i[top bottom] ) end
cell_style()
click to toggle source
# File lib/proforma/prawn_renderer/table_renderer.rb, line 59 def cell_style @cell_style ||= { border_width: 0.5, min_font_size: 1, overflow: :shrink_to_fit, padding: 3, size: text_font_size } end
header_cell_style()
click to toggle source
# File lib/proforma/prawn_renderer/table_renderer.rb, line 75 def header_cell_style @header_cell_style ||= cell_style.merge( background_color: 'D3D3D3', borders: [], font_style: bold_font_style ) end
make_all_rows(table)
click to toggle source
# File lib/proforma/prawn_renderer/table_renderer.rb, line 29 def make_all_rows(table) make_rows(table.header, header_cell_style) + make_rows(table.body, body_cell_style) + make_rows(table.footer, footer_cell_style) end
make_column_widths(row)
click to toggle source
# File lib/proforma/prawn_renderer/table_renderer.rb, line 47 def make_column_widths(row) column_widths = {} row.cells.each_with_index do |cell, index| next unless cell.width column_widths[index] = calculate_width(cell.width) end column_widths end
make_rows(section, cell_style)
click to toggle source
# File lib/proforma/prawn_renderer/table_renderer.rb, line 35 def make_rows(section, cell_style) section.rows.map do |row| row.cells.map do |cell| immediate_style = { align: cell.align.to_s.to_sym } pdf.make_cell(cell.text.to_s, cell_style.merge(immediate_style)) end end end