receipts 1.1.1 → 1.1.2

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: dfed87396d5ed2beb0064ead6f0ac9ca457e06a7b67427ec8963b9f6404db0ce
4
- data.tar.gz: a8a4cbff0f9eadf7552ad5a533522dd6e6746cefa548f3d146a7a3e6bb0f07d3
3
+ metadata.gz: fead98b1a43ff6d6c86b13f9c8114ebcfa322b809f9f2b068b80e03370c63f65
4
+ data.tar.gz: e7e29ceceac61563c182626d3d47ab697584e67896aff884097bb955236d44ca
5
5
  SHA512:
6
- metadata.gz: b6f01ec38f45f6d6e2ed3642ef004185e1b52f7d53a23802014e338d52965099865d5e6c0269ee5528c45c959bec4d4a3fcecf1cbc6774190efa424f01f73c51
7
- data.tar.gz: 338d4628dd34e5af7d4e7de7a00d3c1758b19a26b7fb5c5f1ea561c0f4ce71150841a5c915b20e2270b16e3f63c25ea6d789fe6641a8818b605935fc3b814d63
6
+ metadata.gz: de764a9d7466e6680243ac5b2f033534a6140048f99eb5bc15aaad5b38d27063e4ed7e70f2d45167064dec7b3f941d34b0cab29aab1977e876c926ded6e80839
7
+ data.tar.gz: 7da1873655534b34d80bb735b8fe80da1d84d6f0618f1d1c7be35991e2d5ffeb197aa4b07390a3ba3aba4317ef42c7a874756b075213422d164ed296b9bb7a2b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ### Unreleased
2
2
 
3
+ ### 1.2.0
4
+
5
+ * Update design to give more room for longer product names, addresses, etc - @excid3
6
+
3
7
  ### 1.1.1
4
8
 
5
9
  * [FIX] Use `URI.parse().open` instead - @excid3 @reckerswartz
data/Rakefile CHANGED
@@ -12,6 +12,12 @@ task :console do
12
12
  exec "irb -r receipts -I ./lib"
13
13
  end
14
14
 
15
+ task :examples do
16
+ [:receipt, :invoice, :statement].each { |t| Rake::Task[t].invoke }
17
+
18
+ puts "Use `open examples` to view example PDFs."
19
+ end
20
+
15
21
  task :receipt do
16
22
  require "./lib/receipts"
17
23
 
@@ -23,7 +29,7 @@ task :receipt do
23
29
  name: "GoRails, LLC",
24
30
  address: "123 Fake Street\nNew York City, NY 10012",
25
31
  email: "support@example.com",
26
- logo: URI.open("https://www.ruby-lang.org/images/header-ruby-logo@2x.png")
32
+ logo: "https://www.ruby-lang.org/images/header-ruby-logo@2x.png"
27
33
  },
