prawn-receipt 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 31d013a642f6fd98832f9534902e9d170b8091cf
4
+ data.tar.gz: fe7d72731efb09558111881c3babd98f98630406
5
+ SHA512:
6
+ metadata.gz: 85c21857dd1d6a17cef3005e7f50ac1393acc4ed42653fbc2e4184800d17c48dc01110298ed6768748ec4008956fa4c18c9b14e9b49634b1bf2043bfc1894bd9
7
+ data.tar.gz: 32dedcd34694046060549a31c3b9c4fef3a47401ebd589e05b33194a16fb290a71da619276c1496a10db6e9f3568c2bc03ecffb437ca46b729207c2cfaf8b35d
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in prawn-receipt.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 David Ruan
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Prawn::Receipt
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'prawn-receipt'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install prawn-receipt
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/[my-github-username]/prawn-receipt/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.pattern = "spec/**/*_spec.rb"
6
+ end
7
+
8
+ task :default => :test
9
+
data/data/pr-logo.png ADDED
Binary file
@@ -0,0 +1,19 @@
1
+ require "bundler"
2
+
3
+ Bundler.require
4
+
5
+ require_relative '../lib/prawn/receipt'
6
+
7
+ logo_image_path = File.expand_path("../data/pr-logo.png",
8
+ File.dirname(__FILE__))
9
+
10
+ receipt = Prawn::Receipt.new :logo_image_path => logo_image_path,
11
+ :company_name => "Great Startup",
12
+ :company_email => "support@great-startup.com",
13
+ :customer_email => "nope@one.com",
14
+ :customer_name => "noone",
15
+ :amount_billed => "100.00",
16
+ :credit_card => "123-1234-3456",
17
+ :transaction_id => "123"
18
+
19
+ receipt.render_file "receipt.pdf"
@@ -0,0 +1,5 @@
1
+ module Prawn
2
+ class Receipt
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,84 @@
1
+ require 'prawn'
2
+ require 'prawn/table'
3
+
4
+ require_relative "receipt/version"
5
+
6
+ module Prawn
7
+ class Receipt
8
+ RECEIPTDATADIR = File.expand_path '../../data', File.dirname(__FILE__)
9
+
10
+ include Prawn::View
11
+
12
+ attr_accessor :state
13
+
14
+ def initialize(options)
15
+ @state = Hash[options.dup]
16
+ build_receipt
17
+ end
18
+
19
+ def build_receipt
20
+ image state.fetch(:logo_image_path),
21
+ :position => :center, :width => 225
22
+ #image "#{Prawn::Receipt::RECEIPTDATADIR}/pr-logo.png",
23
+ # :position => :center, :width => 225
24
+
25
+ move_down 60
26
+
27
+ font_size(20) do
28
+ text "Receipt for your payment to #{state.fetch(:company_name)}", :align => :center
29
+ end
30
+
31
+ build_table
32
+
33
+ font_size(16) do
34
+ text "Your account is all paid up, thank you!", :align=> :center
35
+ end
36
+
37
+ bounding_box([0,30], :width => 72*7.5, :height => 30) do
38
+
39
+ text "Your payment for your #{state.fetch(:company_name)} subscription has been successfully processed.", :align=> :center
40
+ text "Please keep this receipt for your records. If you have questions, email <color rgb='0000ff'><u>#{state.fetch(:company_email)}</u><color>", :inline_format => true, :align=> :center
41
+
42
+ end
43
+ end
44
+
45
+ def build_table
46
+ data = [
47
+ ["Payment date", state.fetch(:payment_date) {Time.now.strftime "%B %e, %Y "}],
48
+ ["Account billed", "$#{state.fetch(:amount_billed)} USD"],
49
+ ["Account charged", "#{state.fetch(:customer_name)}(#{state.fetch(:customer_email)})"],
50
+ ["Charged to", state.fetch(:credit_card)],
51
+ ["Transaction ID", state.fetch(:transaction_id)]
52
+ ]
53
+
54
+ move_down 20
55
+
56
+ table data, :row_colors => ["FFFFFF", "EDEEEE"],
57
+ :position => :center,
58
+ :width => 400 do |t|
59
+ apply_common_styling(t, data.length)
60
+ end
61
+
62
+
63
+
64
+ move_down 20
65
+ end
66
+
67
+ private
68
+
69
+ def apply_common_styling(t, size)
70
+ t.instance_eval do
71
+ cells.style(:padding => 10)
72
+
73
+ column(0).style(:font_style => :bold, :borders => [:left], :width => width*0.4)
74
+ column(1).style(:borders => [:right], :width => width*0.6)
75
+
76
+ row(0).style { |c| c.borders += [:top] }
77
+
78
+ row(size - 1).style do |c|
79
+ c.borders += [:bottom]
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'prawn/receipt/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "prawn-receipt"
8
+ spec.version = Prawn::Receipt::VERSION
9
+ spec.authors = ["David Ruan", "Gregory Brown"]
10
+ spec.email = ["ruanwz@gmail.com", "gregory.t.brown@gmail.com"]
11
+ spec.summary = "Prawn Receipt"
12
+ spec.description = "pdf generator for receipt"
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+ spec.add_dependency "prawn", "~> 1.3"
21
+ spec.add_dependency "prawn-table", "~> 0.1.2"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.7"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "pry", ">= 0.0"
26
+ spec.add_development_dependency "minitest", ">= 0.0"
27
+ end
@@ -0,0 +1,41 @@
1
+ require_relative '../spec_helper'
2
+
3
+ require_relative '../../lib/prawn/receipt'
4
+
5
+ describe Prawn::Receipt do
6
+ logo_image_path = File.expand_path("../../data/pr-logo.png",
7
+ File.dirname(__FILE__))
8
+ before do
9
+ @receipt = Prawn::Receipt.new :logo_image_path => logo_image_path,
10
+ :company_name => "Great Startup",
11
+ :company_email => "support@great-startup.com",
12
+ :customer_email => "no@one.com",
13
+ :customer_name => "noone",
14
+ :amount_billed => "100.00",
15
+ :credit_card => "123-1234-3456",
16
+ :transaction_id => "123"
17
+ end
18
+
19
+ it "accept hash options" do
20
+ proc {
21
+ Prawn::Receipt.new
22
+ }.must_raise ArgumentError
23
+ end
24
+
25
+ it "store template var to state" do
26
+ @receipt.state.must_equal :logo_image_path => logo_image_path,
27
+ :company_name => "Great Startup",
28
+ :company_email => "support@great-startup.com",
29
+ :customer_email => "no@one.com",
30
+ :customer_name => "noone",
31
+ :amount_billed => "100.00",
32
+ :credit_card => "123-1234-3456",
33
+ :transaction_id => "123"
34
+ end
35
+
36
+ it "render pdf file" do
37
+ @receipt.render_file "receipt_file.pdf"
38
+ end
39
+
40
+
41
+ end
@@ -0,0 +1,7 @@
1
+ # encoding: utf-8
2
+ require 'minitest/spec'
3
+ require 'minitest/autorun'
4
+ require 'pry'
5
+ require 'bundler'
6
+
7
+ Bundler.require
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: prawn-receipt
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - David Ruan
8
+ - Gregory Brown
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-10-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: prawn
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.3'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.3'
28
+ - !ruby/object:Gem::Dependency
29
+ name: prawn-table
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: 0.1.2
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: 0.1.2
42
+ - !ruby/object:Gem::Dependency
43
+ name: bundler
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '1.7'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '1.7'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rake
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '10.0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '10.0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: pry
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0.0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0.0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: minitest
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0.0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0.0'
98
+ description: pdf generator for receipt
99
+ email:
100
+ - ruanwz@gmail.com
101
+ - gregory.t.brown@gmail.com
102
+ executables: []
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - ".gitignore"
107
+ - Gemfile
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - data/pr-logo.png
112
+ - examples/sample_receipt.rb
113
+ - lib/prawn/receipt.rb
114
+ - lib/prawn/receipt/version.rb
115
+ - prawn-receipt.gemspec
116
+ - spec/prawn/receipt_spec.rb
117
+ - spec/spec_helper.rb
118
+ homepage: ''
119
+ licenses:
120
+ - MIT
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.2.2
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: Prawn Receipt
142
+ test_files:
143
+ - spec/prawn/receipt_spec.rb
144
+ - spec/spec_helper.rb
145
+ has_rdoc: