lib/receipts/base.rb in receipts-2.2.0 vs lib/receipts/base.rb in receipts-2.3.0
- old
+ new
@@ -5,11 +5,11 @@
class << self
attr_reader :title
end
def initialize(attributes = {})
- super page_size: attributes.delete(:page_size) || "LETTER"
+ super(page_size: attributes.delete(:page_size) || "LETTER")
setup_fonts attributes.fetch(:font, Receipts.default_font)
@title = attributes.fetch(:title, self.class.title)
generate_from(attributes)
@@ -20,11 +20,14 @@
company = attributes.fetch(:company)
header company: company, height: attributes.fetch(:logo_height, 16)
render_details attributes.fetch(:details)
render_billing_details company: company, recipient: attributes.fetch(:recipient)
- render_line_items attributes.fetch(:line_items)
+ render_line_items(
+ line_items: attributes.fetch(:line_items),
+ column_widths: attributes[:column_widths]
+ )
render_footer attributes.fetch(:footer, default_message(company: company))
end
def setup_fonts(custom_font = nil)
if !!custom_font
@@ -77,14 +80,21 @@
]
]
table(line_items, width: bounds.width, cell_style: {borders: [], inline_format: true, overflow: :expand})
end
- def render_line_items(line_items, margin_top: 30)
+ def render_line_items(line_items:, margin_top: 30, column_widths: nil)
move_down margin_top
borders = line_items.length - 2
- table(line_items, width: bounds.width, cell_style: {border_color: "eeeeee", inline_format: true}) do
+
+ table_options = {
+ width: bounds.width,
+ cell_style: {border_color: "eeeeee", inline_format: true},
+ column_widths: column_widths
+ }.compact
+
+ table(line_items, table_options) do
cells.padding = 6
cells.borders = []
row(0..borders).borders = [:bottom]
end
end