receipts 2.2.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: 9dd904f28ec977eac50dff178d568a07708de3c80deddd2119047ff8728337f7
4
- data.tar.gz: 28e46c6f307fef00ccce4c4f1a7358ae1b528fb4f6ee65795aba514218ec3929
3
+ metadata.gz: 1606d916a395c1e22c80566221f2db3ad1ed035ec3d426d2500b4beffe1f0f8d
4
+ data.tar.gz: a5d29e51729f90104dceb3ff6faf6a4b3a27f7a404789664895821e62b416752
5
5
  SHA512:
6
- metadata.gz: 99713c6cecafbf19d75c298e94eb66ef11c3e643ec102214eb9d5010ec947b8719ec1df7261afb5a15a796fb7d3994acdab001cede3499bbbd526e5fe29f2d65
7
- data.tar.gz: b6f3e79761afdd71d4b5c482763732eac98881ac4394ddc522def91ebaada25685ef968b5614088f1d4361d9921f320764f8614cb66dfa29c8b7c1081aebc2c0
6
+ metadata.gz: 8a372a3605d3535d4f5fca1bac41a22470541b8717ed51fb8383e0250df0c1a97b7ef104fc388d8e3439572854cb82b925441cb8196336ef6996e411e8b68b2c
7
+ data.tar.gz: 971fe78bd36d9858a45afcdf4035575c51f373f33b1defb9637cde49f38501d322874132e22f06209ed1a05ed6e56a5fe7a1ea56bbbafd49f46977c4214e19b5
data/CHANGELOG.md CHANGED
@@ -1,12 +1,17 @@
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
+
3
9
  * Allow specifiying other page sizes - @excid3
4
10
  * Add `logo_height:` option to specify the height of the logo image
5
11
 
6
12
  ### 2.1.0
7
13
 
8
14
  * Add `Receipts.default_font` - @excid3
9
- >>>>>>> 65dc0260770f3d751f67dc5433be09127367b83b
10
15
 
11
16
  ### 2.0.0
12
17
 
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],
@@ -123,14 +128,32 @@ Here's an example of where each option is displayed.
123
128
 
124
129
  ![options](examples/images/options.jpg)
125
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
+
126
150
  ### Formatting
127
151
 
128
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>`
129
153
 
130
154
  See [the Prawn docs](https://prawnpdf.org/api-docs/2.3.0/Prawn/Text.html#text-instance_method) for more information.
131
155
 
132
-
133
- ##### Page Size
156
+ #### Page Size
134
157
 
135
158
  You can specify a different page size by passing in the `page_size` keyword argument:
136
159
 
@@ -215,7 +238,7 @@ class ChargesController < ApplicationController
215
238
  @charge = current_user.charges.find(params[:id])
216
239
  end
217
240
 
218
- def send_pdf
241
+ def send_pdf
219
242
  # Render the PDF in memory and send as the response
220
243
  send_data @charge.receipt.render,
221
244
  filename: "#{@charge.created_at.strftime("%Y-%m-%d")}-gorails-receipt.pdf",
@@ -242,6 +265,7 @@ Invoices follow the exact same set of steps as above. You'll simply want to modi
242
265
 
243
266
  ```ruby
244
267
  Receipts::Invoice.new(
268
+ # title: "Invoice",
245
269
  details: [
246
270
  ["Invoice Number", "123"],
247
271
  ["Issue Date", Date.today.strftime("%B %d, %Y")],
@@ -278,6 +302,7 @@ Statements follow the exact same set of steps as above. You'll simply want to mo
278
302
 
279
303
  ```ruby
280
304
  Receipts::Statement.new(
305
+ # title: "Statement",
281
306
  details: [
282
307
  ["Statement Number", "123"],
283
308
  ["Issue Date", Date.today.strftime("%B %d, %Y")],
@@ -309,9 +334,8 @@ Receipts::Statement.new(
309
334
 
310
335
  ## Contributing
311
336
 
312
- 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)
313
338
  2. Create your feature branch (`git checkout -b my-new-feature`)
314
339
  3. Commit your changes (`git commit -am 'Add some feature'`)
315
340
  4. Push to the branch (`git push origin my-new-feature`)
316
341
  5. Create a new Pull Request
317
-
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: attributes.delete(: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)
@@ -22,7 +22,10 @@ module Receipts
22
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.2.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.2.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: 2023-01-17 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.4.4
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.