wicked_pdf 0.9.7 → 0.9.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6138e8df9d261ac839ffbe90e43ad3984f915faf
4
- data.tar.gz: 32d4515ad98acb4911bdb69a372661b7c218e4a7
3
+ metadata.gz: d43f635fb31fbe719908c988f8bb42ebc0b6e777
4
+ data.tar.gz: 25f0e915235ca7007cd20fb5bfb94107e38539b3
5
5
  SHA512:
6
- metadata.gz: 3733372cc997b0c6e42c996c530cbc86019df8bec3e1cd951a6958f8e5e355eb2e8eb5a23c19e8b147d103fb087a61dd2725c049efec0f605ada14a22e02f08c
7
- data.tar.gz: 4be3f26f6ffbd68b700853780dcc82a0949906747d5383c13f2f6bbf3c736b509b3b2c04ee154caa1a02fa7ef9b6065aaf61fc741567a1c25d48aad397c5d27d
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
- More information about [wkhtmltopdf](http://code.google.com/p/wkhtmltopdf/) could be found [here](http://madalgo.au.dk/~jakobt/wkhtmltoxdoc/wkhtmltopdf-0.9.9-doc.html).
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!({:locals => options[hf][:html][:locals]}) if options[hf][:html][:locals]
92
- render_opts.merge!({:file => options[hf][:html][:file]}) if options[:file]
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
- require 'active_support/core_ext/class/attribute_accessors'
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'
@@ -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
- require 'open-uri'
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
@@ -1,3 +1,3 @@
1
1
  class WickedPdf
2
- VERSION = '0.9.7'
2
+ VERSION = '0.9.8'
3
3
  end
@@ -0,0 +1,138 @@
1
+  (0.2ms) begin transaction
2
+ ----------------------------------------------------------
3
+ WickedPdfTest: test_should_extract_new_wkhtmltopdf_version
4
+ ----------------------------------------------------------
5
+  (0.1ms) rollback transaction
6
+  (0.1ms) begin transaction
7
+ ----------------------------------------------------------
8
+ WickedPdfTest: test_should_extract_old_wkhtmltopdf_version
9
+ ----------------------------------------------------------
10
+  (0.0ms) rollback transaction
11
+  (0.0ms) begin transaction
12
+ ----------------------------------------------------------------------------
13
+ WickedPdfTest: test_should_extract_wkhtmltopdf_version_with_nondigit_symbols
14
+ ----------------------------------------------------------------------------
15
+  (0.0ms) rollback transaction
16
+  (0.0ms) begin transaction
17
+ ---------------------------------------------------------------------
18
+ WickedPdfTest: test_should_fallback_to_default_version_on_parse_error
19
+ ---------------------------------------------------------------------
20
+  (0.0ms) rollback transaction
21
+  (0.0ms) begin transaction
22
+ ----------------------------------------------------------
23
+ WickedPdfTest: test_should_generate_PDF_from_html_document
24
+ ----------------------------------------------------------
25
+  (0.2ms) rollback transaction
26
+  (0.1ms) begin transaction
27
+ --------------------------------------------------------------------------
28
+ WickedPdfTest: test_should_generate_PDF_from_html_document_with_long_lines
29
+ --------------------------------------------------------------------------
30
+  (0.2ms) begin transaction
31
+ ----------------------------------------------------------
32
+ WickedPdfTest: test_should_extract_new_wkhtmltopdf_version
33
+ ----------------------------------------------------------
34
+  (0.1ms) rollback transaction
35
+  (0.0ms) begin transaction
36
+ ----------------------------------------------------------
37
+ WickedPdfTest: test_should_extract_old_wkhtmltopdf_version
38
+ ----------------------------------------------------------
39
+  (0.0ms) rollback transaction
40
+  (0.0ms) begin transaction
41
+ ----------------------------------------------------------------------------
42
+ WickedPdfTest: test_should_extract_wkhtmltopdf_version_with_nondigit_symbols
43
+ ----------------------------------------------------------------------------
44
+  (0.0ms) rollback transaction
45
+  (0.0ms) begin transaction
46
+ ---------------------------------------------------------------------
47
+ WickedPdfTest: test_should_fallback_to_default_version_on_parse_error
48
+ ---------------------------------------------------------------------
49
+  (0.0ms) rollback transaction
50
+  (0.0ms) begin transaction
51
+ ----------------------------------------------------------
52
+ WickedPdfTest: test_should_generate_PDF_from_html_document
53
+ ----------------------------------------------------------
54
+  (0.2ms) rollback transaction
55
+  (0.1ms) begin transaction
56
+ --------------------------------------------------------------------------
57
+ WickedPdfTest: test_should_generate_PDF_from_html_document_with_long_lines
58
+ --------------------------------------------------------------------------
59
+  (0.2ms) begin transaction
60
+ ----------------------------------------------------------
61
+ WickedPdfTest: test_should_extract_new_wkhtmltopdf_version
62
+ ----------------------------------------------------------
63
+  (0.1ms) rollback transaction
64
+  (0.1ms) begin transaction
65
+ ----------------------------------------------------------
66
+ WickedPdfTest: test_should_extract_old_wkhtmltopdf_version
67
+ ----------------------------------------------------------
68
+  (0.0ms) rollback transaction
69
+  (0.0ms) begin transaction
70
+ ----------------------------------------------------------------------------
71
+ WickedPdfTest: test_should_extract_wkhtmltopdf_version_with_nondigit_symbols
72
+ ----------------------------------------------------------------------------
73
+  (0.0ms) rollback transaction
74
+  (0.0ms) begin transaction
75
+ ---------------------------------------------------------------------
76
+ WickedPdfTest: test_should_fallback_to_default_version_on_parse_error
77
+ ---------------------------------------------------------------------
78
+  (0.0ms) rollback transaction
79
+  (0.0ms) begin transaction
80
+ ----------------------------------------------------------
81
+ WickedPdfTest: test_should_generate_PDF_from_html_document
82
+ ----------------------------------------------------------
83
+  (0.2ms) rollback transaction
84
+  (0.1ms) begin transaction
85
+ --------------------------------------------------------------------------
86
+ WickedPdfTest: test_should_generate_PDF_from_html_document_with_long_lines
87
+ --------------------------------------------------------------------------
88
+  (0.2ms) rollback transaction
89
+  (0.0ms) begin transaction
90
+ ----------------------------------------------------------
91
+ WickedPdfTest: test_should_parse_header_and_footer_options
92
+ ----------------------------------------------------------
93
+  (0.0ms) rollback transaction
94
+  (0.0ms) begin transaction
95
+ ------------------------------------------------
96
+ WickedPdfTest: test_should_parse_margins_options
97
+ ------------------------------------------------
98
+  (0.0ms) rollback transaction
99
+  (0.0ms) begin transaction
100
+ ----------------------------------------------
101
+ WickedPdfTest: test_should_parse_other_options
102
+ ----------------------------------------------
103
+  (0.0ms) rollback transaction
104
+  (0.0ms) begin transaction
105
+ ------------------------------------------------
106
+ WickedPdfTest: test_should_parse_outline_options
107
+ ------------------------------------------------
108
+  (0.0ms) rollback transaction
109
+  (0.0ms) begin transaction
110
+ --------------------------------------------
111
+ WickedPdfTest: test_should_parse_toc_options
112
+ --------------------------------------------
113
+  (0.0ms) rollback transaction
114
+  (0.0ms) begin transaction
115
+ ----------------------------------------------------------------------
116
+ WickedPdfTest: test_should_raise_exception_when_no_path_to_wkhtmltopdf
117
+ ----------------------------------------------------------------------
118
+  (0.0ms) rollback transaction
119
+  (0.0ms) begin transaction
120
+ --------------------------------------------------------------------
121
+ WickedPdfTest: test_should_raise_exception_when_pdf_generation_fails
122
+ --------------------------------------------------------------------
123
+  (0.1ms) rollback transaction
124
+  (0.0ms) begin transaction
125
+ -----------------------------------------------------------------------------
126
+ WickedPdfTest: test_should_raise_exception_when_wkhtmltopdf_is_not_executable
127
+ -----------------------------------------------------------------------------
128
+  (0.0ms) rollback transaction
129
+  (0.0ms) begin transaction
130
+ -------------------------------------------------------------------------
131
+ WickedPdfTest: test_should_raise_exception_when_wkhtmltopdf_path_is_wrong
132
+ -------------------------------------------------------------------------
133
+  (0.0ms) rollback transaction
134
+  (0.0ms) begin transaction
135
+ ------------------------------------------------------------
136
+ WickedPdfTest: test_should_set_Default_version_on_initialize
137
+ ------------------------------------------------------------
138
+  (0.0ms) 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.7
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-18 00:00:00.000000000 Z
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.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