wicked_pdf 0.9.7 → 0.9.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -1
- data/lib/pdf_helper.rb +4 -2
- data/lib/wicked_pdf.rb +6 -1
- data/lib/wicked_pdf_helper.rb +20 -12
- data/lib/wicked_pdf_version.rb +1 -1
- data/test/dummy/log/test.log +138 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d43f635fb31fbe719908c988f8bb42ebc0b6e777
|
4
|
+
data.tar.gz: 25f0e915235ca7007cd20fb5bfb94107e38539b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bcc4d2b23469cc89e24d38325b22bb4a494c97c3f1087b03a657a5fc4b1bff49c75627faf98740c1cea3f7beba1a2ff19a9926fea97998697386ceef7b499f7c
|
7
|
+
data.tar.gz: 86788c652cada2dce61ec796b7b7673b13faca27eb11d9c2cd2b52586cc6b86cbee39ce80b872dbf1012635526f1a5e0b650245e37f63fc409f62490e3a2c903
|
data/README.md
CHANGED
@@ -29,7 +29,9 @@ WickedPdf.config = {
|
|
29
29
|
Note that versions before 0.9.0 [have problems](http://code.google.com/p/wkhtmltopdf/issues/detail?id=82&q=vodnik) on some machines with reading/writing to streams.
|
30
30
|
This plugin relies on streams to communicate with wkhtmltopdf.
|
31
31
|
|
32
|
-
|
32
|
+
For more information about wkhtmltopdf, see the project's [homepage](http://code.google.com/p/wkhtmltopdf/) and
|
33
|
+
[github repo](https://github.com/antialize/wkhtmltopdf). There's also some documentation for a recent, stable version
|
34
|
+
on the author's website, [here](http://madalgo.au.dk/~jakobt/wkhtmltoxdoc/wkhtmltopdf-0.9.9-doc.html).
|
33
35
|
|
34
36
|
Next:
|
35
37
|
|
@@ -286,6 +288,8 @@ If you use the standard `render :pdf => 'some_pdf'` in your app, you will want t
|
|
286
288
|
|
287
289
|
Andreas Happe's post [Generating PDFs from Ruby on Rails](http://www.snikt.net/blog/2012/04/26/wicked-pdf/)
|
288
290
|
|
291
|
+
JESii's post [WickedPDF, wkhtmltopdf, and Heroku...a tricky combination](http://www.nubyrubyrailstales.com/2013/06/wickedpdf-wkhtmltopdf-and-herokua.html)
|
292
|
+
|
289
293
|
StackOverflow [questions with the tag "wicked-pdf"](http://stackoverflow.com/questions/tagged/wicked-pdf)
|
290
294
|
|
291
295
|
### Debugging
|
data/lib/pdf_helper.rb
CHANGED
@@ -56,6 +56,7 @@ module PdfHelper
|
|
56
56
|
|
57
57
|
def make_pdf(options = {})
|
58
58
|
render_opts = {:template => options[:template], :layout => options[:layout], :formats => options[:formats], :handlers => options[:handlers]}
|
59
|
+
render_opts.merge!(:locals => options[:locals]) if options[:locals]
|
59
60
|
render_opts.merge!(:file => options[:file]) if options[:file]
|
60
61
|
html_string = render_to_string(render_opts)
|
61
62
|
options = prerender_header_and_footer(options)
|
@@ -70,6 +71,7 @@ module PdfHelper
|
|
70
71
|
options[:disposition] ||= "inline"
|
71
72
|
if options[:show_as_html]
|
72
73
|
render_opts = {:template => options[:template], :layout => options[:layout], :formats => options[:formats], :handlers => options[:handlers], :content_type => "text/html"}
|
74
|
+
render_opts.merge!(:locals => options[:locals]) if options[:locals]
|
73
75
|
render_opts.merge!(:file => options[:file]) if options[:file]
|
74
76
|
render(render_opts)
|
75
77
|
else
|
@@ -88,8 +90,8 @@ module PdfHelper
|
|
88
90
|
@hf_tempfiles.push( tf=WickedPdfTempfile.new("wicked_#{hf}_pdf.html") )
|
89
91
|
options[hf][:html][:layout] ||= options[:layout]
|
90
92
|
render_opts = {:template => options[hf][:html][:template], :layout => options[hf][:html][:layout], :formats => options[hf][:html][:formats], :handlers => options[hf][:html][:handlers]}
|
91
|
-
render_opts.merge!(
|
92
|
-
render_opts.merge!(
|
93
|
+
render_opts.merge!(:locals => options[hf][:html][:locals]) if options[hf][:html][:locals]
|
94
|
+
render_opts.merge!(:file => options[hf][:html][:file]) if options[:file]
|
93
95
|
tf.write render_to_string(render_opts)
|
94
96
|
tf.flush
|
95
97
|
options[hf][:html][:url] = "file:///#{tf.path}"
|
data/lib/wicked_pdf.rb
CHANGED
@@ -5,7 +5,12 @@ require 'logger'
|
|
5
5
|
require 'digest/md5'
|
6
6
|
require 'rbconfig'
|
7
7
|
require RbConfig::CONFIG['target_os'] == 'mingw32' && !(RUBY_VERSION =~ /1.9/) ? 'win32/open3' : 'open3'
|
8
|
-
|
8
|
+
|
9
|
+
begin
|
10
|
+
require 'active_support/core_ext/module/attribute_accessors'
|
11
|
+
rescue LoadError
|
12
|
+
require 'active_support/core_ext/class/attribute_accessors'
|
13
|
+
end
|
9
14
|
|
10
15
|
begin
|
11
16
|
require 'active_support/core_ext/object/blank'
|
data/lib/wicked_pdf_helper.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
|
1
3
|
module WickedPdfHelper
|
2
4
|
def self.root_path
|
3
5
|
String === Rails.root ? Pathname.new(Rails.root) : Rails.root
|
@@ -65,7 +67,7 @@ module WickedPdfHelper
|
|
65
67
|
URI_REGEXP = %r{^[-a-z]+://|^(?:cid|data):|^//}
|
66
68
|
|
67
69
|
def asset_pathname(source)
|
68
|
-
if Rails.configuration.assets.compile == false
|
70
|
+
if Rails.configuration.assets.compile == false || source.to_s[0] == '/'
|
69
71
|
if asset_path(source) =~ URI_REGEXP
|
70
72
|
# asset_path returns an absolute URL using asset_host if asset_host is set
|
71
73
|
asset_path(source)
|
@@ -78,18 +80,9 @@ module WickedPdfHelper
|
|
78
80
|
end
|
79
81
|
|
80
82
|
def read_asset(source)
|
81
|
-
if Rails.configuration.assets.compile == false
|
83
|
+
if Rails.configuration.assets.compile == false || source.to_s[0] == '/'
|
82
84
|
if asset_path(source) =~ URI_REGEXP
|
83
|
-
|
84
|
-
asset = open(asset_pathname(source), 'r:UTF-8') {|f| f.read }
|
85
|
-
if WickedPdf.config[:expect_gzipped_remote_assets]
|
86
|
-
begin
|
87
|
-
gz = Zlib::GzipReader.new(StringIO.new(asset))
|
88
|
-
asset = gz.read
|
89
|
-
rescue Zlib::GzipFile::Error
|
90
|
-
end
|
91
|
-
end
|
92
|
-
return asset
|
85
|
+
read_from_uri(source)
|
93
86
|
else
|
94
87
|
IO.read(asset_pathname(source))
|
95
88
|
end
|
@@ -97,5 +90,20 @@ module WickedPdfHelper
|
|
97
90
|
Rails.application.assets.find_asset(source).to_s
|
98
91
|
end
|
99
92
|
end
|
93
|
+
|
94
|
+
def read_from_uri(source)
|
95
|
+
encoding = 'UTF-8' if RUBY_VERSION > '1.8'
|
96
|
+
asset = open(asset_pathname(source), "r#{encoding}") {|f| f.read }
|
97
|
+
asset = gzip(asset) if WickedPdf.config[:expect_gzipped_remote_assets]
|
98
|
+
asset
|
99
|
+
end
|
100
|
+
|
101
|
+
def gzip(asset)
|
102
|
+
stringified_asset = StringIO.new(asset)
|
103
|
+
gzipper = Zlib::GzipReader.new(stringified_asset)
|
104
|
+
gzipped_asset = gzipper.read
|
105
|
+
rescue Zlib::GzipFile::Error
|
106
|
+
end
|
107
|
+
|
100
108
|
end
|
101
109
|
end
|
data/lib/wicked_pdf_version.rb
CHANGED
data/test/dummy/log/test.log
CHANGED
@@ -0,0 +1,138 @@
|
|
1
|
+
[1m[36m (0.2ms)[0m [1mbegin transaction[0m
|
2
|
+
----------------------------------------------------------
|
3
|
+
WickedPdfTest: test_should_extract_new_wkhtmltopdf_version
|
4
|
+
----------------------------------------------------------
|
5
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
6
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
7
|
+
----------------------------------------------------------
|
8
|
+
WickedPdfTest: test_should_extract_old_wkhtmltopdf_version
|
9
|
+
----------------------------------------------------------
|
10
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
11
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
12
|
+
----------------------------------------------------------------------------
|
13
|
+
WickedPdfTest: test_should_extract_wkhtmltopdf_version_with_nondigit_symbols
|
14
|
+
----------------------------------------------------------------------------
|
15
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
16
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
17
|
+
---------------------------------------------------------------------
|
18
|
+
WickedPdfTest: test_should_fallback_to_default_version_on_parse_error
|
19
|
+
---------------------------------------------------------------------
|
20
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
21
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
22
|
+
----------------------------------------------------------
|
23
|
+
WickedPdfTest: test_should_generate_PDF_from_html_document
|
24
|
+
----------------------------------------------------------
|
25
|
+
[1m[35m (0.2ms)[0m rollback transaction
|
26
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
27
|
+
--------------------------------------------------------------------------
|
28
|
+
WickedPdfTest: test_should_generate_PDF_from_html_document_with_long_lines
|
29
|
+
--------------------------------------------------------------------------
|
30
|
+
[1m[36m (0.2ms)[0m [1mbegin transaction[0m
|
31
|
+
----------------------------------------------------------
|
32
|
+
WickedPdfTest: test_should_extract_new_wkhtmltopdf_version
|
33
|
+
----------------------------------------------------------
|
34
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
35
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
36
|
+
----------------------------------------------------------
|
37
|
+
WickedPdfTest: test_should_extract_old_wkhtmltopdf_version
|
38
|
+
----------------------------------------------------------
|
39
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
40
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
41
|
+
----------------------------------------------------------------------------
|
42
|
+
WickedPdfTest: test_should_extract_wkhtmltopdf_version_with_nondigit_symbols
|
43
|
+
----------------------------------------------------------------------------
|
44
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
45
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
46
|
+
---------------------------------------------------------------------
|
47
|
+
WickedPdfTest: test_should_fallback_to_default_version_on_parse_error
|
48
|
+
---------------------------------------------------------------------
|
49
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
50
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
51
|
+
----------------------------------------------------------
|
52
|
+
WickedPdfTest: test_should_generate_PDF_from_html_document
|
53
|
+
----------------------------------------------------------
|
54
|
+
[1m[35m (0.2ms)[0m rollback transaction
|
55
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
56
|
+
--------------------------------------------------------------------------
|
57
|
+
WickedPdfTest: test_should_generate_PDF_from_html_document_with_long_lines
|
58
|
+
--------------------------------------------------------------------------
|
59
|
+
[1m[36m (0.2ms)[0m [1mbegin transaction[0m
|
60
|
+
----------------------------------------------------------
|
61
|
+
WickedPdfTest: test_should_extract_new_wkhtmltopdf_version
|
62
|
+
----------------------------------------------------------
|
63
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
64
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
65
|
+
----------------------------------------------------------
|
66
|
+
WickedPdfTest: test_should_extract_old_wkhtmltopdf_version
|
67
|
+
----------------------------------------------------------
|
68
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
69
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
70
|
+
----------------------------------------------------------------------------
|
71
|
+
WickedPdfTest: test_should_extract_wkhtmltopdf_version_with_nondigit_symbols
|
72
|
+
----------------------------------------------------------------------------
|
73
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
74
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
75
|
+
---------------------------------------------------------------------
|
76
|
+
WickedPdfTest: test_should_fallback_to_default_version_on_parse_error
|
77
|
+
---------------------------------------------------------------------
|
78
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
79
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
80
|
+
----------------------------------------------------------
|
81
|
+
WickedPdfTest: test_should_generate_PDF_from_html_document
|
82
|
+
----------------------------------------------------------
|
83
|
+
[1m[35m (0.2ms)[0m rollback transaction
|
84
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
85
|
+
--------------------------------------------------------------------------
|
86
|
+
WickedPdfTest: test_should_generate_PDF_from_html_document_with_long_lines
|
87
|
+
--------------------------------------------------------------------------
|
88
|
+
[1m[35m (0.2ms)[0m rollback transaction
|
89
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
90
|
+
----------------------------------------------------------
|
91
|
+
WickedPdfTest: test_should_parse_header_and_footer_options
|
92
|
+
----------------------------------------------------------
|
93
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
94
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
95
|
+
------------------------------------------------
|
96
|
+
WickedPdfTest: test_should_parse_margins_options
|
97
|
+
------------------------------------------------
|
98
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
99
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
100
|
+
----------------------------------------------
|
101
|
+
WickedPdfTest: test_should_parse_other_options
|
102
|
+
----------------------------------------------
|
103
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
104
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
105
|
+
------------------------------------------------
|
106
|
+
WickedPdfTest: test_should_parse_outline_options
|
107
|
+
------------------------------------------------
|
108
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
109
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
110
|
+
--------------------------------------------
|
111
|
+
WickedPdfTest: test_should_parse_toc_options
|
112
|
+
--------------------------------------------
|
113
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
114
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
115
|
+
----------------------------------------------------------------------
|
116
|
+
WickedPdfTest: test_should_raise_exception_when_no_path_to_wkhtmltopdf
|
117
|
+
----------------------------------------------------------------------
|
118
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
119
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
120
|
+
--------------------------------------------------------------------
|
121
|
+
WickedPdfTest: test_should_raise_exception_when_pdf_generation_fails
|
122
|
+
--------------------------------------------------------------------
|
123
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
124
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
125
|
+
-----------------------------------------------------------------------------
|
126
|
+
WickedPdfTest: test_should_raise_exception_when_wkhtmltopdf_is_not_executable
|
127
|
+
-----------------------------------------------------------------------------
|
128
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
129
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
130
|
+
-------------------------------------------------------------------------
|
131
|
+
WickedPdfTest: test_should_raise_exception_when_wkhtmltopdf_path_is_wrong
|
132
|
+
-------------------------------------------------------------------------
|
133
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
134
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
135
|
+
------------------------------------------------------------
|
136
|
+
WickedPdfTest: test_should_set_Default_version_on_initialize
|
137
|
+
------------------------------------------------------------
|
138
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wicked_pdf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miles Z. Sterret
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-09
|
11
|
+
date: 2013-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -130,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
130
130
|
version: '0'
|
131
131
|
requirements: []
|
132
132
|
rubyforge_project:
|
133
|
-
rubygems_version: 2.0.
|
133
|
+
rubygems_version: 2.0.14
|
134
134
|
signing_key:
|
135
135
|
specification_version: 4
|
136
136
|
summary: PDF generator (from HTML) gem for Ruby on Rails
|