receipts 2.1.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a0b0deba0350c50dd06db780729513d9c65d020c9d625b3c61c174078738ef44
4
- data.tar.gz: 6b508e3232031df8d6952b9c2da80d5910022b2b53ba29e54f84080c12d522da
3
+ metadata.gz: 1606d916a395c1e22c80566221f2db3ad1ed035ec3d426d2500b4beffe1f0f8d
4
+ data.tar.gz: a5d29e51729f90104dceb3ff6faf6a4b3a27f7a404789664895821e62b416752
5
5
  SHA512:
6
- metadata.gz: f734ad542b0405e91370fd960ab93283bd493cdd0523900b6f97a26f91bc8a57834512c7778c551af55e1208c232020743d39b73428bafe118679439838479f0
7
- data.tar.gz: baca857094d744fa1ff47617940a9a665df5fc7da11ebc25e4ac180b9a324b1f00f82f85cfbba09952708e596cbdbe425d73abfab4371f319e7882e3d8dac59e
6
+ metadata.gz: 8a372a3605d3535d4f5fca1bac41a22470541b8717ed51fb8383e0250df0c1a97b7ef104fc388d8e3439572854cb82b925441cb8196336ef6996e411e8b68b2c
7
+ data.tar.gz: 971fe78bd36d9858a45afcdf4035575c51f373f33b1defb9637cde49f38501d322874132e22f06209ed1a05ed6e56a5fe7a1ea56bbbafd49f46977c4214e19b5
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  ### Unreleased
2
2
 
3
+ ### 2.3.0
4
+
5
+ * Add `column_widths:` option to specify line item column widths #35
6
+
7
+ ### 2.2.0
8
+
9
+ * Allow specifiying other page sizes - @excid3
10
+ * Add `logo_height:` option to specify the height of the logo image
11
+
3
12
  ### 2.1.0
4
13
 
