prawn-rails 1.2.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -3
- data/README.md +32 -10
- data/lib/prawn-rails/rails_helper.rb +22 -5
- data/lib/prawn-rails/renderer.rb +1 -10
- data/lib/prawn-rails/version.rb +1 -1
- data/test/dummy_app/app/controllers/reports_controller.rb +21 -2
- data/test/dummy_app/app/views/reports/custom.pdf.prawn +3 -0
- data/test/dummy_app/app/views/reports/custom_disposition.pdf.prawn +3 -0
- data/test/dummy_app/app/views/reports/custom_filename.pdf.prawn +3 -0
- data/test/dummy_app/config/routes.rb +5 -0
- data/test/dummy_app/db/test.sqlite3 +0 -0
- data/test/dummy_app/log/test.log +117 -0
- data/test/dummy_app/tmp/cache/assets/sprockets/v3.0/0Q/0QR6jgJcsDY23uF8NGHFYajkal8CGG4d3kOZQCD8Oj8.cache +1 -0
- data/test/dummy_app/tmp/cache/assets/sprockets/v3.0/1K/1KcQYwe3g9uhY2WePD1_5P38IzP0Veu8rDPI0wXQSP8.cache +1 -0
- data/test/dummy_app/tmp/cache/assets/sprockets/v3.0/3N/3NnKgR2TsTI1qCXKZpts0uJzp2dRJcoYp3nnFU6YE4o.cache +2 -0
- data/test/dummy_app/tmp/cache/assets/sprockets/v3.0/4O/4O6Anm3R8aSIVfMhGtp5tZK3x17fcY1SbWoDN_6hb-o.cache +2 -0
- data/test/dummy_app/tmp/cache/assets/sprockets/v3.0/4X/4XWDJRe7gZAeojFwJq7j6jJxRr152aQBfyhVtPPSHDY.cache +0 -0
- data/test/dummy_app/tmp/cache/assets/sprockets/v3.0/7z/7zB4MNaDZMfwUPQ7LsLGHLt1EAx1oMCEUjywneVyoyY.cache +1 -0
- data/test/dummy_app/tmp/cache/assets/sprockets/v3.0/8D/8D13-8wUZxyVgrsD9RHdWUPhLlWcqnHXtOBMOPQRX-Q.cache +1 -0
- data/test/dummy_app/tmp/cache/assets/sprockets/v3.0/LR/LRLaw7viwBb9Mi_VFZxGbKIooy8Fqf1aB_iOTETsMyc.cache +3 -0
- data/test/dummy_app/tmp/cache/assets/sprockets/v3.0/Mj/MjwYGG9GkHD1fwwH2bg66EBYl3zCA_mqeDF9otey4-U.cache +3 -0
- data/test/dummy_app/tmp/cache/assets/sprockets/v3.0/Yr/YrGeNwkHFUXGwgJhi0aqJdEHL--OyRwU5aN5azmIXM4.cache +0 -0
- data/test/dummy_app/tmp/cache/assets/sprockets/v3.0/ib/ibSeAobTqAE0a-v_-umXpnbXaIEx_WOtSsQkSRJCwwI.cache +0 -0
- data/test/dummy_app/tmp/cache/assets/sprockets/v3.0/mO/mOu9n3QmqPXFbaUP-4RAuwabvsLdudRBvk9LMIOTSoI.cache +1 -0
- data/test/dummy_app/tmp/cache/assets/sprockets/v3.0/vt/vtyC4n-7HZNOJV7EprjE7ThndKZkG00OVD8sO8cUFAM.cache +0 -0
- data/test/dummy_app/tmp/cache/assets/sprockets/v3.0/wt/wtoVyr5IaVgQI72M_TLZFUNHeStJ5maRaHlfA8Vt6d0.cache +1 -0
- data/test/integration/prawn_rails_test.rb +52 -25
- data/test/prawn_rails_test.rb +7 -2
- metadata +64 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b7b43fa3d4d79c190d6dc82e6f883c893e0cb148e22894264ffba862cae17c6b
|
4
|
+
data.tar.gz: 699da6374e86a0c32e14638752961d23b4daa9bdc4d19c9bb1edfcb42f9b858c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '091d86d558e578d37e5d41d65a0b4ff82e996ec9ec00a1fa923efe19fe8c115027f53633dea6307891de8d5834616d1e8aac8436597572ce2f260f19b456d87b'
|
7
|
+
data.tar.gz: e0801642f59f9276b03d1cce777b45d5499866a3381acf1d09588011eb986d6808cddbda55f59287e1557e93c62dcad497a3ceae80f5fefacfec830f6b826e43
|
data/CHANGELOG.md
CHANGED
@@ -2,11 +2,15 @@
|
|
2
2
|
|
3
3
|
* `Unreleased`
|
4
4
|
- Nothing yet
|
5
|
-
|
5
|
+
|
6
|
+
* `v1.3.0`
|
7
|
+
- [PR #40](https://github.com/cortiz/prawn-rails/pull/40) - Add `:filename` and `:disposition` options for `prawn_document
|
8
|
+
- [PR #40](https://github.com/cortiz/prawn-rails/pull/40) - Do not override existing`Content-Disposition` headers
|
9
|
+
|
6
10
|
* `v1.2.1`
|
7
11
|
- [PR #39](https://github.com/cortiz/prawn-rails/pull/39) - Fix Rails 6 deprecation warning for single arity template handlers
|
8
12
|
- Remove unnecessary option logic from `prawn_document` method
|
9
|
-
|
13
|
+
|
10
14
|
* `v1.2.0`
|
11
15
|
- [PR #31](https://github.com/cortiz/prawn-rails/pull/31) - Use Prawn::Document.extensions in favor of custom plug-in loading. This removes all changes made in PR #29 and should behave much more appropriately now.
|
12
16
|
- [Undo PR #29](https://github.com/cortiz/prawn-rails/pull/31) - Use Prawn::Document.extensions in favor of custom plug-in loading
|
@@ -28,5 +32,5 @@
|
|
28
32
|
|
29
33
|
* `v0.1.1`
|
30
34
|
* `v0.1.0`
|
31
|
-
* `v0.0.2`
|
35
|
+
* `v0.0.2`
|
32
36
|
* `v0.0.1`
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Prawn-Rails
|
2
2
|
<a href="https://badge.fury.io/rb/prawn-rails" target="_blank"><img height="21" style='border:0px;height:21px;' border='0' src="https://badge.fury.io/rb/prawn-rails.svg" alt="Gem Version"></a>
|
3
3
|
<a href='https://rubygems.org/gems/prawn-rails' target='_blank'><img height='21' style='border:0px;height:21px;' src='https://ruby-gem-downloads-badge.herokuapp.com/prawn-rails?label=rubygems&type=total&total_label=downloads&color=brightgreen' border='0' alt='RubyGems Downloads' /></a>
|
4
|
-
<a href='https://ko-fi.com/A5071NK' target='_blank'><img height='22' style='border:0px;height:22px;' src='https://az743702.vo.msecnd.net/cdn/kofi1.png?v=a' border='0' alt='Buy Me a Coffee' /></a>
|
4
|
+
<a href='https://ko-fi.com/A5071NK' target='_blank'><img height='22' style='border:0px;height:22px;' src='https://az743702.vo.msecnd.net/cdn/kofi1.png?v=a' border='0' alt='Buy Me a Coffee' /></a>
|
5
5
|
|
6
6
|
|
7
7
|
# Install
|
@@ -12,7 +12,7 @@ gem 'prawn-rails'
|
|
12
12
|
Note: `prawn` and `prawn-table` are dependencies of `prawn-rails` so there is no need to mention it in the projects Gemfile unless you want to use a specific version of either of those libraries.
|
13
13
|
|
14
14
|
# Usage
|
15
|
-
Create a view with `pdf` as format and `prawn` as handler so filename should look like `example.pdf.prawn
|
15
|
+
Create a view with `pdf` as format and `prawn` as handler so filename should look like `example.pdf.prawn`.
|
16
16
|
|
17
17
|
It provides a helper called `prawn_document` which builds a PrawnRails::Document with default options. You can override any options as you please. Example:
|
18
18
|
|
@@ -22,19 +22,41 @@ prawn_document do |pdf|
|
|
22
22
|
end
|
23
23
|
```
|
24
24
|
|
25
|
-
No need to call `pdf.render`, it is called by `prawn_document
|
25
|
+
No need to call `pdf.render`, it is called by `prawn_document`.
|
26
26
|
|
27
|
-
|
27
|
+
You can customize the name of the generated PDF and the file's delivery format with the `:filename` and `:disposition` keys:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
prawn_document(filename: "my-file.pdf", disposition: "attachment") do |pdf|
|
31
|
+
pdf.text "Direct download incoming!"
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
You can also override the content disposition using the [`Content-Disposition` HTTP header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition#As_a_response_header_for_the_main_body). If you've already set this, `prawn-rails` will *not* override it. Here's an example of setting the header directly:
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
def download
|
39
|
+
respond_to do |format|
|
40
|
+
format.pdf do
|
41
|
+
headers["Content-Disposition"] = "attachment; filename=\"charts-#{Time.now.to_i}.pdf\""
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
```
|
46
|
+
|
47
|
+
You can also override the file's name from the controller via `@filename`:
|
28
48
|
|
29
49
|
```ruby
|
30
50
|
def show
|
31
|
-
@filename =
|
51
|
+
@filename = "my_report.pdf"
|
32
52
|
end
|
33
53
|
```
|
34
54
|
|
55
|
+
If no options are given, the file's name will match to your browser's default and the delivery format will default to `inline`.
|
56
|
+
|
35
57
|
# Default configuration
|
36
58
|
|
37
|
-
Add a `prawn-rails.rb` config to your Rails app under `config/initializers` like this
|
59
|
+
Add a `prawn-rails.rb` config to your Rails app under `config/initializers` like this:
|
38
60
|
|
39
61
|
```ruby
|
40
62
|
PrawnRails.config do |config|
|
@@ -44,11 +66,11 @@ PrawnRails.config do |config|
|
|
44
66
|
end
|
45
67
|
```
|
46
68
|
|
47
|
-
Please note that these are the defaults.
|
69
|
+
Please note that these are the defaults.
|
48
70
|
|
49
|
-
For a list of all available options: [http://www.rubydoc.info/gems/prawn/Prawn%2FDocument:initialize](http://www.rubydoc.info/gems/prawn/Prawn%2FDocument:initialize).
|
71
|
+
For a list of all available options: [http://www.rubydoc.info/gems/prawn/Prawn%2FDocument:initialize](http://www.rubydoc.info/gems/prawn/Prawn%2FDocument:initialize).
|
50
72
|
|
51
|
-
For a list of all metadata the the `:info` option supports, please see [https://github.com/prawnpdf/prawn/blob/master/manual/document_and_page_options/metadata.rb](https://github.com/prawnpdf/prawn/blob/master/manual/document_and_page_options/metadata.rb)
|
73
|
+
For a list of all metadata the the `:info` option supports, please see [https://github.com/prawnpdf/prawn/blob/master/manual/document_and_page_options/metadata.rb](https://github.com/prawnpdf/prawn/blob/master/manual/document_and_page_options/metadata.rb).
|
52
74
|
|
53
75
|
If `skip_page_creation` is set to true then you have to create the first page yourself. Example:
|
54
76
|
|
@@ -62,7 +84,7 @@ pdf.start_new_page size: "A4", page_layout: :portrait
|
|
62
84
|
|
63
85
|
#### Hello World
|
64
86
|
|
65
|
-
```ruby
|
87
|
+
```ruby
|
66
88
|
# hello.pdf.prawn
|
67
89
|
|
68
90
|
prawn_document do |pdf|
|
@@ -4,18 +4,35 @@ module PrawnRails
|
|
4
4
|
module RailsHelper
|
5
5
|
|
6
6
|
def prawn_document(options={})
|
7
|
-
options
|
8
|
-
|
9
|
-
|
10
|
-
}
|
11
|
-
})
|
7
|
+
@filename ||= options[:filename]
|
8
|
+
|
9
|
+
options.reverse_merge!(get_metadata)
|
12
10
|
|
13
11
|
pdf = PrawnRails::Document.new(options)
|
14
12
|
|
13
|
+
# Ignore headers when we're not rendering from an ActionController context.
|
14
|
+
if defined?(controller) && controller.respond_to?(:response) && !controller.response.nil?
|
15
|
+
disposition = options[:disposition] || "inline"
|
16
|
+
disposition += "; filename=\"#{@filename}\"" if @filename
|
17
|
+
|
18
|
+
# Don't override 'Content-Disposition' if we've chosen to set it elsewhere.
|
19
|
+
controller.response.headers['Content-Disposition'] ||= disposition
|
20
|
+
end
|
21
|
+
|
15
22
|
yield pdf if block_given?
|
16
23
|
|
17
24
|
pdf.render
|
18
25
|
end
|
19
26
|
|
27
|
+
def get_metadata
|
28
|
+
return {} unless @filename
|
29
|
+
|
30
|
+
{
|
31
|
+
info: {
|
32
|
+
Title: @filename.sub(/\.pdf$/i, '')
|
33
|
+
}
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
20
37
|
end
|
21
38
|
end
|
data/lib/prawn-rails/renderer.rb
CHANGED
@@ -3,17 +3,8 @@ require "prawn-rails/document"
|
|
3
3
|
module PrawnRails
|
4
4
|
class Renderer
|
5
5
|
|
6
|
-
### WARNING: BE VERY CAREFUL IF EDITING THIS METHOD
|
7
6
|
def self.call(template, source = nil)
|
8
|
-
|
9
|
-
@filename ||= "\#{controller.action_name}.pdf"
|
10
|
-
|
11
|
-
if controller.respond_to?(:response) && !controller.response.nil?
|
12
|
-
controller.response.headers['Content-Disposition'] = "inline; filename=\\\"\#{@filename}\\\""
|
13
|
-
end
|
14
|
-
|
15
|
-
#{(source || template.source).strip}
|
16
|
-
}
|
7
|
+
(source || template.source).strip
|
17
8
|
end
|
18
9
|
|
19
10
|
end
|
data/lib/prawn-rails/version.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class ReportsController < ApplicationController
|
2
|
-
|
2
|
+
|
3
3
|
def sample
|
4
4
|
@items = [
|
5
5
|
{name: "Hello"},
|
@@ -14,5 +14,24 @@ class ReportsController < ApplicationController
|
|
14
14
|
[7,8,9],
|
15
15
|
]
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
|
+
def custom_filename
|
19
|
+
end
|
20
|
+
|
21
|
+
def custom_disposition
|
22
|
+
end
|
23
|
+
|
24
|
+
def custom
|
25
|
+
end
|
26
|
+
|
27
|
+
def ivar_filename
|
28
|
+
@filename = "ivar-filename.pdf"
|
29
|
+
render :custom
|
30
|
+
end
|
31
|
+
|
32
|
+
def custom_headers
|
33
|
+
headers['Content-Disposition'] = "attachment;filename=\"custom-headers.pdf\""
|
34
|
+
render :custom
|
35
|
+
end
|
36
|
+
|
18
37
|
end
|
File without changes
|
@@ -0,0 +1,117 @@
|
|
1
|
+
[1m[35m (0.1ms)[0m [1m[36mbegin transaction[0m
|
2
|
+
------------------------------------------------------------------------------------
|
3
|
+
NavigationTest: test_Renders_table_pdf_action_using_auto-required_plugin_Prawn-Table
|
4
|
+
------------------------------------------------------------------------------------
|
5
|
+
Started GET "/reports/table?format=pdf" for 127.0.0.1 at 2019-08-07 11:33:33 -0700
|
6
|
+
Processing by ReportsController#table as PDF
|
7
|
+
Rendering reports/table.pdf.prawn
|
8
|
+
Rendered reports/table.pdf.prawn (112.7ms)
|
9
|
+
Completed 200 OK in 121ms (Views: 120.1ms | ActiveRecord: 0.0ms)
|
10
|
+
[1m[35m (0.1ms)[0m [1m[31mrollback transaction[0m
|
11
|
+
[1m[35m (0.1ms)[0m [1m[36mbegin transaction[0m
|
12
|
+
------------------------------------------------------
|
13
|
+
NavigationTest: test_Registers_:prawn_template_handler
|
14
|
+
------------------------------------------------------
|
15
|
+
[1m[35m (0.1ms)[0m [1m[31mrollback transaction[0m
|
16
|
+
[1m[35m (0.1ms)[0m [1m[36mbegin transaction[0m
|
17
|
+
-----------------------------------------------------------------------
|
18
|
+
NavigationTest: test_Respects_both_options_on_'prawn-document'_together
|
19
|
+
-----------------------------------------------------------------------
|
20
|
+
Started GET "/reports/custom.pdf" for 127.0.0.1 at 2019-08-07 11:33:33 -0700
|
21
|
+
Processing by ReportsController#custom as PDF
|
22
|
+
Rendering reports/custom.pdf.prawn
|
23
|
+
Rendered reports/custom.pdf.prawn (2.2ms)
|
24
|
+
Completed 200 OK in 4ms (Views: 2.9ms | ActiveRecord: 0.0ms)
|
25
|
+
[1m[35m (0.1ms)[0m [1m[31mrollback transaction[0m
|
26
|
+
[1m[35m (0.1ms)[0m [1m[36mbegin transaction[0m
|
27
|
+
-----------------------------------------------------------------
|
28
|
+
NavigationTest: test_Sets_file_name_from_'@filename'_when_present
|
29
|
+
-----------------------------------------------------------------
|
30
|
+
Started GET "/reports/ivar_filename.pdf" for 127.0.0.1 at 2019-08-07 11:33:33 -0700
|
31
|
+
Processing by ReportsController#ivar_filename as PDF
|
32
|
+
Rendering reports/custom.pdf.prawn
|
33
|
+
Rendered reports/custom.pdf.prawn (1.8ms)
|
34
|
+
Completed 200 OK in 3ms (Views: 2.4ms | ActiveRecord: 0.0ms)
|
35
|
+
[1m[35m (0.1ms)[0m [1m[31mrollback transaction[0m
|
36
|
+
[1m[35m (0.1ms)[0m [1m[36mbegin transaction[0m
|
37
|
+
----------------------------------------
|
38
|
+
NavigationTest: test_Renders_html_action
|
39
|
+
----------------------------------------
|
40
|
+
Started GET "/reports/sample" for 127.0.0.1 at 2019-08-07 11:33:33 -0700
|
41
|
+
Processing by ReportsController#sample as HTML
|
42
|
+
Rendering reports/sample.html.erb within layouts/application
|
43
|
+
Rendered reports/sample.html.erb within layouts/application (1.2ms)
|
44
|
+
Completed 200 OK in 203ms (Views: 202.2ms | ActiveRecord: 0.0ms)
|
45
|
+
[1m[35m (0.1ms)[0m [1m[31mrollback transaction[0m
|
46
|
+
[1m[35m (0.1ms)[0m [1m[36mbegin transaction[0m
|
47
|
+
------------------------------------------------------------
|
48
|
+
NavigationTest: test_Respects_the_'disposition'_option_alone
|
49
|
+
------------------------------------------------------------
|
50
|
+
Started GET "/reports/custom_disposition.pdf" for 127.0.0.1 at 2019-08-07 11:33:33 -0700
|
51
|
+
Processing by ReportsController#custom_disposition as PDF
|
52
|
+
Rendering reports/custom_disposition.pdf.prawn
|
53
|
+
Rendered reports/custom_disposition.pdf.prawn (16.4ms)
|
54
|
+
Completed 200 OK in 20ms (Views: 19.4ms | ActiveRecord: 0.0ms)
|
55
|
+
[1m[35m (0.1ms)[0m [1m[31mrollback transaction[0m
|
56
|
+
[1m[35m (0.1ms)[0m [1m[36mbegin transaction[0m
|
57
|
+
---------------------------------------------
|
58
|
+
NavigationTest: test_Registers_:pdf_mime_type
|
59
|
+
---------------------------------------------
|
60
|
+
[1m[35m (0.1ms)[0m [1m[31mrollback transaction[0m
|
61
|
+
[1m[35m (0.1ms)[0m [1m[36mbegin transaction[0m
|
62
|
+
------------------------------------------
|
63
|
+
NavigationTest: test_Renders_pdf_to_string
|
64
|
+
------------------------------------------
|
65
|
+
Rendering reports/sample.pdf.prawn
|
66
|
+
Rendered reports/sample.pdf.prawn (72.0ms)
|
67
|
+
[1m[35m (0.1ms)[0m [1m[31mrollback transaction[0m
|
68
|
+
[1m[35m (0.1ms)[0m [1m[36mbegin transaction[0m
|
69
|
+
----------------------------------------------
|
70
|
+
NavigationTest: test_Renders_sample_pdf_action
|
71
|
+
----------------------------------------------
|
72
|
+
Started GET "/reports/sample?format=pdf" for 127.0.0.1 at 2019-08-07 11:33:33 -0700
|
73
|
+
Processing by ReportsController#sample as PDF
|
74
|
+
Rendering reports/sample.pdf.prawn
|
75
|
+
Rendered reports/sample.pdf.prawn (20.5ms)
|
76
|
+
Completed 200 OK in 22ms (Views: 21.2ms | ActiveRecord: 0.0ms)
|
77
|
+
[1m[35m (0.1ms)[0m [1m[31mrollback transaction[0m
|
78
|
+
[1m[35m (0.1ms)[0m [1m[36mbegin transaction[0m
|
79
|
+
--------------------------------------------------------------------
|
80
|
+
NavigationTest: test_Maintains_existing_'Content-Disposition'_header
|
81
|
+
--------------------------------------------------------------------
|
82
|
+
Started GET "/reports/custom_headers.pdf" for 127.0.0.1 at 2019-08-07 11:33:33 -0700
|
83
|
+
Processing by ReportsController#custom_headers as PDF
|
84
|
+
Rendering reports/custom.pdf.prawn
|
85
|
+
Rendered reports/custom.pdf.prawn (1.9ms)
|
86
|
+
Completed 200 OK in 3ms (Views: 2.5ms | ActiveRecord: 0.0ms)
|
87
|
+
[1m[35m (0.1ms)[0m [1m[31mrollback transaction[0m
|
88
|
+
[1m[35m (0.1ms)[0m [1m[36mbegin transaction[0m
|
89
|
+
-----------------------------------------------
|
90
|
+
NavigationTest: test_render_to_string_in_mailer
|
91
|
+
-----------------------------------------------
|
92
|
+
Rendering reports/sample.pdf.prawn
|
93
|
+
Rendered reports/sample.pdf.prawn (19.5ms)
|
94
|
+
Rendering reports_mailer/send_report.html.erb
|
95
|
+
Rendered reports_mailer/send_report.html.erb (0.4ms)
|
96
|
+
ReportsMailer#send_report: processed outbound mail in 280.1ms
|
97
|
+
[1m[35m (0.1ms)[0m [1m[31mrollback transaction[0m
|
98
|
+
[1m[35m (0.1ms)[0m [1m[36mbegin transaction[0m
|
99
|
+
---------------------------------------------------------
|
100
|
+
NavigationTest: test_Respects_the_'filename'_option_alone
|
101
|
+
---------------------------------------------------------
|
102
|
+
Started GET "/reports/custom_filename.pdf" for 127.0.0.1 at 2019-08-07 11:33:34 -0700
|
103
|
+
Processing by ReportsController#custom_filename as PDF
|
104
|
+
Rendering reports/custom_filename.pdf.prawn
|
105
|
+
Rendered reports/custom_filename.pdf.prawn (2.1ms)
|
106
|
+
Completed 200 OK in 4ms (Views: 2.8ms | ActiveRecord: 0.0ms)
|
107
|
+
[1m[35m (0.1ms)[0m [1m[31mrollback transaction[0m
|
108
|
+
[1m[35m (0.1ms)[0m [1m[36mbegin transaction[0m
|
109
|
+
--------------------------------------------------------------
|
110
|
+
PrawnRailsTest: test_matches_.PDF_extension_regardless_of_case
|
111
|
+
--------------------------------------------------------------
|
112
|
+
[1m[35m (0.1ms)[0m [1m[31mrollback transaction[0m
|
113
|
+
[1m[35m (0.1ms)[0m [1m[36mbegin transaction[0m
|
114
|
+
----------------------------------------------
|
115
|
+
PrawnRailsTest: test_text_can_take_non_strings
|
116
|
+
----------------------------------------------
|
117
|
+
[1m[35m (0.1ms)[0m [1m[31mrollback transaction[0m
|
@@ -0,0 +1 @@
|
|
1
|
+
I"�app/assets/javascripts/application.js?type=application/javascript&id=7b3a99820c71d7042d0378186f81e6ffd61c650a55f27cebcb852601ae05fa83:ET
|
@@ -0,0 +1 @@
|
|
1
|
+
I"�app/assets/stylesheets/application.css?type=text/css&pipeline=self&id=de1f6ddbeed2af709dcf36381627b030f3002cda655cc621dcb78b60b6120a69:ET
|
@@ -0,0 +1,2 @@
|
|
1
|
+
[o:Set:
|
2
|
+
@hash}I"environment-version:ETTI"environment-paths;TTI"rails-env;TTI"Lprocessors:type=application/javascript&file_type=application/javascript;TTI"8file-digest://app/assets/javascripts/application.js;TTI"Zprocessors:type=application/javascript&file_type=application/javascript&pipeline=self;TTF
|
Binary file
|
@@ -0,0 +1 @@
|
|
1
|
+
"%�汷g�d�Q~�A�fǟ��#�R��&�j�
|
@@ -0,0 +1 @@
|
|
1
|
+
"%��B�����șo�$'�A�d��L���xR�U
|
Binary file
|
Binary file
|
@@ -0,0 +1 @@
|
|
1
|
+
I"�app/assets/javascripts/application.js?type=application/javascript&pipeline=self&id=1111edca24b3df6c2857a3e3fe10a1fc3030827fb4be5ce1c5072f75d77c88fb:ET
|
Binary file
|
@@ -0,0 +1 @@
|
|
1
|
+
I"}app/assets/stylesheets/application.css?type=text/css&id=1fef9fc1245c63a4668490c81d3c6c1e5b485f76b14c9805b2f4bfbb005aebfe:ET
|
@@ -6,6 +6,15 @@ require 'pdf/reader'
|
|
6
6
|
class NavigationTest < ActionDispatch::IntegrationTest
|
7
7
|
fixtures :all
|
8
8
|
|
9
|
+
def confirm_pdf_format(source)
|
10
|
+
reader = PDF::Reader.new(StringIO.new(source))
|
11
|
+
assert_not_nil(reader)
|
12
|
+
assert_equal(1, reader.page_count)
|
13
|
+
page_str = reader.pages[0].to_s
|
14
|
+
assert page_str.include?('Hello World!')
|
15
|
+
assert_not page_str.include?("<h1>Hello World!</h1>")
|
16
|
+
end
|
17
|
+
|
9
18
|
test "Registers :pdf mime type" do
|
10
19
|
assert Mime::Type.lookup_by_extension(:pdf)
|
11
20
|
end
|
@@ -17,35 +26,20 @@ class NavigationTest < ActionDispatch::IntegrationTest
|
|
17
26
|
test "Renders html action" do
|
18
27
|
get '/reports/sample'
|
19
28
|
assert_response :success
|
20
|
-
#assert @response.body.include?("<h1>Hello World!</h1>")
|
21
29
|
assert_match("<h1>Hello World!</h1>", @response.body)
|
22
30
|
end
|
23
31
|
|
24
32
|
test "Renders pdf to string" do
|
25
33
|
pdf_str = ApplicationController.new.render_to_string("reports/sample.pdf", locals: {:@items => []})
|
26
34
|
|
27
|
-
|
28
|
-
assert_not_nil(reader)
|
29
|
-
|
30
|
-
page_str = reader.pages[0].to_s
|
31
|
-
assert page_str.include?('Hello World!')
|
32
|
-
assert_not page_str.include?("<h1>Hello World!</h1>")
|
35
|
+
confirm_pdf_format(pdf_str)
|
33
36
|
end
|
34
37
|
|
35
38
|
test "Renders sample pdf action" do
|
36
39
|
get '/reports/sample', params: {format: :pdf}
|
37
40
|
assert_response :success
|
38
|
-
assert_not @response.body.include?("<h1>Hello World!</h1>")
|
39
|
-
|
40
|
-
reader = PDF::Reader.new(StringIO.new(@response.body))
|
41
|
-
assert_not_nil(reader)
|
42
|
-
|
43
|
-
assert_equal(1, reader.page_count)
|
44
41
|
|
45
|
-
|
46
|
-
|
47
|
-
assert page_str.include?('Hello World!')
|
48
|
-
assert_not page_str.include?("<h1>Hello World!</h1>")
|
42
|
+
confirm_pdf_format(@response.body)
|
49
43
|
end
|
50
44
|
|
51
45
|
test "Renders table pdf action using auto-required plugin Prawn-Table" do
|
@@ -62,17 +56,50 @@ class NavigationTest < ActionDispatch::IntegrationTest
|
|
62
56
|
assert_equal(page_str, "1 2 3\n\n4 5 6\n\n7 8 9")
|
63
57
|
end
|
64
58
|
|
59
|
+
test "Sets file name from '@filename' when present" do
|
60
|
+
get '/reports/ivar_filename.pdf'
|
61
|
+
|
62
|
+
disposition_header = @response.headers["Content-Disposition"]
|
63
|
+
assert disposition_header.include?("attachment")
|
64
|
+
assert disposition_header.include?("ivar-filename.pdf")
|
65
|
+
end
|
66
|
+
|
67
|
+
test "Maintains existing 'Content-Disposition' header" do
|
68
|
+
get '/reports/custom_headers.pdf'
|
69
|
+
|
70
|
+
disposition_header = @response.headers["Content-Disposition"]
|
71
|
+
assert disposition_header.include?("attachment")
|
72
|
+
assert disposition_header.include?("custom-headers.pdf")
|
73
|
+
end
|
74
|
+
|
75
|
+
test "Respects the 'filename' option alone" do
|
76
|
+
get '/reports/custom_filename.pdf'
|
77
|
+
|
78
|
+
disposition_header = @response.headers["Content-Disposition"]
|
79
|
+
assert disposition_header.include?("inline")
|
80
|
+
assert disposition_header.include?("from-options.pdf")
|
81
|
+
end
|
82
|
+
|
83
|
+
test "Respects the 'disposition' option alone" do
|
84
|
+
get '/reports/custom_disposition.pdf'
|
85
|
+
|
86
|
+
disposition_header = @response.headers["Content-Disposition"]
|
87
|
+
assert disposition_header.include?("attachment")
|
88
|
+
assert_not disposition_header.include?("filename")
|
89
|
+
end
|
90
|
+
|
91
|
+
test "Respects both options on 'prawn-document' together" do
|
92
|
+
get '/reports/custom.pdf'
|
93
|
+
|
94
|
+
disposition_header = @response.headers["Content-Disposition"]
|
95
|
+
assert disposition_header.include?("attachment")
|
96
|
+
assert disposition_header.include?("from-options.pdf")
|
97
|
+
end
|
98
|
+
|
65
99
|
test "render_to_string in mailer" do
|
66
100
|
mail = ReportsMailer.send_report
|
67
101
|
assert_equal(1, mail.attachments.size)
|
68
102
|
|
69
|
-
|
70
|
-
assert_not_nil(reader)
|
71
|
-
assert_equal(1, reader.page_count)
|
72
|
-
|
73
|
-
page_str = reader.pages[0].to_s
|
74
|
-
|
75
|
-
assert page_str.include?('Hello World!')
|
76
|
-
assert_not page_str.include?("<h1>Hello World!</h1>")
|
103
|
+
confirm_pdf_format(mail.attachments["report.pdf"].body.raw_source)
|
77
104
|
end
|
78
105
|
end
|
data/test/prawn_rails_test.rb
CHANGED
@@ -7,8 +7,6 @@ class PrawnRailsTest < ActiveSupport::TestCase
|
|
7
7
|
include PrawnRails::RailsHelper
|
8
8
|
|
9
9
|
test "text can take non strings" do
|
10
|
-
@filename = ""
|
11
|
-
|
12
10
|
output = prawn_document do |pdf|
|
13
11
|
pdf.text "Number:"
|
14
12
|
pdf.text 10
|
@@ -20,4 +18,11 @@ class PrawnRailsTest < ActiveSupport::TestCase
|
|
20
18
|
page = reader.page(1).to_s
|
21
19
|
assert page.include?("Number:\n10")
|
22
20
|
end
|
21
|
+
|
22
|
+
test "matches .PDF extension regardless of case" do
|
23
|
+
["pDf", "pdf", "PDF"].each do |ext|
|
24
|
+
@filename = "test.#{ext}"
|
25
|
+
assert_equal get_metadata[:info][:Title], "test"
|
26
|
+
end
|
27
|
+
end
|
23
28
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prawn-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carlos Ortiz
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-07
|
12
|
+
date: 2019-08-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: prawn
|
@@ -147,6 +147,9 @@ files:
|
|
147
147
|
- test/dummy_app/app/controllers/reports_controller.rb
|
148
148
|
- test/dummy_app/app/mailers/reports_mailer.rb
|
149
149
|
- test/dummy_app/app/views/layouts/application.html.erb
|
150
|
+
- test/dummy_app/app/views/reports/custom.pdf.prawn
|
151
|
+
- test/dummy_app/app/views/reports/custom_disposition.pdf.prawn
|
152
|
+
- test/dummy_app/app/views/reports/custom_filename.pdf.prawn
|
150
153
|
- test/dummy_app/app/views/reports/sample.html.erb
|
151
154
|
- test/dummy_app/app/views/reports/sample.pdf.prawn
|
152
155
|
- test/dummy_app/app/views/reports/table.pdf.prawn
|
@@ -170,6 +173,22 @@ files:
|
|
170
173
|
- test/dummy_app/config/routes.rb
|
171
174
|
- test/dummy_app/config/secrets.yml
|
172
175
|
- test/dummy_app/db/schema.rb
|
176
|
+
- test/dummy_app/db/test.sqlite3
|
177
|
+
- test/dummy_app/log/test.log
|
178
|
+
- test/dummy_app/tmp/cache/assets/sprockets/v3.0/0Q/0QR6jgJcsDY23uF8NGHFYajkal8CGG4d3kOZQCD8Oj8.cache
|
179
|
+
- test/dummy_app/tmp/cache/assets/sprockets/v3.0/1K/1KcQYwe3g9uhY2WePD1_5P38IzP0Veu8rDPI0wXQSP8.cache
|
180
|
+
- test/dummy_app/tmp/cache/assets/sprockets/v3.0/3N/3NnKgR2TsTI1qCXKZpts0uJzp2dRJcoYp3nnFU6YE4o.cache
|
181
|
+
- test/dummy_app/tmp/cache/assets/sprockets/v3.0/4O/4O6Anm3R8aSIVfMhGtp5tZK3x17fcY1SbWoDN_6hb-o.cache
|
182
|
+
- test/dummy_app/tmp/cache/assets/sprockets/v3.0/4X/4XWDJRe7gZAeojFwJq7j6jJxRr152aQBfyhVtPPSHDY.cache
|
183
|
+
- test/dummy_app/tmp/cache/assets/sprockets/v3.0/7z/7zB4MNaDZMfwUPQ7LsLGHLt1EAx1oMCEUjywneVyoyY.cache
|
184
|
+
- test/dummy_app/tmp/cache/assets/sprockets/v3.0/8D/8D13-8wUZxyVgrsD9RHdWUPhLlWcqnHXtOBMOPQRX-Q.cache
|
185
|
+
- test/dummy_app/tmp/cache/assets/sprockets/v3.0/LR/LRLaw7viwBb9Mi_VFZxGbKIooy8Fqf1aB_iOTETsMyc.cache
|
186
|
+
- test/dummy_app/tmp/cache/assets/sprockets/v3.0/Mj/MjwYGG9GkHD1fwwH2bg66EBYl3zCA_mqeDF9otey4-U.cache
|
187
|
+
- test/dummy_app/tmp/cache/assets/sprockets/v3.0/Yr/YrGeNwkHFUXGwgJhi0aqJdEHL--OyRwU5aN5azmIXM4.cache
|
188
|
+
- test/dummy_app/tmp/cache/assets/sprockets/v3.0/ib/ibSeAobTqAE0a-v_-umXpnbXaIEx_WOtSsQkSRJCwwI.cache
|
189
|
+
- test/dummy_app/tmp/cache/assets/sprockets/v3.0/mO/mOu9n3QmqPXFbaUP-4RAuwabvsLdudRBvk9LMIOTSoI.cache
|
190
|
+
- test/dummy_app/tmp/cache/assets/sprockets/v3.0/vt/vtyC4n-7HZNOJV7EprjE7ThndKZkG00OVD8sO8cUFAM.cache
|
191
|
+
- test/dummy_app/tmp/cache/assets/sprockets/v3.0/wt/wtoVyr5IaVgQI72M_TLZFUNHeStJ5maRaHlfA8Vt6d0.cache
|
173
192
|
- test/integration/prawn_rails_test.rb
|
174
193
|
- test/prawn_rails_test.rb
|
175
194
|
- test/test_helper.rb
|
@@ -196,36 +215,55 @@ signing_key:
|
|
196
215
|
specification_version: 4
|
197
216
|
summary: Prawn Handler for Rails
|
198
217
|
test_files:
|
199
|
-
- test/integration/prawn_rails_test.rb
|
200
|
-
- test/prawn_rails_test.rb
|
201
|
-
- test/test_helper.rb
|
202
|
-
- test/dummy_app/Rakefile
|
203
|
-
- test/dummy_app/db/schema.rb
|
204
|
-
- test/dummy_app/app/mailers/reports_mailer.rb
|
205
|
-
- test/dummy_app/app/controllers/reports_controller.rb
|
206
|
-
- test/dummy_app/app/controllers/application_controller.rb
|
207
|
-
- test/dummy_app/app/assets/javascripts/application.js
|
208
|
-
- test/dummy_app/app/assets/stylesheets/application.css
|
209
218
|
- test/dummy_app/app/views/reports_mailer/send_report.html.erb
|
210
|
-
- test/dummy_app/app/views/
|
211
|
-
- test/dummy_app/app/views/reports/table.pdf.prawn
|
219
|
+
- test/dummy_app/app/views/reports/custom_filename.pdf.prawn
|
212
220
|
- test/dummy_app/app/views/reports/sample.pdf.prawn
|
221
|
+
- test/dummy_app/app/views/reports/custom.pdf.prawn
|
213
222
|
- test/dummy_app/app/views/reports/sample.html.erb
|
214
|
-
- test/dummy_app/
|
215
|
-
- test/dummy_app/
|
216
|
-
- test/dummy_app/
|
217
|
-
- test/dummy_app/
|
218
|
-
- test/dummy_app/
|
219
|
-
- test/dummy_app/
|
220
|
-
- test/dummy_app/
|
221
|
-
- test/dummy_app/
|
223
|
+
- test/dummy_app/app/views/reports/table.pdf.prawn
|
224
|
+
- test/dummy_app/app/views/reports/custom_disposition.pdf.prawn
|
225
|
+
- test/dummy_app/app/views/layouts/application.html.erb
|
226
|
+
- test/dummy_app/app/mailers/reports_mailer.rb
|
227
|
+
- test/dummy_app/app/assets/javascripts/application.js
|
228
|
+
- test/dummy_app/app/assets/stylesheets/application.css
|
229
|
+
- test/dummy_app/app/controllers/reports_controller.rb
|
230
|
+
- test/dummy_app/app/controllers/application_controller.rb
|
222
231
|
- test/dummy_app/config/environment.rb
|
232
|
+
- test/dummy_app/config/secrets.yml
|
233
|
+
- test/dummy_app/config/application.rb
|
234
|
+
- test/dummy_app/config/database.yml
|
223
235
|
- test/dummy_app/config/initializers/mime_types.rb
|
224
|
-
- test/dummy_app/config/initializers/prawn-rails.rb
|
225
|
-
- test/dummy_app/config/initializers/secret_token.rb
|
226
236
|
- test/dummy_app/config/initializers/backtrace_silencers.rb
|
227
|
-
- test/dummy_app/config/initializers/inflections.rb
|
228
237
|
- test/dummy_app/config/initializers/session_store.rb
|
238
|
+
- test/dummy_app/config/initializers/secret_token.rb
|
229
239
|
- test/dummy_app/config/initializers/wrap_parameters.rb
|
230
|
-
- test/dummy_app/config/
|
240
|
+
- test/dummy_app/config/initializers/prawn-rails.rb
|
241
|
+
- test/dummy_app/config/initializers/inflections.rb
|
242
|
+
- test/dummy_app/config/routes.rb
|
243
|
+
- test/dummy_app/config/locales/en.yml
|
244
|
+
- test/dummy_app/config/environments/production.rb
|
245
|
+
- test/dummy_app/config/environments/test.rb
|
246
|
+
- test/dummy_app/config/environments/development.rb
|
231
247
|
- test/dummy_app/config/boot.rb
|
248
|
+
- test/dummy_app/log/test.log
|
249
|
+
- test/dummy_app/config.ru
|
250
|
+
- test/dummy_app/Rakefile
|
251
|
+
- test/dummy_app/db/test.sqlite3
|
252
|
+
- test/dummy_app/db/schema.rb
|
253
|
+
- test/dummy_app/tmp/cache/assets/sprockets/v3.0/1K/1KcQYwe3g9uhY2WePD1_5P38IzP0Veu8rDPI0wXQSP8.cache
|
254
|
+
- test/dummy_app/tmp/cache/assets/sprockets/v3.0/8D/8D13-8wUZxyVgrsD9RHdWUPhLlWcqnHXtOBMOPQRX-Q.cache
|
255
|
+
- test/dummy_app/tmp/cache/assets/sprockets/v3.0/4O/4O6Anm3R8aSIVfMhGtp5tZK3x17fcY1SbWoDN_6hb-o.cache
|
256
|
+
- test/dummy_app/tmp/cache/assets/sprockets/v3.0/4X/4XWDJRe7gZAeojFwJq7j6jJxRr152aQBfyhVtPPSHDY.cache
|
257
|
+
- test/dummy_app/tmp/cache/assets/sprockets/v3.0/LR/LRLaw7viwBb9Mi_VFZxGbKIooy8Fqf1aB_iOTETsMyc.cache
|
258
|
+
- test/dummy_app/tmp/cache/assets/sprockets/v3.0/Mj/MjwYGG9GkHD1fwwH2bg66EBYl3zCA_mqeDF9otey4-U.cache
|
259
|
+
- test/dummy_app/tmp/cache/assets/sprockets/v3.0/mO/mOu9n3QmqPXFbaUP-4RAuwabvsLdudRBvk9LMIOTSoI.cache
|
260
|
+
- test/dummy_app/tmp/cache/assets/sprockets/v3.0/3N/3NnKgR2TsTI1qCXKZpts0uJzp2dRJcoYp3nnFU6YE4o.cache
|
261
|
+
- test/dummy_app/tmp/cache/assets/sprockets/v3.0/wt/wtoVyr5IaVgQI72M_TLZFUNHeStJ5maRaHlfA8Vt6d0.cache
|
262
|
+
- test/dummy_app/tmp/cache/assets/sprockets/v3.0/Yr/YrGeNwkHFUXGwgJhi0aqJdEHL--OyRwU5aN5azmIXM4.cache
|
263
|
+
- test/dummy_app/tmp/cache/assets/sprockets/v3.0/vt/vtyC4n-7HZNOJV7EprjE7ThndKZkG00OVD8sO8cUFAM.cache
|
264
|
+
- test/dummy_app/tmp/cache/assets/sprockets/v3.0/0Q/0QR6jgJcsDY23uF8NGHFYajkal8CGG4d3kOZQCD8Oj8.cache
|
265
|
+
- test/dummy_app/tmp/cache/assets/sprockets/v3.0/7z/7zB4MNaDZMfwUPQ7LsLGHLt1EAx1oMCEUjywneVyoyY.cache
|
266
|
+
- test/dummy_app/tmp/cache/assets/sprockets/v3.0/ib/ibSeAobTqAE0a-v_-umXpnbXaIEx_WOtSsQkSRJCwwI.cache
|
267
|
+
- test/prawn_rails_test.rb
|
268
|
+
- test/integration/prawn_rails_test.rb
|
269
|
+
- test/test_helper.rb
|