28
34
  line_items: [
29
35
  ["Date", Time.now.to_s],
data/examples/invoice.pdf CHANGED
Binary file
data/examples/receipt.pdf CHANGED
Binary file
Binary file
@@ -2,7 +2,7 @@ require "prawn"
2
2
  require "prawn/table"
3
3
 
4
4
  module Receipts
5
- class Invoice < Prawn::Document
5
+ class Invoice < Base
6
6
  attr_reader :attributes, :id, :company, :custom_font, :line_items, :logo, :message, :product, :subheading, :bill_to, :issue_date, :due_date, :status
7
7
 
8
8
  def initialize(attributes)
@@ -18,7 +18,7 @@ module Receipts
18
18
  @due_date = attributes.fetch(:due_date)
19
19
  @status = attributes.fetch(:status)
20
20
 
21
- super(margin: 0)
21
+ super(page_size: "LETTER")
22
22
 
23
23
  setup_fonts if custom_font.any?
24
24
  generate
@@ -34,65 +34,36 @@ module Receipts
34
34
  "INVOICE #%{id}"
35
35
  end
36
36
 
37
- def setup_fonts
38
- font_families.update "Primary" => custom_font
39
- font "Primary"
40
- end
41
-
42
37
  def generate
43
- bounding_box [0, 792], width: 612, height: 792 do
44
- bounding_box [85, 792], width: 442, height: 792 do
45
- header
46
- charge_details
47
- footer
48
- end
49
- end
38
+ header
39
+ description
40
+ invoice_details
41
+ charge_details
42
+ footer
50
43
  end
51
44
 
52
- def header
53
- move_down 60
54
-
45
+ def header(height: 24)
55
46
  logo = company[:logo]
47
+ return if logo.nil?
48
+ image load_image(logo), height: height
49
+ end
56
50
 
57
- if logo.nil?
58
- move_down 32
59
- elsif logo.is_a?(String)
60
- image URI.parse(logo).open, height: 32
61
- else
62
- image logo, height: 32
63
- end
64
-
51
+ def description
65
52
  move_down 8
66
- label(subheading % {id: id})
53
+ text label(subheading % {id: id}), inline_format: true, leading: 4
54
+ end
67
55
 
56
+ def invoice_details
68
57
  move_down 10
69
-
70
- # Cache the Y value so we can have both boxes at the same height
71
- top = y
72
- bounding_box([0, y], width: 200) do
73
- label "BILL TO"
74
-
75
- move_down 5
76
- text_box bill_to, at: [0, cursor], width: 200, height: 75, inline_format: true, size: 10, leading: 4, overflow: :shrink_to_fit
77
- end
78
-
79
- bounding_box([250, top], width: 200) do
80
- label "INVOICE DATE"
81
-
82
- move_down 5
83
- text issue_date.to_s, inline_format: true, size: 12, leading: 4
84
-
85
- move_down 10
86
- label "DUE DATE"
87
-
88
- move_down 5
89
- text due_date.to_s, inline_format: true, size: 12, leading: 4
90
-
91
- move_down 10
92
- label "STATUS"
93
-
94
- move_down 5
95
- text status, inline_format: true, size: 12, leading: 4
58
+ font_size 9
59
+
60
+ line_items = [
61
+ [{content: "#{label("BILL TO")}\n#{bill_to}", rowspan: 3, padding: [0, 12, 0, 0]}, "#{label("INVOICE DATE")}\n#{issue_date}"],
62
+ ["#{label("DUE DATE")}\n#{due_date}"],
63
+ ["#{label("STATUS")}\n#{status}"]
64
+ ]
65
+ table(line_items, width: bounds.width, cell_style: {inline_format: true, overflow: :shrink_to_fit}) do
66
+ cells.borders = []
96
67
  end
97
68
  end
98
69
 
@@ -101,8 +72,8 @@ module Receipts
101
72
 
102
73
  borders = line_items.length - 2
103
74
 
104
- table(line_items, width: bounds.width, cell_style: {border_color: "cccccc", inline_format: true}) do
105
- cells.padding = 12
75
+ table(line_items, width: bounds.width, cell_style: {border_color: "cccccc", inline_format: true, overflow: :shrink_to_fit}) do
76
+ cells.padding = 10
106
77
  cells.borders = []
107
78
  row(0..borders).borders = [:bottom]
108
79
  end
@@ -110,15 +81,11 @@ module Receipts
110
81
 
111
82
  def footer
112
83
  move_down 30
113
- text message, inline_format: true, size: 12, leading: 4
84
+ text message, inline_format: true, leading: 4
114
85
 
115
86
  move_down 30
116
87
  text company.fetch(:name), inline_format: true
117
88
  text "<color rgb='888888'>#{company.fetch(:address)}</color>", inline_format: true
118
89
  end
119
-
120
- def label(text)
121
- text "<color rgb='a6a6a6'>#{text}</color>", inline_format: true, size: 8
122
- end
123
90
  end
124
91
  end
@@ -1,8 +1,5 @@
1
- require "prawn"
2
- require "prawn/table"
3
-
4
1
  module Receipts
5
- class Receipt < Prawn::Document
2
+ class Receipt < Base
6
3
  attr_reader :attributes, :id, :company, :custom_font, :line_items, :logo, :message, :product, :subheading
7
4
 
8
5
  def initialize(attributes)
@@ -14,7 +11,7 @@ module Receipts
14
11
  @message = attributes.fetch(:message) { default_message }
15
12
  @subheading = attributes.fetch(:subheading) { default_subheading }
16
13
 
17
- super(margin: 0)
14
+ super(page_size: "LETTER")
18
15
 
19
16
  setup_fonts if custom_font.any?
20
17
  generate
@@ -30,48 +27,35 @@ module Receipts
30
27
  "RECEIPT FOR CHARGE #%{id}"
31
28
  end
32
29
 
33
- def setup_fonts
34
- font_families.update "Primary" => custom_font
35
- font "Primary"
36
- end
37
-
38
30
  def generate
39
- bounding_box [0, 792], width: 612, height: 792 do
40
- bounding_box [85, 792], width: 442, height: 792 do
41
- header
42
- charge_details
43
- footer
44
- end
45
- end
31
+ header
32
+ description
33
+ charge_details
34
+ footer
46
35
  end
47
36
 
48
- def header
49
- move_down 60
50
-
37
+ def header(height: 24)
51
38
  logo = company[:logo]
39
+ return if logo.nil?
40
+ image load_image(logo), height: height
41
+ end
52
42
 
53
- if logo.nil?
54
- move_down 32
55
- elsif logo.is_a?(String)
56
- image URI.parse(logo).open, height: 32
57
- else
58
- image logo, height: 32
59
- end
60
-
43
+ def description
61
44
  move_down 8
62
45
  text "<color rgb='a6a6a6'>#{subheading % {id: id}}</color>", inline_format: true
63
46
 
64
47
  move_down 30
65
- text message, inline_format: true, size: 12.5, leading: 4
48
+ text message, inline_format: true, leading: 4
66
49
  end
67
50
 
68
51
  def charge_details
69
52
  move_down 30
53
+ font_size 9
70
54
 
71
55
  borders = line_items.length - 2
72
56
 
73
57
  table(line_items, width: bounds.width, cell_style: {border_color: "cccccc", inline_format: true}) do
74
- cells.padding = 12
58
+ cells.padding = 10
75
59
  cells.borders = []
76
60
  row(0..borders).borders = [:bottom]
77
61
  end
@@ -1,8 +1,5 @@
1
- require "prawn"
2
- require "prawn/table"
3
-
4
1
  module Receipts
5
- class Statement < Prawn::Document
2
+ class Statement < Base
6
3
  attr_reader :attributes, :id, :company, :custom_font, :line_items, :logo, :message, :product, :subheading, :bill_to, :issue_date, :start_date, :end_date
7
4
 
8
5
  def initialize(attributes)
@@ -18,7 +15,7 @@ module Receipts
18
15
  @start_date = attributes.fetch(:start_date)
19
16
  @end_date = attributes.fetch(:end_date)
20
17
 
21
- super(margin: 0)
18
+ super(page_size: "LETTER")
22
19
 
23
20
  setup_fonts if custom_font.any?
24
21
  generate
@@ -34,57 +31,36 @@ module Receipts
34
31
  "STATEMENT #%{id}"
35
32
  end
36
33
 
37
- def setup_fonts
38
- font_families.update "Primary" => custom_font
39
- font "Primary"
40
- end
41
-
42
34
  def generate
43
- bounding_box [0, 792], width: 612, height: 792 do
44
- bounding_box [85, 792], width: 442, height: 792 do
45
- header
46
- charge_details
47
- footer
48
- end
49
- end
35
+ header
36
+ description
37
+ statement_details
38
+ charge_details
39
+ footer
50
40
  end
51
41
 
52
- def header
53
- move_down 60
54
-
42
+ def header(height: 24)
55
43
  logo = company[:logo]
44
+ return if logo.nil?
45
+ image load_image(logo), height: height
46
+ end
56
47
 
57
- if logo.nil?
58
- move_down 32
59
- elsif logo.is_a?(String)
60
- image URI.parse(logo).open, height: 32
61
- else
62
- image logo, height: 32
63
- end
64
-
48
+ def description
65
49
  move_down 8
66
- label(subheading % {id: id})
50
+ text label(subheading % {id: id}), inline_format: true, leading: 4
51
+ end
67
52
 
53
+ def statement_details
68
54
  move_down 10
69
-
70
- # Cache the Y value so we can have both boxes at the same height
71
- top = y
72
- bounding_box([0, y], width: 200) do
73
- move_down 5
74
- text_box bill_to, at: [0, cursor], width: 200, height: 75, inline_format: true, size: 10, leading: 4, overflow: :shrink_to_fit
75
- end
76
-
77
- bounding_box([250, top], width: 200) do
78
- label "STATEMENT DATE"
79
-
80
- move_down 5
81
- text issue_date.to_s, inline_format: true, size: 12, leading: 4
82
-
83
- move_down 10
84
- label "STATEMENT PERIOD"
85
-
86
- move_down 5
87
- text "#{start_date} - #{end_date}", inline_format: true, size: 12, leading: 4
55
+ font_size 9
56
+
57
+ line_items = [
58
+ [{content: "#{label("BILL TO")}\n#{bill_to}", rowspan: 3, padding: [0, 12, 0, 0]}, "#{label("INVOICE DATE")}\n#{issue_date}"],
59
+ ["#{label("STATEMENT DATE")}\n#{issue_date}"],
60
+ ["#{label("STATEMENT PERIOD")}\n#{start_date} - #{end_date}"]
61
+ ]
62
+ table(line_items, width: bounds.width, cell_style: {inline_format: true, overflow: :shrink_to_fit}) do
63
+ cells.borders = []
88
64
  end
89
65
  end
90
66
 
@@ -94,7 +70,7 @@ module Receipts
94
70
  borders = line_items.length - 2
95
71
 
96
72
  table(line_items, width: bounds.width, cell_style: {border_color: "cccccc", inline_format: true}) do
97
- cells.padding = 12
73
+ cells.padding = 10
98
74
  cells.borders = []
99
75
  row(0..borders).borders = [:bottom]
100
76
  end
@@ -102,15 +78,11 @@ module Receipts
102
78
 
103
79
  def footer
104
80
  move_down 30
105
- text message, inline_format: true, size: 12, leading: 4
81
+ text message, inline_format: true, leading: 4
106
82
 
107
83
  move_down 30
108
84
  text company.fetch(:name), inline_format: true
109
85
  text "<color rgb='888888'>#{company.fetch(:address)}</color>", inline_format: true
110
86
  end
111
-
112
- def label(text)
113
- text "<color rgb='a6a6a6'>#{text}</color>", inline_format: true, size: 8
114
- end
115
87
  end
116
88
  end
@@ -1,3 +1,3 @@
1
1
  module Receipts
2
- VERSION = "1.1.1"
2
+ VERSION = "1.1.2"
3
3
  end
data/lib/receipts.rb CHANGED
@@ -1,8 +1,29 @@
1
- require "open-uri"
2
1
  require "receipts/version"
2
+ require "open-uri"
3
+ require "prawn"
4
+ require "prawn/table"
3
5
 
4
6
  module Receipts
5
7
  autoload :Invoice, "receipts/invoice"
6
8
  autoload :Receipt, "receipts/receipt"
7
9
  autoload :Statement, "receipts/statement"
10
+
11
+ class Base < Prawn::Document
12
+ def setup_fonts
13
+ font_families.update "Primary" => custom_font
14
+ font "Primary"
15
+ end
16
+
17
+ def load_image(logo)
18
+ if logo.is_a? String
19
+ logo.start_with?("http") ? URI.parse(logo).open : File.open(logo)
20
+ else
21
+ logo
22
+ end
23
+ end
24
+
25
+ def label(text)
26
+ "<font size='8'><color rgb='a6a6a6'>#{text}</color></font>"
27
+ end
28
+ end
8
29
  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: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Oliver
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-01 00:00:00.000000000 Z
11
+ date: 2021-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -161,7 +161,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
161
161
  - !ruby/object:Gem::Version
162
162
  version: '0'
163
163
  requirements: []
164
- rubygems_version: 3.2.15
164
+ rubygems_version: 3.2.22
165
165
  signing_key:
166
166
  specification_version: 4
167
167
  summary: Receipts for your Rails application that works with any payment provider.