5
14
  * Add `Receipts.default_font` - @excid3
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- ![travisci](https://api.travis-ci.org/excid3/receipts.svg)
1
+ [![Tests](https://github.com/excid3/receipts/actions/workflows/ci.yml/badge.svg)](https://github.com/excid3/receipts/actions/workflows/ci.yml)
2
2
 
3
3
  # Receipts Gem
4
4
 
@@ -16,11 +16,15 @@ gem 'receipts'
16
16
 
17
17
  And then execute:
18
18
 
19
- $ bundle
19
+ ```sh
20
+ $ bundle
21
+ ```
20
22
 
21
23
  Or install it yourself as:
22
24
 
23
- $ gem install receipts
25
+ ```sh
26
+ $ gem install receipts
27
+ ```
24
28
 
25
29
  ## Usage
26
30
 
@@ -28,6 +32,7 @@ To generate a Receipt, Invoice, or Statement, create an instance and provide con
28
32
 
29
33
  ```ruby
30
34
  r = Receipts::Receipt.new(
35
+ # title: "Receipt",
31
36
  details: [
32
37
  ["Receipt Number", "123"],
33
38
  ["Date paid", Date.today],
@@ -76,7 +81,6 @@ Receipts.default_font = {
76
81
  }
77
82
  ```
78
83
 
79
-
80
84
  ### Options
81
85
 
82
86
  You can pass the following options to generate a PDF:
@@ -118,16 +122,45 @@ You can pass the following options to generate a PDF:
118
122
  }
119
123
  ```
120
124
 
125
+ * `logo_height` - An integer value of how tall the logo should be. Defaults to `16`
126
+
121
127
  Here's an example of where each option is displayed.
122
128
 
123
129
  ![options](examples/images/options.jpg)
124
130
 
131
+ #### Line Items Table - Column Widths
132
+
133
+ You may set an option to configure the line items table's columns width in order to accommodate shortcomings of Prawn's width guessing ability to render header and content reasonably sized.
134
+ The configuration depends on your line item column count and follows the prawn/table configuration as documented [here](https://prawnpdf.org/prawn-table-manual.pdf):
135
+
136
+ This will size the second column to 400 and the fourth column to 50.
137
+
138
+ ```ruby
139
+ column_widths: {1 => 400,3 => 50 }
140
+ ```
141
+
142
+ This will set all column widths, considering your table has 4 columns.
143
+
144
+ ```ruby
145
+ column_widths: [100, 200, 240]
146
+ ```
147
+
148
+ If not set, it will fall back to Prawn's default behavior.
149
+
125
150
  ### Formatting
126
151
 
127
152
  `details` and `line_items` allow inline formatting with Prawn. This allows you to use HTML tags to format text: `<b>` `<i>` `<u>` `<strikethrough>` `<sub>` `<sup>` `<font>` `<color>` `<link>`
128
153
 
129
154
  See [the Prawn docs](https://prawnpdf.org/api-docs/2.3.0/Prawn/Text.html#text-instance_method) for more information.
130
155
 
156
+ #### Page Size
157
+
158
+ You can specify a different page size by passing in the `page_size` keyword argument:
159
+
160
+ ```ruby
161
+ receipt = Receipts::Receipt.new page_size: "A4"
162
+ ```
163
+
131
164
  ### Internationalization (I18n)
132
165
 
133
166
  You can use `I18n.t` when rendering your receipts to internationalize them.
@@ -205,7 +238,7 @@ class ChargesController < ApplicationController
205
238
  @charge = current_user.charges.find(params[:id])
206
239
  end
207
240
 
208
- def send_pdf
241
+ def send_pdf
209
242
  # Render the PDF in memory and send as the response
210
243
  send_data @charge.receipt.render,
211
244
  filename: "#{@charge.created_at.strftime("%Y-%m-%d")}-gorails-receipt.pdf",
@@ -232,6 +265,7 @@ Invoices follow the exact same set of steps as above. You'll simply want to modi
232
265
 
233
266
  ```ruby
234
267
  Receipts::Invoice.new(
268
+ # title: "Invoice",
235
269
  details: [
236
270
  ["Invoice Number", "123"],
237
271
  ["Issue Date", Date.today.strftime("%B %d, %Y")],
@@ -268,6 +302,7 @@ Statements follow the exact same set of steps as above. You'll simply want to mo
268
302
 
269
303
  ```ruby
270
304
  Receipts::Statement.new(
305
+ # title: "Statement",
271
306
  details: [
272
307
  ["Statement Number", "123"],
273
308
  ["Issue Date", Date.today.strftime("%B %d, %Y")],
@@ -299,9 +334,8 @@ Receipts::Statement.new(
299
334
 
300
335
  ## Contributing
301
336
 
302
- 1. Fork it ( https://github.com/excid3/receipts/fork )
337
+ 1. Fork it [https://github.com/excid3/receipts/fork](https://github.com/excid3/receipts/fork)
303
338
  2. Create your feature branch (`git checkout -b my-new-feature`)
304
339
  3. Commit your changes (`git commit -am 'Add some feature'`)
305
340
  4. Push to the branch (`git push origin my-new-feature`)
306
341
  5. Create a new Pull Request
307
-
data/examples/invoice.pdf CHANGED
Binary file
data/examples/receipt.pdf CHANGED
Binary file
Binary file
data/lib/receipts/base.rb CHANGED
@@ -7,7 +7,7 @@ module Receipts
7
7
  end
8
8
 
9
9
  def initialize(attributes = {})
10
- super(page_size: "LETTER")
10
+ super(page_size: attributes.delete(:page_size) || "LETTER")
11
11
  setup_fonts attributes.fetch(:font, Receipts.default_font)
12
12
 
13
13
  @title = attributes.fetch(:title, self.class.title)
@@ -19,10 +19,13 @@ module Receipts
19
19
  return if attributes.empty?
20
20
 
21
21
  company = attributes.fetch(:company)
22
- header company: company
22
+ header company: company, height: attributes.fetch(:logo_height, 16)
23
23
  render_details attributes.fetch(:details)
24
24
  render_billing_details company: company, recipient: attributes.fetch(:recipient)
25
- render_line_items attributes.fetch(:line_items)
25
+ render_line_items(
26
+ line_items: attributes.fetch(:line_items),
27
+ column_widths: attributes[:column_widths]
28
+ )
26
29
  render_footer attributes.fetch(:footer, default_message(company: company))
27
30
  end
28
31
 
@@ -79,11 +82,18 @@ module Receipts
79
82
  table(line_items, width: bounds.width, cell_style: {borders: [], inline_format: true, overflow: :expand})
80
83
  end
81
84
 
82
- def render_line_items(line_items, margin_top: 30)
85
+ def render_line_items(line_items:, margin_top: 30, column_widths: nil)
83
86
  move_down margin_top
84
87
 
85
88
  borders = line_items.length - 2
86
- table(line_items, width: bounds.width, cell_style: {border_color: "eeeeee", inline_format: true}) do
89
+
90
+ table_options = {
91
+ width: bounds.width,
92
+ cell_style: {border_color: "eeeeee", inline_format: true},
93
+ column_widths: column_widths
94
+ }.compact
95
+
96
+ table(line_items, table_options) do
87
97
  cells.padding = 6
88
98
  cells.borders = []
89
99
  row(0..borders).borders = [:bottom]
@@ -1,3 +1,3 @@
1
1
  module Receipts
2
- VERSION = "2.1.0"
2
+ VERSION = "2.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: receipts
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Oliver
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-11-24 00:00:00.000000000 Z
11
+ date: 2024-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: prawn
@@ -90,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
90
  - !ruby/object:Gem::Version
91
91
  version: '0'
92
92
  requirements: []
93
- rubygems_version: 3.3.7
93
+ rubygems_version: 3.5.4
94
94
  signing_key:
95
95
  specification_version: 4
96
96
  summary: Receipts for your Rails application that works with any payment provider.