Skip to content

Commit

Permalink
Configurable company details (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
excid3 committed Mar 26, 2024
1 parent af703af commit 58e37fd
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 7 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,22 @@
### Unreleased

* Add `display: []` for configuring company details that are rendered

```ruby
r = Receipts::Receipt.new(
company: {
name: "Example, LLC",
address: "123 Fake Street\nNew York City, NY 10012",
phone: "(555) 867-5309",
email: "support@example.com",
iban: "123456789",
logo: File.expand_path("./examples/images/logo.png"),
display: [:address, :phone, :email, :iban]
},
# ...
)
```

### 2.3.0

* Add `column_widths:` option to specify line item column widths #35
Expand Down
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -107,6 +107,8 @@ You can pass the following options to generate a PDF:
logo: "https://www.ruby-lang.org/images/header-ruby-logo@2x.png" # Downloaded with OpenURI
```

* `display: []` - Customize the company details rendered. By default, renders `[:address, :phone, :email]` under the company name. Items in the array should be Symbols matching keys in the `company` hash to be displayed.

* `details` - Array of details about the Receipt, Invoice, Statement. Typically, this is receipt numbers, issue date, due date, status, etc.

* `line_items` - Array of line items to be displayed in table format.
Expand Down
4 changes: 3 additions & 1 deletion Rakefile
Expand Up @@ -36,7 +36,9 @@ task :receipt do
address: "123 Fake Street\nNew York City, NY 10012",
phone: "(555) 867-5309",
email: "support@example.com",
logo: File.expand_path("./examples/images/logo.png")
iban: "123456789",
logo: File.expand_path("./examples/images/logo.png"),
display: [:address, :phone, :email, nil, :iban]
},
details: [
["Receipt Number", "123"],
Expand Down
Binary file modified examples/invoice.pdf
Binary file not shown.
Binary file modified examples/receipt.pdf
Binary file not shown.
Binary file modified examples/statement.pdf
Binary file not shown.
9 changes: 3 additions & 6 deletions lib/receipts/base.rb
Expand Up @@ -64,14 +64,11 @@ def render_details(details, margin_top: 16)
table(details, cell_style: {borders: [], inline_format: true, padding: [0, 8, 2, 0]})
end

def render_billing_details(company:, recipient:, margin_top: 16)
def render_billing_details(company:, recipient:, margin_top: 16, display_values: nil)
move_down margin_top

company_details = [
company[:address],
company[:phone],
company[:email]
].compact.join("\n")
display_values ||= company.fetch(:display, [:address, :phone, :email])
company_details = company.values_at(*display_values).compact.join("\n")

line_items = [
[
Expand Down

0 comments on commit 58e37fd

Please sign in to comment.