receipts 2.3.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.standard.yml +1 -0
- data/CHANGELOG.md +29 -0
- data/Gemfile +0 -1
- data/README.md +31 -10
- data/Rakefile +3 -1
- data/examples/invoice.pdf +0 -0
- data/examples/receipt.pdf +0 -0
- data/examples/statement.pdf +0 -0
- data/lib/receipts/base.rb +6 -13
- data/lib/receipts/fonts/Inter-Bold.ttf +0 -0
- data/lib/receipts/fonts/Inter-Regular.ttf +0 -0
- data/lib/receipts/fonts/OFL.txt +92 -0
- data/lib/receipts/pdf/document.rb +383 -0
- data/lib/receipts/pdf/font.rb +168 -0
- data/lib/receipts/pdf/geometry.rb +29 -0
- data/lib/receipts/pdf/image.rb +242 -0
- data/lib/receipts/pdf/inline_format.rb +79 -0
- data/lib/receipts/pdf/table.rb +250 -0
- data/lib/receipts/pdf/text_layout.rb +175 -0
- data/lib/receipts/pdf/true_type.rb +387 -0
- data/lib/receipts/pdf/writer.rb +119 -0
- data/lib/receipts/version.rb +1 -1
- data/lib/receipts.rb +9 -2
- metadata +18 -43
- data/receipts.gemspec +0 -33
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a47085bc4aed90ea312b2824ded3d8160c62479d59041b482ff8bb0cdf7776b3
|
|
4
|
+
data.tar.gz: 7d356f573664804db0684f104f3a8df60549413fc0d16918f9062ede95d604ff
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 329d7d5947440183086281c55a54e340550783fbbc8f9c21fff7dee0c02b9c6e0a0ba3bd7512efb2a15bf3ce091f0c10b98fe49909e8a09e7208f9a5adc3fd45
|
|
7
|
+
data.tar.gz: b390f51b8bc9e506b90cc4ab8486f278edde18945f726498faf27c4ab2b022c0e3f31adb4d0793a86992440e1db394ba9d3aaa04889c51b18c1669055587d727
|
data/.standard.yml
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ruby_version: 2.7
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
### Unreleased
|
|
2
2
|
|
|
3
|
+
### 3.0.0
|
|
4
|
+
|
|
5
|
+
* Replace Prawn with a built-in, pure Ruby PDF generator. Receipts no longer has any gem dependencies.
|
|
6
|
+
* Embed the Inter font by default, adding Unicode support (Latin, Greek, Cyrillic) without configuring a custom font
|
|
7
|
+
* Custom fonts must be TrueType (`.ttf`) files; only used characters are embedded
|
|
8
|
+
* **Breaking:** Receipts objects inherit from `Receipts::PDF::Document` instead of `Prawn::Document`. Custom content using Prawn APIs beyond `text`, `image`, `table`, `move_down`/`move_up`, `font`, `font_size`, `bounds` and `start_new_page` needs updating.
|
|
9
|
+
* **Breaking:** Table cells no longer accept Prawn's `overflow:` option. Rows always grow to fit their content, so remove `overflow:` from any custom `cell_style`.
|
|
10
|
+
|
|
11
|
+
### 2.4.0
|
|
12
|
+
|
|
13
|
+
* Add `display: []` for configuring company details that are rendered #38 - @excid3
|
|
14
|
+
|
|
15
|
+
```ruby
|
|
16
|
+
r = Receipts::Receipt.new(
|
|
17
|
+
company: {
|
|
18
|
+
name: "Example, LLC",
|
|
19
|
+
address: "123 Fake Street\nNew York City, NY 10012",
|
|
20
|
+
phone: "(555) 867-5309",
|
|
21
|
+
email: "support@example.com",
|
|
22
|
+
iban: "123456789",
|
|
23
|
+
logo: File.expand_path("./examples/images/logo.png"),
|
|
24
|
+
display: [:address, :phone, :email, :iban]
|
|
25
|
+
},
|
|
26
|
+
# ...
|
|
27
|
+
)
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
* Fix Prawn docs link in README #36 - @ocarreterom
|
|
31
|
+
|
|
3
32
|
### 2.3.0
|
|
4
33
|
|
|
5
34
|
* Add `column_widths:` option to specify line item column widths #35
|
data/Gemfile
CHANGED
data/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# Receipts Gem
|
|
4
4
|
|
|
5
|
-
Receipts, Invoices, and Statements for your Rails application that works with any payment provider.
|
|
5
|
+
Receipts, Invoices, and Statements for your Rails application that works with any payment provider. PDFs are generated in pure Ruby with no dependencies.
|
|
6
6
|
|
|
7
7
|
Check out the [example PDFs](https://github.com/excid3/receipts/blob/master/examples/).
|
|
8
8
|
|
|
@@ -72,7 +72,9 @@ r.render_file "examples/receipt.pdf"
|
|
|
72
72
|
|
|
73
73
|
### Configuration
|
|
74
74
|
|
|
75
|
-
|
|
75
|
+
PDFs use the bundled [Inter](https://rsms.me/inter/) font by default, which supports Latin, Greek, and Cyrillic characters.
|
|
76
|
+
|
|
77
|
+
You can specify a different default font for all PDFs by defining the following in an initializer:
|
|
76
78
|
|
|
77
79
|
```ruby
|
|
78
80
|
Receipts.default_font = {
|
|
@@ -81,6 +83,8 @@ Receipts.default_font = {
|
|
|
81
83
|
}
|
|
82
84
|
```
|
|
83
85
|
|
|
86
|
+
Fonts must be TrueType (`.ttf`) files. Only the characters used are embedded in each PDF. You may also provide `italic:` and `bold_italic:` fonts; otherwise italic text is simulated by slanting the normal font.
|
|
87
|
+
|
|
84
88
|
### Options
|
|
85
89
|
|
|
86
90
|
You can pass the following options to generate a PDF:
|
|
@@ -107,6 +111,8 @@ You can pass the following options to generate a PDF:
|
|
|
107
111
|
logo: "https://www.ruby-lang.org/images/header-ruby-logo@2x.png" # Downloaded with OpenURI
|
|
108
112
|
```
|
|
109
113
|
|
|
114
|
+
* `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.
|
|
115
|
+
|
|
110
116
|
* `details` - Array of details about the Receipt, Invoice, Statement. Typically, this is receipt numbers, issue date, due date, status, etc.
|
|
111
117
|
|
|
112
118
|
* `line_items` - Array of line items to be displayed in table format.
|
|
@@ -130,8 +136,7 @@ Here's an example of where each option is displayed.
|
|
|
130
136
|
|
|
131
137
|
#### Line Items Table - Column Widths
|
|
132
138
|
|
|
133
|
-
|
|
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):
|
|
139
|
+
By default, columns are sized to fit their content and any leftover space is split evenly between columns. You may set the width of specific columns in points (1/72 inch) to override this.
|
|
135
140
|
|
|
136
141
|
This will size the second column to 400 and the fourth column to 50.
|
|
137
142
|
|
|
@@ -145,13 +150,18 @@ This will set all column widths, considering your table has 4 columns.
|
|
|
145
150
|
column_widths: [100, 200, 240]
|
|
146
151
|
```
|
|
147
152
|
|
|
148
|
-
|
|
153
|
+
Columns without a width are sized automatically.
|
|
149
154
|
|
|
150
155
|
### Formatting
|
|
151
156
|
|
|
152
|
-
`details` and `
|
|
157
|
+
`details`, `line_items`, `recipient` and `footer` allow inline formatting using HTML-like tags:
|
|
153
158
|
|
|
154
|
-
|
|
159
|
+
* `<b>` / `<strong>`, `<i>` / `<em>`, `<u>`, `<strikethrough>`, `<sub>`, `<sup>`, `<br>`
|
|
160
|
+
* `<font name="Primary" size="12" character_spacing="1">`
|
|
161
|
+
* `<color rgb="#5eba7d">` or `<color c="0" m="100" y="100" k="0">`
|
|
162
|
+
* `<link href="https://example.com">`
|
|
163
|
+
|
|
164
|
+
Use `<`, `>` and `&` for literal `<`, `>` and `&` characters.
|
|
155
165
|
|
|
156
166
|
#### Page Size
|
|
157
167
|
|
|
@@ -181,17 +191,28 @@ You can change the entire PDF content by instantiating an Receipts object withou
|
|
|
181
191
|
receipt = Receipts::Receipt.new # creates an empty PDF
|
|
182
192
|
```
|
|
183
193
|
|
|
184
|
-
Each Receipts object inherits from
|
|
194
|
+
Each Receipts object inherits from `Receipts::PDF::Document`, which provides a small, Prawn-like API for adding your own content:
|
|
185
195
|
|
|
186
196
|
```ruby
|
|
187
|
-
receipt.text("hello world")
|
|
197
|
+
receipt.text("hello world", size: 12, style: :bold, align: :center, color: "4b5563")
|
|
198
|
+
receipt.text("<b>Bold</b> and <i>italic</i>", inline_format: true)
|
|
199
|
+
receipt.move_down 20
|
|
200
|
+
receipt.image "logo.png", height: 24, position: :right
|
|
201
|
+
receipt.table([["Item", "Amount"], ["Product", "$10"]], width: receipt.bounds.width) do
|
|
202
|
+
row(0).font_style = :bold
|
|
203
|
+
column(1).align = :right
|
|
204
|
+
end
|
|
205
|
+
receipt.stroke_horizontal_rule
|
|
206
|
+
receipt.start_new_page
|
|
188
207
|
```
|
|
189
208
|
|
|
209
|
+
Images must be PNG (non-interlaced) or JPEG files.
|
|
210
|
+
|
|
190
211
|
You can also use the Receipts helpers in your custom PDFs at the current cursor position.
|
|
191
212
|
|
|
192
213
|
```ruby
|
|
193
214
|
receipt.text("Custom header")
|
|
194
|
-
receipt.render_line_items([
|
|
215
|
+
receipt.render_line_items(line_items: [
|
|
195
216
|
["my line items"]
|
|
196
217
|
])
|
|
197
218
|
receipt.render_footer("This is a custom footer using the Receipts helper")
|
data/Rakefile
CHANGED
|
@@ -36,7 +36,9 @@ task :receipt do
|
|
|
36
36
|
address: "123 Fake Street\nNew York City, NY 10012",
|
|
37
37
|
phone: "(555) 867-5309",
|
|
38
38
|
email: "support@example.com",
|
|
39
|
-
|
|
39
|
+
iban: "123456789",
|
|
40
|
+
logo: File.expand_path("./examples/images/logo.png"),
|
|
41
|
+
display: [:address, :phone, :email, nil, :iban]
|
|
40
42
|
},
|
|
41
43
|
details: [
|
|
42
44
|
["Receipt Number", "123"],
|
data/examples/invoice.pdf
CHANGED
|
Binary file
|
data/examples/receipt.pdf
CHANGED
|
Binary file
|
data/examples/statement.pdf
CHANGED
|
Binary file
|
data/lib/receipts/base.rb
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
module Receipts
|
|
2
|
-
class Base <
|
|
2
|
+
class Base < PDF::Document
|
|
3
3
|
attr_accessor :title, :company
|
|
4
4
|
|
|
5
5
|
class << self
|
|
@@ -39,11 +39,7 @@ module Receipts
|
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
def load_image(logo)
|
|
42
|
-
|
|
43
|
-
logo.start_with?("http") ? URI.parse(logo).open : File.open(logo)
|
|
44
|
-
else
|
|
45
|
-
logo
|
|
46
|
-
end
|
|
42
|
+
(logo.is_a?(String) && logo.start_with?("http")) ? URI.parse(logo).open : logo
|
|
47
43
|
end
|
|
48
44
|
|
|
49
45
|
def header(company: {}, height: 16)
|
|
@@ -64,14 +60,11 @@ module Receipts
|
|
|
64
60
|
table(details, cell_style: {borders: [], inline_format: true, padding: [0, 8, 2, 0]})
|
|
65
61
|
end
|
|
66
62
|
|
|
67
|
-
def render_billing_details(company:, recipient:, margin_top: 16)
|
|
63
|
+
def render_billing_details(company:, recipient:, margin_top: 16, display_values: nil)
|
|
68
64
|
move_down margin_top
|
|
69
65
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
company[:phone],
|
|
73
|
-
company[:email]
|
|
74
|
-
].compact.join("\n")
|
|
66
|
+
display_values ||= company.fetch(:display, [:address, :phone, :email])
|
|
67
|
+
company_details = company.values_at(*display_values).compact.join("\n")
|
|
75
68
|
|
|
76
69
|
line_items = [
|
|
77
70
|
[
|
|
@@ -79,7 +72,7 @@ module Receipts
|
|
|
79
72
|
{content: Array(recipient).join("\n"), padding: [0, 12, 0, 0]}
|
|
80
73
|
]
|
|
81
74
|
]
|
|
82
|
-
table(line_items, width: bounds.width, cell_style: {borders: [], inline_format: true
|
|
75
|
+
table(line_items, width: bounds.width, cell_style: {borders: [], inline_format: true})
|
|
83
76
|
end
|
|
84
77
|
|
|
85
78
|
def render_line_items(line_items:, margin_top: 30, column_widths: nil)
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
Copyright (c) 2016 The Inter Project Authors (https://github.com/rsms/inter)
|
|
2
|
+
|
|
3
|
+
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
|
4
|
+
This license is copied below, and is also available with a FAQ at:
|
|
5
|
+
http://scripts.sil.org/OFL
|
|
6
|
+
|
|
7
|
+
-----------------------------------------------------------
|
|
8
|
+
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
|
9
|
+
-----------------------------------------------------------
|
|
10
|
+
|
|
11
|
+
PREAMBLE
|
|
12
|
+
The goals of the Open Font License (OFL) are to stimulate worldwide
|
|
13
|
+
development of collaborative font projects, to support the font creation
|
|
14
|
+
efforts of academic and linguistic communities, and to provide a free and
|
|
15
|
+
open framework in which fonts may be shared and improved in partnership
|
|
16
|
+
with others.
|
|
17
|
+
|
|
18
|
+
The OFL allows the licensed fonts to be used, studied, modified and
|
|
19
|
+
redistributed freely as long as they are not sold by themselves. The
|
|
20
|
+
fonts, including any derivative works, can be bundled, embedded,
|
|
21
|
+
redistributed and/or sold with any software provided that any reserved
|
|
22
|
+
names are not used by derivative works. The fonts and derivatives,
|
|
23
|
+
however, cannot be released under any other type of license. The
|
|
24
|
+
requirement for fonts to remain under this license does not apply
|
|
25
|
+
to any document created using the fonts or their derivatives.
|
|
26
|
+
|
|
27
|
+
DEFINITIONS
|
|
28
|
+
"Font Software" refers to the set of files released by the Copyright
|
|
29
|
+
Holder(s) under this license and clearly marked as such. This may
|
|
30
|
+
include source files, build scripts and documentation.
|
|
31
|
+
|
|
32
|
+
"Reserved Font Name" refers to any names specified as such after the
|
|
33
|
+
copyright statement(s).
|
|
34
|
+
|
|
35
|
+
"Original Version" refers to the collection of Font Software components as
|
|
36
|
+
distributed by the Copyright Holder(s).
|
|
37
|
+
|
|
38
|
+
"Modified Version" refers to any derivative made by adding to, deleting,
|
|
39
|
+
or substituting -- in part or in whole -- any of the components of the
|
|
40
|
+
Original Version, by changing formats or by porting the Font Software to a
|
|
41
|
+
new environment.
|
|
42
|
+
|
|
43
|
+
"Author" refers to any designer, engineer, programmer, technical
|
|
44
|
+
writer or other person who contributed to the Font Software.
|
|
45
|
+
|
|
46
|
+
PERMISSION AND CONDITIONS
|
|
47
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
48
|
+
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
|
49
|
+
redistribute, and sell modified and unmodified copies of the Font
|
|
50
|
+
Software, subject to the following conditions:
|
|
51
|
+
|
|
52
|
+
1) Neither the Font Software nor any of its individual components,
|
|
53
|
+
in Original or Modified Versions, may be sold by itself.
|
|
54
|
+
|
|
55
|
+
2) Original or Modified Versions of the Font Software may be bundled,
|
|
56
|
+
redistributed and/or sold with any software, provided that each copy
|
|
57
|
+
contains the above copyright notice and this license. These can be
|
|
58
|
+
included either as stand-alone text files, human-readable headers or
|
|
59
|
+
in the appropriate machine-readable metadata fields within text or
|
|
60
|
+
binary files as long as those fields can be easily viewed by the user.
|
|
61
|
+
|
|
62
|
+
3) No Modified Version of the Font Software may use the Reserved Font
|
|
63
|
+
Name(s) unless explicit written permission is granted by the corresponding
|
|
64
|
+
Copyright Holder. This restriction only applies to the primary font name as
|
|
65
|
+
presented to the users.
|
|
66
|
+
|
|
67
|
+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
|
68
|
+
Software shall not be used to promote, endorse or advertise any
|
|
69
|
+
Modified Version, except to acknowledge the contribution(s) of the
|
|
70
|
+
Copyright Holder(s) and the Author(s) or with their explicit written
|
|
71
|
+
permission.
|
|
72
|
+
|
|
73
|
+
5) The Font Software, modified or unmodified, in part or in whole,
|
|
74
|
+
must be distributed entirely under this license, and must not be
|
|
75
|
+
distributed under any other license. The requirement for fonts to
|
|
76
|
+
remain under this license does not apply to any document created
|
|
77
|
+
using the Font Software.
|
|
78
|
+
|
|
79
|
+
TERMINATION
|
|
80
|
+
This license becomes null and void if any of the above conditions are
|
|
81
|
+
not met.
|
|
82
|
+
|
|
83
|
+
DISCLAIMER
|
|
84
|
+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
85
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
|
86
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
|
87
|
+
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
|
88
|
+
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
89
|
+
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
|
90
|
+
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
91
|
+
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
|
92
|
+
OTHER DEALINGS IN THE FONT SOFTWARE.
|