From 8ad8bb9083047fcf8ebabc8fc1d7e846b5e28e14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0ar=C5=ABnas=20Navickas?= Date: Sat, 23 Mar 2024 00:13:06 +0200 Subject: [PATCH 1/4] Include additional company fields --- lib/receipts/base.rb | 22 ++++++++++--------- test/test_receipts.rb | 51 +++++++++++++++++++++++++++++-------------- 2 files changed, 47 insertions(+), 26 deletions(-) diff --git a/lib/receipts/base.rb b/lib/receipts/base.rb index 444ae45..9e7e518 100644 --- a/lib/receipts/base.rb +++ b/lib/receipts/base.rb @@ -7,7 +7,7 @@ class << self 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) @@ -31,8 +31,8 @@ def generate_from(attributes) def setup_fonts(custom_font = nil) if !!custom_font - font_families.update "Primary" => custom_font - font "Primary" + font_families.update 'Primary' => custom_font + font 'Primary' end font_size 8 @@ -40,7 +40,7 @@ def setup_fonts(custom_font = nil) def load_image(logo) if logo.is_a? String - logo.start_with?("http") ? URI.parse(logo).open : File.open(logo) + logo.start_with?('http') ? URI.parse(logo).open : File.open(logo) else logo end @@ -50,7 +50,7 @@ def header(company: {}, height: 16) logo = company[:logo] if logo.nil? - text company.fetch(:name), align: :right, style: :bold, size: 16, color: "4b5563" + text company.fetch(:name), align: :right, style: :bold, size: 16, color: '4b5563' else image load_image(logo), height: height, position: :right end @@ -61,13 +61,15 @@ def header(company: {}, height: 16) def render_details(details, margin_top: 16) move_down margin_top - table(details, cell_style: {borders: [], inline_format: true, padding: [0, 8, 2, 0]}) + table(details, cell_style: { borders: [], inline_format: true, padding: [0, 8, 2, 0] }) end def render_billing_details(company:, recipient:, margin_top: 16) move_down margin_top company_details = [ + company[:company_code], + company[:iban], company[:address], company[:phone], company[:email] @@ -75,11 +77,11 @@ def render_billing_details(company:, recipient:, margin_top: 16) line_items = [ [ - {content: "#{company.fetch(:name)}\n#{company_details}", padding: [0, 12, 0, 0]}, - {content: Array(recipient).join("\n"), padding: [0, 12, 0, 0]} + { content: "#{company.fetch(:name)}\n#{company_details}", padding: [0, 12, 0, 0] }, + { content: Array(recipient).join("\n"), padding: [0, 12, 0, 0] } ] ] - table(line_items, width: bounds.width, cell_style: {borders: [], inline_format: true, overflow: :expand}) + table(line_items, width: bounds.width, cell_style: { borders: [], inline_format: true, overflow: :expand }) end def render_line_items(line_items:, margin_top: 30, column_widths: nil) @@ -89,7 +91,7 @@ def render_line_items(line_items:, margin_top: 30, column_widths: nil) table_options = { width: bounds.width, - cell_style: {border_color: "eeeeee", inline_format: true}, + cell_style: { border_color: 'eeeeee', inline_format: true }, column_widths: column_widths }.compact diff --git a/test/test_receipts.rb b/test/test_receipts.rb index 3b03be9..8cd2cfc 100644 --- a/test/test_receipts.rb +++ b/test/test_receipts.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require "test_helper" +require 'test_helper' class TestReceipts < Minitest::Test def test_without_arguments @@ -18,16 +18,16 @@ def test_renderable def test_receipt_with_arguments assert_instance_of Receipts::Receipt, Receipts::Receipt.new( company: { - name: "Company", - address: "123 Street", - email: "company@example.org" + name: 'Company', + address: '123 Street', + email: 'company@example.org' }, recipient: [], details: [ - ["Receipt", "123"] + %w[Receipt 123] ], line_items: [ - ["Product", "$10"] + ['Product', '$10'] ] ) end @@ -35,16 +35,35 @@ def test_receipt_with_arguments def test_invoice_with_arguments assert_instance_of Receipts::Invoice, Receipts::Invoice.new( company: { - name: "Company", - address: "123 Street", - email: "company@example.org" + name: 'Company', + address: '123 Street', + email: 'company@example.org' }, recipient: [], details: [ - ["Receipt", "123"] + %w[Receipt 123] ], line_items: [ - ["Product", "$10"] + ['Product', '$10'] + ] + ) + end + + def test_invoice_with_additional_company_data + assert_instance_of Receipts::Invoice, Receipts::Invoice.new( + company: { + name: 'Company', + address: '123 Street', + email: 'company@example.org', + company_code: '000123', + iban: 'LT241997677264666618' + }, + recipient: [], + details: [ + %w[Receipt 123] + ], + line_items: [ + ['Product', '$10'] ] ) end @@ -52,16 +71,16 @@ def test_invoice_with_arguments def test_statement_with_arguments assert_instance_of Receipts::Statement, Receipts::Statement.new( company: { - name: "Company", - address: "123 Street", - email: "company@example.org" + name: 'Company', + address: '123 Street', + email: 'company@example.org' }, recipient: [], details: [ - ["Receipt", "123"] + %w[Receipt 123] ], line_items: [ - ["Product", "$10"] + ['Product', '$10'] ] ) end From 13ba6eb067ad6950a1cfbf026028808d89544702 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0ar=C5=ABnas=20Navickas?= <606346+zaibacu@users.noreply.github.com> Date: Sat, 23 Mar 2024 00:18:11 +0200 Subject: [PATCH 2/4] Rollback styling changes Remove opinions done by editor --- test/test_receipts.rb | 46 +++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/test/test_receipts.rb b/test/test_receipts.rb index 8cd2cfc..f12efb6 100644 --- a/test/test_receipts.rb +++ b/test/test_receipts.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'test_helper' +require "test_helper" class TestReceipts < Minitest::Test def test_without_arguments @@ -18,16 +18,16 @@ def test_renderable def test_receipt_with_arguments assert_instance_of Receipts::Receipt, Receipts::Receipt.new( company: { - name: 'Company', - address: '123 Street', - email: 'company@example.org' + name: "Company", + address: "123 Street", + email: "company@example.org" }, recipient: [], details: [ - %w[Receipt 123] + [Receipt 123] ], line_items: [ - ['Product', '$10'] + ["Product", "$10"] ] ) end @@ -35,16 +35,16 @@ def test_receipt_with_arguments def test_invoice_with_arguments assert_instance_of Receipts::Invoice, Receipts::Invoice.new( company: { - name: 'Company', - address: '123 Street', - email: 'company@example.org' + name: "Company", + address: "123 Street", + email: "company@example.org" }, recipient: [], details: [ - %w[Receipt 123] + [Receipt 123] ], line_items: [ - ['Product', '$10'] + ["Product", "$10"] ] ) end @@ -52,18 +52,18 @@ def test_invoice_with_arguments def test_invoice_with_additional_company_data assert_instance_of Receipts::Invoice, Receipts::Invoice.new( company: { - name: 'Company', - address: '123 Street', - email: 'company@example.org', - company_code: '000123', - iban: 'LT241997677264666618' + name: "Company", + address: "123 Street", + email: "company@example.org", + company_code: "000123", + iban: "LT241997677264666618" }, recipient: [], details: [ - %w[Receipt 123] + [Receipt 123] ], line_items: [ - ['Product', '$10'] + ["Product", "$10"] ] ) end @@ -71,16 +71,16 @@ def test_invoice_with_additional_company_data def test_statement_with_arguments assert_instance_of Receipts::Statement, Receipts::Statement.new( company: { - name: 'Company', - address: '123 Street', - email: 'company@example.org' + name: "Company", + address: "123 Street", + email: "company@example.org" }, recipient: [], details: [ - %w[Receipt 123] + [Receipt 123] ], line_items: [ - ['Product', '$10'] + ["Product", "$10"] ] ) end From 235ce6544fcdc968dc43be5bbf3ca606ac800c0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0ar=C5=ABnas=20Navickas?= Date: Sat, 23 Mar 2024 00:23:36 +0200 Subject: [PATCH 3/4] ... and now actually fix it --- lib/receipts/base.rb | 22 +++++++++++----------- test/test_receipts.rb | 8 ++++---- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/receipts/base.rb b/lib/receipts/base.rb index 9e7e518..160aae1 100644 --- a/lib/receipts/base.rb +++ b/lib/receipts/base.rb @@ -7,7 +7,7 @@ class << self 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) @@ -31,8 +31,8 @@ def generate_from(attributes) def setup_fonts(custom_font = nil) if !!custom_font - font_families.update 'Primary' => custom_font - font 'Primary' + font_families.update "Primary" => custom_font + font "Primary" end font_size 8 @@ -40,7 +40,7 @@ def setup_fonts(custom_font = nil) def load_image(logo) if logo.is_a? String - logo.start_with?('http') ? URI.parse(logo).open : File.open(logo) + logo.start_with?("http") ? URI.parse(logo).open : File.open(logo) else logo end @@ -50,7 +50,7 @@ def header(company: {}, height: 16) logo = company[:logo] if logo.nil? - text company.fetch(:name), align: :right, style: :bold, size: 16, color: '4b5563' + text company.fetch(:name), align: :right, style: :bold, size: 16, color: "4b5563" else image load_image(logo), height: height, position: :right end @@ -61,7 +61,7 @@ def header(company: {}, height: 16) def render_details(details, margin_top: 16) move_down margin_top - table(details, cell_style: { borders: [], inline_format: true, padding: [0, 8, 2, 0] }) + table(details, cell_style: {borders: [], inline_format: true, padding: [0, 8, 2, 0]}) end def render_billing_details(company:, recipient:, margin_top: 16) @@ -77,11 +77,11 @@ def render_billing_details(company:, recipient:, margin_top: 16) line_items = [ [ - { content: "#{company.fetch(:name)}\n#{company_details}", padding: [0, 12, 0, 0] }, - { content: Array(recipient).join("\n"), padding: [0, 12, 0, 0] } + {content: "#{company.fetch(:name)}\n#{company_details}", padding: [0, 12, 0, 0]}, + {content: Array(recipient).join("\n"), padding: [0, 12, 0, 0]} ] ] - table(line_items, width: bounds.width, cell_style: { borders: [], inline_format: true, overflow: :expand }) + table(line_items, width: bounds.width, cell_style: {borders: [], inline_format: true, overflow: :expand}) end def render_line_items(line_items:, margin_top: 30, column_widths: nil) @@ -91,7 +91,7 @@ def render_line_items(line_items:, margin_top: 30, column_widths: nil) table_options = { width: bounds.width, - cell_style: { border_color: 'eeeeee', inline_format: true }, + cell_style: {border_color: "eeeeee", inline_format: true}, column_widths: column_widths }.compact @@ -111,4 +111,4 @@ def default_message(company:) "For questions, contact us anytime at #{company.fetch(:email)}." end end -end +end \ No newline at end of file diff --git a/test/test_receipts.rb b/test/test_receipts.rb index f12efb6..5be61d2 100644 --- a/test/test_receipts.rb +++ b/test/test_receipts.rb @@ -24,7 +24,7 @@ def test_receipt_with_arguments }, recipient: [], details: [ - [Receipt 123] + ["Receipt", "123"] ], line_items: [ ["Product", "$10"] @@ -41,7 +41,7 @@ def test_invoice_with_arguments }, recipient: [], details: [ - [Receipt 123] + ["Receipt", "123"] ], line_items: [ ["Product", "$10"] @@ -60,7 +60,7 @@ def test_invoice_with_additional_company_data }, recipient: [], details: [ - [Receipt 123] + ["Receipt", "123"] ], line_items: [ ["Product", "$10"] @@ -77,7 +77,7 @@ def test_statement_with_arguments }, recipient: [], details: [ - [Receipt 123] + ["Receipt", "123"] ], line_items: [ ["Product", "$10"] From ca70b799b5ba1a90e9ac512e9ff6ff1502f0cbea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0ar=C5=ABnas=20Navickas?= Date: Sat, 23 Mar 2024 00:27:44 +0200 Subject: [PATCH 4/4] Fix newline --- lib/receipts/base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/receipts/base.rb b/lib/receipts/base.rb index 160aae1..d42a197 100644 --- a/lib/receipts/base.rb +++ b/lib/receipts/base.rb @@ -111,4 +111,4 @@ def default_message(company:) "For questions, contact us anytime at #{company.fetch(:email)}." end end -end \ No newline at end of file +end