receipts 2.0.0 → 2.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 875a1ff6a3a1dcca7a1de7c21362ce0837426c3f5b3299cd9f15f38daf97cfa2
4
- data.tar.gz: 2aed77f22588a1675b558eccbe1122cc94912e04fa692aacaa7a40b16429495e
3
+ metadata.gz: 9dd904f28ec977eac50dff178d568a07708de3c80deddd2119047ff8728337f7
4
+ data.tar.gz: 28e46c6f307fef00ccce4c4f1a7358ae1b528fb4f6ee65795aba514218ec3929
5
5
  SHA512:
6
- metadata.gz: f54fc0957bccf87ebd1ae377d275f9dfe0f39a8b2cd0e8c4b5a96635183abd24f229eea142631a98d5a61156fc87cd366864e35a044a53e60ec072de08ada3e5
7
- data.tar.gz: 87745a1fe2f9cb84c69a00d816e254c4cc7b2dfee02457ece89d9e543a39b65813bfd427e7fa789e5a56feea1a3837ac3e8cc5d4574e4894805b535de76cf630
6
+ metadata.gz: 99713c6cecafbf19d75c298e94eb66ef11c3e643ec102214eb9d5010ec947b8719ec1df7261afb5a15a796fb7d3994acdab001cede3499bbbd526e5fe29f2d65
7
+ data.tar.gz: b6f3e79761afdd71d4b5c482763732eac98881ac4394ddc522def91ebaada25685ef968b5614088f1d4361d9921f320764f8614cb66dfa29c8b7c1081aebc2c0
data/CHANGELOG.md CHANGED
@@ -1,12 +1,20 @@
1
1
  ### Unreleased
2
2
 
3
+ * Allow specifiying other page sizes - @excid3
4
+ * Add `logo_height:` option to specify the height of the logo image
5
+
6
+ ### 2.1.0
7
+
8
+ * Add `Receipts.default_font` - @excid3
9
+ >>>>>>> 65dc0260770f3d751f67dc5433be09127367b83b
10
+
3
11
  ### 2.0.0
4
12
 
5
13
  * New, consistent layouts between Receipts, Invoices, and Statements - @excid3
6
14
  * PDFs can now be completely customized - @excid3
7
15
  * Add line_items to Receipts - @excid3
8
16
 
9
- ### 1.2.0
17
+ ### 1.1.2
10
18
 
11
19
  * Update design to give more room for longer product names, addresses, etc - @excid3
12
20
 
data/README.md CHANGED
@@ -59,12 +59,23 @@ r = Receipts::Receipt.new(
59
59
  )
60
60
 
61
61
  # Returns a string of the raw PDF
62
- r.render
62
+ r.render
63
63
 
64
64
  # Writes the PDF to disk
65
65
  r.render_file "examples/receipt.pdf"
66
66
  ```
67
67
 
68
+ ### Configuration
69
+
70
+ You can specify the default font for all PDFs by defining the following in an initializer:
71
+
72
+ ```ruby
73
+ Receipts.default_font = {
74
+ bold: Rails.root.join('app/assets/fonts/tradegothic/TradeGothic-Bold.ttf'),
75
+ normal: Rails.root.join('app/assets/fonts/tradegothic/TradeGothic.ttf'),
76
+ }
77
+ ```
78
+
68
79
  ### Options
69
80
 
70
81
  You can pass the following options to generate a PDF:
@@ -106,16 +117,27 @@ You can pass the following options to generate a PDF:
106
117
  }
107
118
  ```
108
119
 
120
+ * `logo_height` - An integer value of how tall the logo should be. Defaults to `16`
121
+
109
122
  Here's an example of where each option is displayed.
110
123
 
111
124
  ![options](examples/images/options.jpg)
112
125
 
113
126
  ### Formatting
114
127
 
115
- `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
+ `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>`
116
129
 
117
130
  See [the Prawn docs](https://prawnpdf.org/api-docs/2.3.0/Prawn/Text.html#text-instance_method) for more information.
118
131
 
132
+
133
+ ##### Page Size
134
+
135
+ You can specify a different page size by passing in the `page_size` keyword argument:
136
+
137
+ ```ruby
138
+ receipt = Receipts::Receipt.new page_size: "A4"
139
+ ```
140
+
119
141
  ### Internationalization (I18n)
120
142
 
121
143
  You can use `I18n.t` when rendering your receipts to internationalize them.
@@ -192,13 +214,13 @@ class ChargesController < ApplicationController
192
214
  def set_charge
193
215
  @charge = current_user.charges.find(params[:id])
194
216
  end
195
-
217
+
196
218
  def send_pdf
197
219
  # Render the PDF in memory and send as the response
198
220
  send_data @charge.receipt.render,
199
- filename: "#{@charge.created_at.strftime("%Y-%m-%d")}-gorails-receipt.pdf",
200
- type: "application/pdf",
201
- disposition: :inline # or :attachment to download
221
+ filename: "#{@charge.created_at.strftime("%Y-%m-%d")}-gorails-receipt.pdf",
222
+ type: "application/pdf",
223
+ disposition: :inline # or :attachment to download
202
224
  end
203
225
  end
204
226
  ```
data/examples/invoice.pdf CHANGED
Binary file
data/examples/receipt.pdf CHANGED
Binary file
Binary file
data/lib/receipts/base.rb CHANGED
@@ -7,8 +7,8 @@ module Receipts
7
7
  end
8
8
 
9
9
  def initialize(attributes = {})
10
- super(page_size: "LETTER")
11
- setup_fonts attributes[:font]
10
+ super page_size: attributes.delete(:page_size) || "LETTER"
11
+ setup_fonts attributes.fetch(:font, Receipts.default_font)
12
12
 
13
13
  @title = attributes.fetch(:title, self.class.title)
14
14
 
@@ -19,7 +19,7 @@ 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
25
  render_line_items attributes.fetch(:line_items)
@@ -1,3 +1,3 @@
1
1
  module Receipts
2
- VERSION = "2.0.0"
2
+ VERSION = "2.2.0"
3
3
  end
data/lib/receipts.rb CHANGED
@@ -8,4 +8,19 @@ module Receipts
8
8
  autoload :Invoice, "receipts/invoice"
9
9
  autoload :Receipt, "receipts/receipt"
10
10
  autoload :Statement, "receipts/statement"
11
+
12
+ @@default_font = nil
13
+
14
+ # Customize the default font hash
15
+ # default_font = {
16
+ # bold: "path/to/font",
17
+ # normal: "path/to/font",
18
+ # }
19
+ def self.default_font=(path)
20
+ @@default_font = path
21
+ end
22
+
23
+ def self.default_font
24
+ @@default_font
25
+ end
11
26
  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.0.0
4
+ version: 2.2.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-01-30 00:00:00.000000000 Z
11
+ date: 2023-01-17 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.2.32
93
+ rubygems_version: 3.4.4
94
94
  signing_key:
95
95
  specification_version: 4
96
96
  summary: Receipts for your Rails application that works with any payment provider.