prawn_plus 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +3 -0
- data/LICENSE.rdoc +20 -0
- data/README.rdoc +116 -0
- data/lib/prawn_plus/railtie.rb +8 -0
- data/lib/prawn_plus/template_handlers/prawn.rb +13 -0
- data/lib/prawn_plus/version.rb +3 -0
- data/lib/prawn_plus.rb +4 -0
- metadata +184 -0
data/CHANGELOG.rdoc
ADDED
data/LICENSE.rdoc
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 {Red Alchemist}[http://www.redalchemist.com].
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
= Overview
|
2
|
+
|
3
|
+
{<img src="https://secure.travis-ci.org/bkuhlmann/prawn_plus.png" />}[http://travis-ci.org/bkuhlmann/prawn_plus]
|
4
|
+
|
5
|
+
= Features
|
6
|
+
|
7
|
+
* Loads the Prawn[https://github.com/prawnpdf/prawn] gem by default (no Gemfile entry necessary).
|
8
|
+
* Registers PDF as a MIME type.
|
9
|
+
* Registers a template handler for rendering ".prawn" template view files.
|
10
|
+
|
11
|
+
= Requirements
|
12
|
+
|
13
|
+
1. {Ruby on Rails}[http://rubyonrails.org].
|
14
|
+
2. Prawn[https://github.com/prawnpdf/prawn].
|
15
|
+
|
16
|
+
= Setup
|
17
|
+
|
18
|
+
Type the following from the command line to install:
|
19
|
+
|
20
|
+
gem install prawn_plus
|
21
|
+
|
22
|
+
Add the following to your Gemfile:
|
23
|
+
|
24
|
+
gem "prawn_plus"
|
25
|
+
|
26
|
+
= Usage
|
27
|
+
|
28
|
+
== Views
|
29
|
+
|
30
|
+
Within your views you can craft Prawn templates using Ruby code. For example, assuming there are document resources, then
|
31
|
+
the following structure might exist:
|
32
|
+
|
33
|
+
/views/documents/show.html.erb
|
34
|
+
/views/documents/show.pdf.prawn
|
35
|
+
|
36
|
+
The show.html.erb could have a link to the PDF download. Example:
|
37
|
+
|
38
|
+
<%= link_to "PDF Download", action: "show", id: @document.id, format: "pdf" %>
|
39
|
+
|
40
|
+
The show.pdf.prawn file would contain the Prawn syntax for crafting the PDF. A simple example
|
41
|
+
might look like this:
|
42
|
+
|
43
|
+
pdf.text "Hello, I'm a PDF!"
|
44
|
+
|
45
|
+
...which would render the following output:
|
46
|
+
|
47
|
+
{<img src="https://github.com/bkuhlmann/prawn_plus/raw/master/doc/examples/basic.png" />}[https://github.com/bkuhlmann/prawn_plus]
|
48
|
+
|
49
|
+
You could also render a more complex PDF with tabular information, for example:
|
50
|
+
|
51
|
+
pdf.text "Metals"
|
52
|
+
pdf.move_down 10
|
53
|
+
pdf.font_size = 10
|
54
|
+
|
55
|
+
data = [
|
56
|
+
["Name", "Atomic Number", "Price"],
|
57
|
+
["Mercury", "80", number_to_currency(10)],
|
58
|
+
["Platinum", "78", number_to_currency(25)],
|
59
|
+
["Titanium", "22", number_to_currency(50)]
|
60
|
+
]
|
61
|
+
|
62
|
+
pdf.table data, header: true, column_widths: [100, 50, 50], row_colors: ["FFFFFF", "E5ECF9"] do
|
63
|
+
columns(0).align = :left
|
64
|
+
columns(1..2).align = :right
|
65
|
+
row(0).text_color = "FFFFFF"
|
66
|
+
row(0).background_color = "000000"
|
67
|
+
row(0).columns(0..2).font_style = :bold
|
68
|
+
row(0).columns(0..2).align = :center
|
69
|
+
end
|
70
|
+
|
71
|
+
...which would render the following output:
|
72
|
+
|
73
|
+
{<img src="https://github.com/bkuhlmann/prawn_plus/raw/master/doc/examples/complex.png" />}[https://github.com/bkuhlmann/prawn_plus]
|
74
|
+
|
75
|
+
NOTE: The _pdf_ object must always be referenced when making using of the Prawn syntax - it is initialized for you
|
76
|
+
as a Prawn::Document instance.
|
77
|
+
|
78
|
+
== Controllers
|
79
|
+
|
80
|
+
Within your controller, only the respond_to method is required. Using the same example above, only the following
|
81
|
+
would be necessary:
|
82
|
+
|
83
|
+
class DocumentsController < ApplicationController
|
84
|
+
respond_to :pdf
|
85
|
+
|
86
|
+
def show
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
That's it!
|
91
|
+
|
92
|
+
= Tests
|
93
|
+
|
94
|
+
To test, do the following:
|
95
|
+
|
96
|
+
1. cd to the gem root.
|
97
|
+
2. bundle install
|
98
|
+
3. bundle exec rspec spec
|
99
|
+
|
100
|
+
= Contributions
|
101
|
+
|
102
|
+
Please log all feedback/issues via GitHub Issues. Thanks.
|
103
|
+
|
104
|
+
= Credits
|
105
|
+
|
106
|
+
Developed by {Brooke Kuhlmann}[http://www.redalchemist.com] at {Red Alchemist}[http://www.redalchemist.com]
|
107
|
+
|
108
|
+
= License
|
109
|
+
|
110
|
+
Copyright (c) 2012 {Red Alchemist}[http://www.redalchemist.com].
|
111
|
+
Read the LICENSE for details.
|
112
|
+
|
113
|
+
= History
|
114
|
+
|
115
|
+
Read the CHANGELOG for details.
|
116
|
+
Built with Gemsmith[https://github.com/bkuhlmann/gemsmith].
|
@@ -0,0 +1,8 @@
|
|
1
|
+
module PrawnPlus
|
2
|
+
class Railtie < Rails::Railtie
|
3
|
+
initializer "prawn_plus.initialize" do
|
4
|
+
Mime::Type.register("application/pdf", :pdf) unless Mime::Type.lookup_by_extension :pdf
|
5
|
+
ActionView::Template.register_template_handler :prawn, PrawnPlus::TemplateHandlers::Prawn.new
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module PrawnPlus
|
2
|
+
module TemplateHandlers
|
3
|
+
class Prawn
|
4
|
+
# Renders a Prawn template. It is assumed that the template will reference a
|
5
|
+
# _pdf_ (a.k.a. Prawn:Document) instance.
|
6
|
+
# * +template+ - Required. The template to render to a PDF.
|
7
|
+
# * +options+ - Optional. The template options. Default: {}.
|
8
|
+
def call template, options = {}
|
9
|
+
"pdf = ::Prawn::Document.new;" + template.source + ";pdf.render;"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/prawn_plus.rb
ADDED
metadata
ADDED
@@ -0,0 +1,184 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: prawn_plus
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Brooke Kuhlmann
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-05-26 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3.2'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.2'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: prawn
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0.12'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0.12'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: sqlite3
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rspec-rails
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: capybara
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: rb-fsevent
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: guard-rspec
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
type: :development
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
description: Enhances default Prawn PDF functionality (which includes PDF template
|
143
|
+
handling/rendering).
|
144
|
+
email: brooke@redalchemist.com
|
145
|
+
executables: []
|
146
|
+
extensions: []
|
147
|
+
extra_rdoc_files:
|
148
|
+
- README.rdoc
|
149
|
+
- CHANGELOG.rdoc
|
150
|
+
- LICENSE.rdoc
|
151
|
+
files:
|
152
|
+
- lib/prawn_plus/railtie.rb
|
153
|
+
- lib/prawn_plus/template_handlers/prawn.rb
|
154
|
+
- lib/prawn_plus/version.rb
|
155
|
+
- lib/prawn_plus.rb
|
156
|
+
- README.rdoc
|
157
|
+
- CHANGELOG.rdoc
|
158
|
+
- LICENSE.rdoc
|
159
|
+
homepage: http://www.redalchemist.com
|
160
|
+
licenses:
|
161
|
+
- MIT
|
162
|
+
post_install_message: ! '(W): www.redalchemist.com. (T): @ralchemist.'
|
163
|
+
rdoc_options: []
|
164
|
+
require_paths:
|
165
|
+
- lib
|
166
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
167
|
+
none: false
|
168
|
+
requirements:
|
169
|
+
- - ~>
|
170
|
+
- !ruby/object:Gem::Version
|
171
|
+
version: 1.9.0
|
172
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
173
|
+
none: false
|
174
|
+
requirements:
|
175
|
+
- - ! '>='
|
176
|
+
- !ruby/object:Gem::Version
|
177
|
+
version: '0'
|
178
|
+
requirements: []
|
179
|
+
rubyforge_project:
|
180
|
+
rubygems_version: 1.8.24
|
181
|
+
signing_key:
|
182
|
+
specification_version: 3
|
183
|
+
summary: Enhances default Prawn PDF functionality.
|
184
|
+
test_files: []
|