rails_pdf 0.2.0 → 0.2.1
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/README.md +31 -14
- data/lib/rails_pdf/renderer.rb +8 -1
- data/lib/rails_pdf/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 678f0f8bea4244c6d485dc5f1b75fab64eb3eabaad6d51951c4ea958af159e56
|
|
4
|
+
data.tar.gz: 856f2c46206dabb82b979537d7f89dafd29b5f70f164552a07413e558224bdab
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a1fe29e986fa4160d2f3479cd3bcd8ccea5038ab3ce1792960f520ab57b0cf4000328e0e1aab906d9a1338be5abc4bfa06ca4c31d0b16af013e6ef2d72468239
|
|
7
|
+
data.tar.gz: 24566e771c4710e783a0f5c19428d2ade592ddc47624d20a426549b635cf3c95404927c71559b67d928cc9f46ada34dd6a0c97d9f3d29e41e7ff4280d7ab12b8
|
data/README.md
CHANGED
|
@@ -14,6 +14,7 @@ Create PDF documents in Rails your app from HTML, CSS and JS.
|
|
|
14
14
|
- Separates PDF templates from app views
|
|
15
15
|
- Doesn't insert any middleware into your app
|
|
16
16
|
- Pub format is similar to slim
|
|
17
|
+
- Pass locals to the view
|
|
17
18
|
|
|
18
19
|
It's uses [ReLaXedJS](https://github.com/RelaxedJS/ReLaXed) tool, which is wrapper arround chromium headless.
|
|
19
20
|
|
|
@@ -28,19 +29,19 @@ _If you want to contribute and add more templates - it' very easy to do. See #Te
|
|
|
28
29
|
<td width="25%">
|
|
29
30
|
<a href="https://github.com/igorkasyanchuk/rails_pdf/blob/master/docs/report_1.png">
|
|
30
31
|
<img src="https://github.com/igorkasyanchuk/rails_pdf/blob/master/docs/report_1_thumb.png?raw=true" />
|
|
31
|
-
</a>
|
|
32
|
+
</a>
|
|
32
33
|
Template: <a href="https://github.com/igorkasyanchuk/rails_pdf/blob/master/lib/generators/rails_pdf/templates/simple_invoice/invoice.pug.erb">simple_invoice</a>
|
|
33
34
|
</td>
|
|
34
35
|
<td width="25%">
|
|
35
36
|
<a href="https://github.com/igorkasyanchuk/rails_pdf/blob/master/docs/report_2.png">
|
|
36
37
|
<img src="https://github.com/igorkasyanchuk/rails_pdf/blob/master/docs/report_2_thumb.png?raw=true" />
|
|
37
|
-
</a>
|
|
38
|
+
</a>
|
|
38
39
|
Template: <a href="https://github.com/igorkasyanchuk/rails_pdf/blob/master/lib/generators/rails_pdf/templates/basic_invoice/invoice.pug.erb">basic_invoice</a>
|
|
39
40
|
</td>
|
|
40
41
|
<td width="50%">
|
|
41
42
|
<a href="https://github.com/igorkasyanchuk/rails_pdf/blob/master/docs/report_3c.png">
|
|
42
43
|
<img src="https://github.com/igorkasyanchuk/rails_pdf/blob/master/docs/report_3c_thumb.png?raw=true" />
|
|
43
|
-
</a>
|
|
44
|
+
</a>
|
|
44
45
|
Template: <a href="https://github.com/igorkasyanchuk/rails_pdf/blob/master/lib/generators/rails_pdf/templates/chart1/chart.pug.erb">chart1</a>
|
|
45
46
|
</td>
|
|
46
47
|
</tr>
|
|
@@ -48,9 +49,9 @@ _If you want to contribute and add more templates - it' very easy to do. See #Te
|
|
|
48
49
|
<td width="25%">
|
|
49
50
|
<a href="https://github.com/igorkasyanchuk/rails_pdf/blob/master/docs/report_4.png">
|
|
50
51
|
<img src="https://github.com/igorkasyanchuk/rails_pdf/blob/master/docs/report_4_thumb.png?raw=true" />
|
|
51
|
-
</a>
|
|
52
|
+
</a>
|
|
52
53
|
Template: <a href="https://github.com/igorkasyanchuk/rails_pdf/blob/master/lib/generators/rails_pdf/templates/products/index.pug.erb">products</a>
|
|
53
|
-
</td>
|
|
54
|
+
</td>
|
|
54
55
|
<td width="25%">
|
|
55
56
|
</td>
|
|
56
57
|
<td width="25%">
|
|
@@ -83,14 +84,24 @@ This is how you can generate and send PDF files on the fly:
|
|
|
83
84
|
send_data(data, type: 'application/pdf', disposition: 'inline', filename: 'report.pdf')
|
|
84
85
|
end
|
|
85
86
|
end
|
|
86
|
-
|
|
87
|
+
|
|
87
88
|
# or return file as attachment
|
|
88
|
-
|
|
89
|
+
|
|
89
90
|
def invoice
|
|
90
91
|
RailsPDF.template("report2/invoice.pug.erb").render do |data|
|
|
91
92
|
send_data(data, type: 'application/pdf', disposition: 'attachment', filename: 'report.pdf')
|
|
92
93
|
end
|
|
93
|
-
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# sample with locals
|
|
97
|
+
# works similar how regular partials works
|
|
98
|
+
|
|
99
|
+
def report
|
|
100
|
+
@invoice = Invoice.find(params[:id])
|
|
101
|
+
RailsPDF.template("report2/invoice.pug.erb").locals(invoice: @invoice).render do |data|
|
|
102
|
+
send_data(data, type: 'application/pdf', disposition: 'inline', filename: 'report.pdf')
|
|
103
|
+
end
|
|
104
|
+
end
|
|
94
105
|
```
|
|
95
106
|
|
|
96
107
|
If you need to create PDF file and save to file on drive:
|
|
@@ -137,9 +148,11 @@ Installation of gem is very simple, it's just requires one additional step to in
|
|
|
137
148
|
|
|
138
149
|
#### Install RelaxedJS
|
|
139
150
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
151
|
+
```bash
|
|
152
|
+
$ git clone https://github.com/RelaxedJS/ReLaXed.git .
|
|
153
|
+
$ npm install
|
|
154
|
+
$ sudo npm link --unsafe-perm=true
|
|
155
|
+
```
|
|
143
156
|
|
|
144
157
|
Verify it's installed with: `relaxed --version`.
|
|
145
158
|
|
|
@@ -166,7 +179,7 @@ $ bundle
|
|
|
166
179
|
// A4
|
|
167
180
|
$page-width: 8.27in;
|
|
168
181
|
$page-height: 11.69in;
|
|
169
|
-
```
|
|
182
|
+
```
|
|
170
183
|
- if you want to add header/footer (sample: lib/generators/rails_pdf/templates/simple_invoice/invoice.pug.erb)
|
|
171
184
|
```pug
|
|
172
185
|
h1 My document
|
|
@@ -184,8 +197,8 @@ $ bundle
|
|
|
184
197
|
## Development
|
|
185
198
|
|
|
186
199
|
- open `test/dummy`
|
|
187
|
-
- rake db:migrate
|
|
188
|
-
- `rails s -b 0.0.0.0`
|
|
200
|
+
- `bundle exec rake db:migrate`
|
|
201
|
+
- `bundle exec rails s -b 0.0.0.0`
|
|
189
202
|
- open `localhost:3000/report.pdf`
|
|
190
203
|
- modify templates in app/pdf
|
|
191
204
|
|
|
@@ -222,6 +235,10 @@ Before deploy app to production please don't forget to install Relaxed.JS on it.
|
|
|
222
235
|
|
|
223
236
|
You are welcome to contribute.
|
|
224
237
|
|
|
238
|
+
## Contributors
|
|
239
|
+
|
|
240
|
+
* https://github.com/gambala
|
|
241
|
+
|
|
225
242
|
## License
|
|
226
243
|
|
|
227
244
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/lib/rails_pdf/renderer.rb
CHANGED
|
@@ -12,10 +12,17 @@ module RailsPDF
|
|
|
12
12
|
self
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
+
def locals(locals)
|
|
16
|
+
@locals = locals
|
|
17
|
+
self
|
|
18
|
+
end
|
|
19
|
+
|
|
15
20
|
def render(&block)
|
|
16
21
|
controller = ActionController::Base.new
|
|
17
22
|
view = ActionView::Base.new(ActionController::Base.view_paths, {}, controller)
|
|
18
|
-
|
|
23
|
+
params = { file: @file, layout: @layout }
|
|
24
|
+
params = params.merge(locals: @locals) if @locals.present?
|
|
25
|
+
content = view.render(params)
|
|
19
26
|
|
|
20
27
|
logger.debug "RailsPDF ====="
|
|
21
28
|
logger.debug "RailsPDF content:\n#{content}"
|
data/lib/rails_pdf/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rails_pdf
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Igor Kasyanchuk
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2019-
|
|
11
|
+
date: 2019-08-06 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|
|
@@ -122,8 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
122
122
|
- !ruby/object:Gem::Version
|
|
123
123
|
version: '0'
|
|
124
124
|
requirements: []
|
|
125
|
-
|
|
126
|
-
rubygems_version: 2.7.7
|
|
125
|
+
rubygems_version: 3.0.2
|
|
127
126
|
signing_key:
|
|
128
127
|
specification_version: 4
|
|
129
128
|
summary: Reliable way to generate PDF files of any complexity.
|