wicked_pdf 0.9.6 → 0.9.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6138e8df9d261ac839ffbe90e43ad3984f915faf
4
+ data.tar.gz: 32d4515ad98acb4911bdb69a372661b7c218e4a7
5
+ SHA512:
6
+ metadata.gz: 3733372cc997b0c6e42c996c530cbc86019df8bec3e1cd951a6958f8e5e355eb2e8eb5a23c19e8b147d103fb087a61dd2725c049efec0f605ada14a22e02f08c
7
+ data.tar.gz: 4be3f26f6ffbd68b700853780dcc82a0949906747d5383c13f2f6bbf3c736b509b3b2c04ee154caa1a02fa7ef9b6065aaf61fc741567a1c25d48aad397c5d27d
data/README.md CHANGED
@@ -9,10 +9,23 @@ _Wicked PDF has been verified to work on Ruby 1.8.7 and 1.9.2; Rails 2 and Rails
9
9
  ### Installation
10
10
 
11
11
  First, be sure to install [wkhtmltopdf](http://code.google.com/p/wkhtmltopdf/).
12
+
13
+ One simple way to install all of the binaries (Linux, OSX, Windows) is through the gem [wkhtmltopdf-binary](https://github.com/steerio/wkhtmltopdf-binary).
14
+ To install, simply add
15
+
16
+ ```ruby
17
+ gem 'wkhtmltopdf-binary'
18
+ ```
19
+
20
+ To your Gemfile.
21
+
12
22
  If your wkhtmltopdf executable is not on your webserver's path, configure it in an initializer:
13
- WickedPdf.config = {
14
- :exe_path => '/usr/local/bin/wkhtmltopdf'
15
- }
23
+
24
+ ```ruby
25
+ WickedPdf.config = {
26
+ :exe_path => '/usr/local/bin/wkhtmltopdf'
27
+ }
28
+ ```
16
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.
17
30
  This plugin relies on streams to communicate with wkhtmltopdf.
18
31
 
@@ -25,7 +38,9 @@ Next:
25
38
 
26
39
  or add this to your Gemfile:
27
40
 
28
- gem 'wicked_pdf'
41
+ ```ruby
42
+ gem 'wicked_pdf'
43
+ ```
29
44
 
30
45
  You may also need to add
31
46
  ```ruby
@@ -34,197 +49,219 @@ Mime::Type.register "application/pdf", :pdf
34
49
  to `config/initializers/mime_types.rb`
35
50
 
36
51
  ### Basic Usage
37
-
38
- class ThingsController < ApplicationController
39
- def show
40
- respond_to do |format|
41
- format.html
42
- format.pdf do
43
- render :pdf => "file_name"
44
- end
45
- end
52
+ ```ruby
53
+ class ThingsController < ApplicationController
54
+ def show
55
+ respond_to do |format|
56
+ format.html
57
+ format.pdf do
58
+ render :pdf => "file_name"
46
59
  end
47
60
  end
61
+ end
62
+ end
63
+ ```
64
+ ### Usage Conditions - Important!
65
+
66
+ The wkhtmltopdf binary is run outside of your Rails application; therefore, your normal layouts will not work. If you plan to use any CSS, Javascript, or image files, you must modify your layout so that you provide an absolute reference to these files. The best option for Rails without the asset pipeline is to use the `wicked_pdf_stylesheet_link_tag`, `wicked_pdf_image_tag`, and `wicked_pdf_javascript_include_tag` helpers or to go straight to a CDN (Content Delivery Network) for popular libraries such as jQuery.
67
+
68
+ #### wicked_pdf helpers
69
+ ```html
70
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
71
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
72
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
73
+ <head>
74
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
75
+ <%= wicked_pdf_stylesheet_link_tag "pdf" -%>
76
+ <%= wicked_pdf_javascript_include_tag "number_pages" %>
77
+ </head>
78
+ <body onload='number_pages'>
79
+ <div id="header">
80
+ <%= wicked_pdf_image_tag 'mysite.jpg' %>
81
+ </div>
82
+ <div id="content">
83
+ <%= yield %>
84
+ </div>
85
+ </body>
86
+ </html>
87
+ ```
88
+ #### CDN reference
48
89
 
49
- ### Advanced Usage with all available options
90
+ In this case, you can use that standard Rails helpers and point to the current CDN for whichever framework you are using. For jQuery, it would look somethng like this, given the current versions at the time of this writing.
91
+ ```html
92
+ <!DOCTYPE...
93
+ <html...
94
+ <head>
95
+ <%= javascript_include_tag "http://code.jquery.com/jquery-1.10.0.min.js" %>
96
+ <%= javascript_include_tag "http://code.jquery.com/ui/1.10.3/jquery-ui.min.js" %>
97
+ ```
98
+ #### Asset pipeline usage
50
99
 
51
- class ThingsController < ApplicationController
52
- def show
53
- respond_to do |format|
54
- format.html
55
- format.pdf do
56
- render :pdf => 'file_name',
57
- :disposition => 'attachment', # default 'inline'
58
- :template => 'things/show.pdf.erb',
59
- :file => "#{Rails.root}/files/foo.erb"
60
- :layout => 'pdf.html', # use 'pdf.html' for a pdf.html.erb file
61
- :wkhtmltopdf => '/usr/local/bin/wkhtmltopdf', # path to binary
62
- :show_as_html => params[:debug].present?, # allow debuging based on url param
63
- :orientation => 'Landscape', # default Portrait
64
- :page_size => 'A4, Letter, ...', # default A4
65
- :save_to_file => Rails.root.join('pdfs', "#{filename}.pdf"),
66
- :save_only => false, # depends on :save_to_file being set first
67
- :proxy => 'TEXT',
68
- :basic_auth => false # when true username & password are automatically sent from session
69
- :username => 'TEXT',
70
- :password => 'TEXT',
71
- :cover => 'URL',
72
- :dpi => 'dpi',
73
- :encoding => 'TEXT',
74
- :user_style_sheet => 'URL',
75
- :cookie => ['_session_id SESSION_ID'], # could be an array or a single string in a 'name value' format
76
- :post => ['query QUERY_PARAM'], # could be an array or a single string in a 'name value' format
77
- :redirect_delay => NUMBER,
78
- :zoom => FLOAT,
79
- :page_offset => NUMBER,
80
- :book => true,
81
- :default_header => true,
82
- :disable_javascript => false,
83
- :grayscale => true,
84
- :lowquality => true,
85
- :enable_plugins => true,
86
- :disable_internal_links => true,
87
- :disable_external_links => true,
88
- :print_media_type => true,
89
- :disable_smart_shrinking => true,
90
- :use_xserver => true,
91
- :no_background => true,
92
- :extra => '' # directly inserted into the command to wkhtmltopdf
93
- :margin => {:top => SIZE, # default 10 (mm)
94
- :bottom => SIZE,
95
- :left => SIZE,
96
- :right => SIZE},
97
- :header => {:html => { :template => 'users/header.pdf.erb', # use :template OR :url
98
- :layout => 'pdf_plain.html', # optional, use 'pdf_plain.html' for a pdf_plain.html.erb file, defaults to main layout
99
- :url => 'www.example.com',
100
- :locals => { :foo => @bar }},
101
- :center => 'TEXT',
102
- :font_name => 'NAME',
103
- :font_size => SIZE,
104
- :left => 'TEXT',
105
- :right => 'TEXT',
106
- :spacing => REAL,
107
- :line => true,
108
- :content => 'HTML CONTENT ALREADY RENDERED'}, # optionally you can pass plain html already rendered (useful if using pdf_from_string)
109
- :footer => {:html => { :template => 'shared/footer.pdf.erb', # use :template OR :url
110
- :layout => 'pdf_plain.html', # optional, use 'pdf_plain.html' for a pdf_plain.html.erb file, defaults to main layout
111
- :url => 'www.example.com',
112
- :locals => { :foo => @bar }},
113
- :center => 'TEXT',
114
- :font_name => 'NAME',
115
- :font_size => SIZE,
116
- :left => 'TEXT',
117
- :right => 'TEXT',
118
- :spacing => REAL,
119
- :line => true,
120
- :content => 'HTML CONTENT ALREADY RENDERED'}, # optionally you can pass plain html already rendered (useful if using pdf_from_string)
121
- :toc => {:font_name => "NAME",
122
- :depth => LEVEL,
123
- :header_text => "TEXT",
124
- :header_fs => SIZE,
125
- :l1_font_size => SIZE,
126
- :l2_font_size => SIZE,
127
- :l3_font_size => SIZE,
128
- :l4_font_size => SIZE,
129
- :l5_font_size => SIZE,
130
- :l6_font_size => SIZE,
131
- :l7_font_size => SIZE,
132
- :l1_indentation => NUM,
133
- :l2_indentation => NUM,
134
- :l3_indentation => NUM,
135
- :l4_indentation => NUM,
136
- :l5_indentation => NUM,
137
- :l6_indentation => NUM,
138
- :l7_indentation => NUM,
139
- :no_dots => true,
140
- :disable_links => true,
141
- :disable_back_links => true},
142
- :outline => {:outline => true,
143
- :outline_depth => LEVEL}
144
- end
145
- end
100
+ The way to handle this for the asset pipeline on Heroku is to include these files in your asset precompile list, as follows:
101
+
102
+ config.assets.precompile += ['blueprint/screen.css', 'pdf.css', 'jquery.ui.datepicker.js', 'pdf.js', ...etc...]
103
+
104
+ ### Advanced Usage with all available options
105
+ ```ruby
106
+ class ThingsController < ApplicationController
107
+ def show
108
+ respond_to do |format|
109
+ format.html
110
+ format.pdf do
111
+ render :pdf => 'file_name',
112
+ :disposition => 'attachment', # default 'inline'
113
+ :template => 'things/show.pdf.erb',
114
+ :file => "#{Rails.root}/files/foo.erb"
115
+ :layout => 'pdf.html', # use 'pdf.html' for a pdf.html.erb file
116
+ :wkhtmltopdf => '/usr/local/bin/wkhtmltopdf', # path to binary
117
+ :show_as_html => params[:debug].present?, # allow debuging based on url param
118
+ :orientation => 'Landscape', # default Portrait
119
+ :page_size => 'A4, Letter, ...', # default A4
120
+ :save_to_file => Rails.root.join('pdfs', "#{filename}.pdf"),
121
+ :save_only => false, # depends on :save_to_file being set first
122
+ :proxy => 'TEXT',
123
+ :basic_auth => false # when true username & password are automatically sent from session
124
+ :username => 'TEXT',
125
+ :password => 'TEXT',
126
+ :cover => 'URL',
127
+ :dpi => 'dpi',
128
+ :encoding => 'TEXT',
129
+ :user_style_sheet => 'URL',
130
+ :cookie => ['_session_id SESSION_ID'], # could be an array or a single string in a 'name value' format
131
+ :post => ['query QUERY_PARAM'], # could be an array or a single string in a 'name value' format
132
+ :redirect_delay => NUMBER,
133
+ :javascript_delay => NUMBER,
134
+ :zoom => FLOAT,
135
+ :page_offset => NUMBER,
136
+ :book => true,
137
+ :default_header => true,
138
+ :disable_javascript => false,
139
+ :grayscale => true,
140
+ :lowquality => true,
141
+ :enable_plugins => true,
142
+ :disable_internal_links => true,
143
+ :disable_external_links => true,
144
+ :print_media_type => true,
145
+ :disable_smart_shrinking => true,
146
+ :use_xserver => true,
147
+ :no_background => true,
148
+ :extra => '' # directly inserted into the command to wkhtmltopdf
149
+ :margin => {:top => SIZE, # default 10 (mm)
150
+ :bottom => SIZE,
151
+ :left => SIZE,
152
+ :right => SIZE},
153
+ :header => {:html => { :template => 'users/header.pdf.erb', # use :template OR :url
154
+ :layout => 'pdf_plain.html', # optional, use 'pdf_plain.html' for a pdf_plain.html.erb file, defaults to main layout
155
+ :url => 'www.example.com',
156
+ :locals => { :foo => @bar }},
157
+ :center => 'TEXT',
158
+ :font_name => 'NAME',
159
+ :font_size => SIZE,
160
+ :left => 'TEXT',
161
+ :right => 'TEXT',
162
+ :spacing => REAL,
163
+ :line => true,
164
+ :content => 'HTML CONTENT ALREADY RENDERED'}, # optionally you can pass plain html already rendered (useful if using pdf_from_string)
165
+ :footer => {:html => { :template => 'shared/footer.pdf.erb', # use :template OR :url
166
+ :layout => 'pdf_plain.html', # optional, use 'pdf_plain.html' for a pdf_plain.html.erb file, defaults to main layout
167
+ :url => 'www.example.com',
168
+ :locals => { :foo => @bar }},
169
+ :center => 'TEXT',
170
+ :font_name => 'NAME',
171
+ :font_size => SIZE,
172
+ :left => 'TEXT',
173
+ :right => 'TEXT',
174
+ :spacing => REAL,
175
+ :line => true,
176
+ :content => 'HTML CONTENT ALREADY RENDERED'}, # optionally you can pass plain html already rendered (useful if using pdf_from_string)
177
+ :toc => {:font_name => "NAME",
178
+ :depth => LEVEL,
179
+ :header_text => "TEXT",
180
+ :header_fs => SIZE,
181
+ :l1_font_size => SIZE,
182
+ :l2_font_size => SIZE,
183
+ :l3_font_size => SIZE,
184
+ :l4_font_size => SIZE,
185
+ :l5_font_size => SIZE,
186
+ :l6_font_size => SIZE,
187
+ :l7_font_size => SIZE,
188
+ :l1_indentation => NUM,
189
+ :l2_indentation => NUM,
190
+ :l3_indentation => NUM,
191
+ :l4_indentation => NUM,
192
+ :l5_indentation => NUM,
193
+ :l6_indentation => NUM,
194
+ :l7_indentation => NUM,
195
+ :no_dots => true,
196
+ :disable_links => true,
197
+ :disable_back_links => true},
198
+ :outline => {:outline => true,
199
+ :outline_depth => LEVEL}
146
200
  end
147
201
  end
148
-
202
+ end
203
+ end
204
+ ```
149
205
  By default, it will render without a layout (:layout => false) and the template for the current controller and action.
150
206
 
151
207
  ### Super Advanced Usage ###
152
208
 
153
209
  If you need to just create a pdf and not display it:
154
-
155
- # create a pdf from a string
156
- pdf = WickedPdf.new.pdf_from_string('<h1>Hello There!</h1>')
157
-
158
- # create a pdf from string using templates, layouts and content option for header or footer
159
- WickedPdf.new.pdf_from_string(
160
- render_to_string(:pdf => "pdf_file.pdf", :template => 'templates/pdf.html.erb', :layout => 'pdfs/layout_pdf'),
161
- :footer => {:content => render_to_string({:template => 'templates/pdf_footer.html.erb', :layout => 'pdfs/layout_pdf'})}
162
- )
163
- # or from your controller, using views & templates and all wicked_pdf options as normal
164
- pdf = render_to_string :pdf => "some_file_name"
210
+ ```ruby
211
+ # create a pdf from a string
212
+ pdf = WickedPdf.new.pdf_from_string('<h1>Hello There!</h1>')
213
+
214
+ # create a pdf from string using templates, layouts and content option for header or footer
215
+ WickedPdf.new.pdf_from_string(
216
+ render_to_string('templates/pdf.html.erb', :layout => 'pdfs/layout_pdf'),
217
+ :footer => {
218
+ :content => render_to_string(:layout => 'pdfs/layout_pdf')
219
+ }
220
+ )
221
+
222
+ # or from your controller, using views & templates and all wicked_pdf options as normal
223
+ pdf = render_to_string :pdf => "some_file_name"
165
224
 
166
- # then save to a file
167
- save_path = Rails.root.join('pdfs','filename.pdf')
168
- File.open(save_path, 'wb') do |file|
169
- file << pdf
170
- end
171
-
225
+ # then save to a file
226
+ save_path = Rails.root.join('pdfs','filename.pdf')
227
+ File.open(save_path, 'wb') do |file|
228
+ file << pdf
229
+ end
230
+ ```
172
231
  If you need to display utf encoded characters, add this to your pdf views or layouts:
173
-
174
- <meta http-equiv="content-type" content="text/html; charset=utf-8" />
175
-
176
- ### Styles
177
-
178
- You must define absolute paths to CSS files, images, and javascripts; the best option is to use the *wicked_pdf_stylesheet_link_tag*, *wicked_pdf_image_tag*, and *wicked_pdf_javascript_include_tag* helpers.
179
-
180
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
181
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
182
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
183
- <head>
184
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
185
- <%= wicked_pdf_stylesheet_link_tag "pdf" -%>
186
- <%= wicked_pdf_javascript_include_tag "number_pages" %>
187
- </head>
188
- <body onload='number_pages'>
189
- <div id="header">
190
- <%= wicked_pdf_image_tag 'mysite.jpg' %>
191
- </div>
192
- <div id="content">
193
- <%= yield %>
194
- </div>
195
- </body>
196
- </html>
197
-
232
+ ```html
233
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
234
+ ```
198
235
  ### Page Numbering
199
236
 
200
237
  A bit of javascript can help you number your pages. Create a template or header/footer file with this:
201
-
202
- <html>
203
- <head>
204
- <script>
205
- function number_pages() {
206
- var vars={};
207
- var x=document.location.search.substring(1).split('&');
208
- for(var i in x) {var z=x[i].split('=',2);vars[z[0]] = unescape(z[1]);}
209
- var x=['frompage','topage','page','webpage','section','subsection','subsubsection'];
210
- for(var i in x) {
211
- var y = document.getElementsByClassName(x[i]);
212
- for(var j=0; j<y.length; ++j) y[j].textContent = vars[x[i]];
213
- }
214
- }
215
- </script>
216
- </head>
217
- <body onload="number_pages()">
218
- Page <span class="page"></span> of <span class="topage"></span>
219
- </body>
220
- </html>
221
-
238
+ ```html
239
+ <html>
240
+ <head>
241
+ <script>
242
+ function number_pages() {
243
+ var vars={};
244
+ var x=document.location.search.substring(1).split('&');
245
+ for(var i in x) {var z=x[i].split('=',2);vars[z[0]] = unescape(z[1]);}
246
+ var x=['frompage','topage','page','webpage','section','subsection','subsubsection'];
247
+ for(var i in x) {
248
+ var y = document.getElementsByClassName(x[i]);
249
+ for(var j=0; j<y.length; ++j) y[j].textContent = vars[x[i]];
250
+ }
251
+ }
252
+ </script>
253
+ </head>
254
+ <body onload="number_pages()">
255
+ Page <span class="page"></span> of <span class="topage"></span>
256
+ </body>
257
+ </html>
258
+ ```
222
259
  Anything with a class listed in "var x" above will be auto-filled at render time.
223
260
 
224
261
  If you do not have explicit page breaks (and therefore do not have any "page" class), you can also use wkhtmltopdf's built in page number generation by setting one of the headers to "[page]":
225
-
226
- render :pdf => 'filename', :header => { :right => '[page] of [topage]' }
227
-
262
+ ```ruby
263
+ render :pdf => 'filename', :header => { :right => '[page] of [topage]' }
264
+ ```
228
265
  ### Configuration
229
266
 
230
267
  You can put your default configuration, applied to all pdf's at "wicked_pdf.rb" initializer.
@@ -232,17 +269,17 @@ You can put your default configuration, applied to all pdf's at "wicked_pdf.rb"
232
269
  ### Rack Middleware
233
270
 
234
271
  If you would like to have WickedPdf automatically generate PDF views for all (or nearly all) pages by appending .pdf to the URL, add the following to your Rails app:
235
-
236
- # in application.rb (Rails3) or environment.rb (Rails2)
237
- require 'wicked_pdf'
238
- config.middleware.use WickedPdf::Middleware
239
-
272
+ ```ruby
273
+ # in application.rb (Rails3) or environment.rb (Rails2)
274
+ require 'wicked_pdf'
275
+ config.middleware.use WickedPdf::Middleware
276
+ ```
240
277
  If you want to turn on or off the middleware for certain urls, use the `:only` or `:except` conditions like so:
241
-
242
- # conditions can be plain strings or regular expressions, and you can supply only one or an array
243
- config.middleware.use WickedPdf::Middleware, {}, :only => '/invoice'
244
- config.middleware.use WickedPdf::Middleware, {}, :except => [ %r[^/admin], '/secret', %r[^/people/\d] ]
245
-
278
+ ```ruby
279
+ # conditions can be plain strings or regular expressions, and you can supply only one or an array
280
+ config.middleware.use WickedPdf::Middleware, {}, :only => '/invoice'
281
+ config.middleware.use WickedPdf::Middleware, {}, :except => [ %r[^/admin], '/secret', %r[^/people/\d] ]
282
+ ```
246
283
  If you use the standard `render :pdf => 'some_pdf'` in your app, you will want to exclude those actions from the middleware.
247
284
 
248
285
  ### Further Reading
@@ -260,9 +297,9 @@ First of all you must configure the render parameter ":show_as_html => params[:d
260
297
  http://localhost:3001/CONTROLLER/X.pdf?debug=1
261
298
 
262
299
  However, the wicked_pdf_* helpers will use file:/// paths for assets when using :show_as_html, and your browser's cross-domain safety feature will kick in, and not render them. To get around this, you can load your assets like so in your templates:
263
-
300
+ ```html
264
301
  <%= params[:debug].present? ? image_tag('foo') : wicked_pdf_image_tag('foo') %>
265
-
302
+ ```
266
303
  ### Inspiration
267
304
 
268
305
  You may have noticed: this plugin is heavily inspired by the PrinceXML plugin [princely](http://github.com/mbleigh/princely/tree/master). PrinceXML's cost was prohibitive for me. So, with a little help from some friends (thanks [jqr](http://github.com/jqr)), I tracked down wkhtmltopdf, and here we are.
data/lib/pdf_helper.rb CHANGED
@@ -87,7 +87,8 @@ module PdfHelper
87
87
  @hf_tempfiles = [] if ! defined?(@hf_tempfiles)
88
88
  @hf_tempfiles.push( tf=WickedPdfTempfile.new("wicked_#{hf}_pdf.html") )
89
89
  options[hf][:html][:layout] ||= options[:layout]
90
- render_opts = {:template => options[hf][:html][:template], :layout => options[hf][:html][:layout], :locals => options[hf][:html][:locals], :formats => options[hf][:html][:formats], :handlers => options[hf][:html][:handlers]}
90
+ 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]
91
92
  render_opts.merge!({:file => options[hf][:html][:file]}) if options[:file]
92
93
  tf.write render_to_string(render_opts)
93
94
  tf.flush
data/lib/wicked_pdf.rb CHANGED
@@ -48,6 +48,7 @@ class WickedPdf
48
48
 
49
49
  temp_path = options.delete(:temp_path)
50
50
  string_file = WickedPdfTempfile.new("wicked_pdf.html", temp_path)
51
+ string_file.binmode
51
52
  string_file.write(string)
52
53
  string_file.close
53
54
  generated_pdf_file = WickedPdfTempfile.new("wicked_pdf_generated_file.pdf", temp_path)
@@ -22,7 +22,8 @@ module WickedPdfHelper
22
22
 
23
23
  def wicked_pdf_javascript_src_tag(jsfile, options={})
24
24
  jsfile = WickedPdfHelper.add_extension(jsfile, 'js')
25
- javascript_src_tag "file:///#{WickedPdfHelper.root_path.join('public', 'javascripts', jsfile)}", options
25
+ src = "file:///#{WickedPdfHelper.root_path.join('public', 'javascripts', jsfile)}"
26
+ content_tag("script", "", { "type" => Mime::JS, "src" => path_to_javascript(src) }.merge(options))
26
27
  end
27
28
 
28
29
  def wicked_pdf_javascript_include_tag(*sources)
@@ -39,12 +40,12 @@ module WickedPdfHelper
39
40
  end
40
41
 
41
42
  def wicked_pdf_image_tag(img, options={})
42
- image_tag "file:///#{asset_pathname(img).to_s}", options
43
+ image_tag wicked_pdf_asset_path(img), options
43
44
  end
44
45
 
45
46
  def wicked_pdf_javascript_src_tag(jsfile, options={})
46
47
  jsfile = WickedPdfHelper.add_extension(jsfile, 'js')
47
- javascript_include_tag "file:///#{asset_pathname(jsfile).to_s}", options
48
+ javascript_include_tag wicked_pdf_asset_path(jsfile), options
48
49
  end
49
50
 
50
51
  def wicked_pdf_javascript_include_tag(*sources)
@@ -54,6 +55,10 @@ module WickedPdfHelper
54
55
  }.join("\n").html_safe
55
56
  end
56
57
 
58
+ def wicked_pdf_asset_path(asset)
59
+ "file:///#{asset_pathname(asset).to_s}"
60
+ end
61
+
57
62
  private
58
63
 
59
64
  # borrowed from actionpack/lib/action_view/helpers/asset_url_helper.rb
@@ -76,7 +81,15 @@ module WickedPdfHelper
76
81
  if Rails.configuration.assets.compile == false
77
82
  if asset_path(source) =~ URI_REGEXP
78
83
  require 'open-uri'
79
- open(asset_pathname(source), 'r:UTF-8') {|f| f.read }
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
80
93
  else
81
94
  IO.read(asset_pathname(source))
82
95
  end
@@ -58,7 +58,7 @@ class WickedPdf
58
58
  rules = [@conditions[:only]].flatten
59
59
  rules.any? do |pattern|
60
60
  if pattern.is_a?(Regexp)
61
- @request.path =~ pattern
61
+ @request.fullpath =~ pattern
62
62
  else
63
63
  @request.path[0, pattern.length] == pattern
64
64
  end
@@ -67,7 +67,7 @@ class WickedPdf
67
67
  rules = [@conditions[:except]].flatten
68
68
  rules.map do |pattern|
69
69
  if pattern.is_a?(Regexp)
70
- return false if @request.path =~ pattern
70
+ return false if @request.fullpath =~ pattern
71
71
  else
72
72
  return false if @request.path[0, pattern.length] == pattern
73
73
  end
@@ -1,3 +1,3 @@
1
1
  class WickedPdf
2
- VERSION = '0.9.6'
2
+ VERSION = '0.9.7'
3
3
  end
@@ -1,32 +0,0 @@
1
- Connecting to database specified by database.yml
2
- Connecting to database specified by database.yml
3
- Connecting to database specified by database.yml
4
- Connecting to database specified by database.yml
5
- Connecting to database specified by database.yml
6
- Connecting to database specified by database.yml
7
- Connecting to database specified by database.yml
8
- Connecting to database specified by database.yml
9
- Connecting to database specified by database.yml
10
- Connecting to database specified by database.yml
11
-  (1.0ms) begin transaction
12
-  (0.0ms) rollback transaction
13
-  (0.0ms) begin transaction
14
-  (1.0ms) rollback transaction
15
-  (0.0ms) begin transaction
16
-  (0.0ms) rollback transaction
17
-  (0.0ms) begin transaction
18
-  (0.0ms) rollback transaction
19
-  (1.0ms) begin transaction
20
-  (1.0ms) rollback transaction
21
-  (0.0ms) begin transaction
22
-  (0.0ms) rollback transaction
23
-  (0.0ms) begin transaction
24
-  (0.0ms) rollback transaction
25
-  (0.0ms) begin transaction
26
-  (0.0ms) rollback transaction
27
-  (0.0ms) begin transaction
28
-  (0.0ms) rollback transaction
29
-  (0.0ms) begin transaction
30
-  (0.0ms) rollback transaction
31
-  (0.0ms) begin transaction
32
-  (0.0ms) rollback transaction
metadata CHANGED
@@ -1,71 +1,66 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: wicked_pdf
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 9
8
- - 6
9
- version: 0.9.6
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.7
10
5
  platform: ruby
11
- authors:
6
+ authors:
12
7
  - Miles Z. Sterret
13
8
  autorequire:
14
9
  bindir: bin
15
10
  cert_chain: []
16
-
17
- date: 2013-04-23 00:00:00 -04:00
18
- default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
11
+ date: 2013-09-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
21
14
  name: rails
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- segments:
28
- - 0
29
- version: "0"
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
30
20
  type: :runtime
31
- version_requirements: *id001
32
- - !ruby/object:Gem::Dependency
33
- name: rake
34
21
  prerelease: false
35
- requirement: &id002 !ruby/object:Gem::Requirement
36
- requirements:
37
- - - ">="
38
- - !ruby/object:Gem::Version
39
- segments:
40
- - 0
41
- version: "0"
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
42
34
  type: :development
43
- version_requirements: *id002
44
- - !ruby/object:Gem::Dependency
45
- name: sqlite3
46
35
  prerelease: false
47
- requirement: &id003 !ruby/object:Gem::Requirement
48
- requirements:
49
- - - ">="
50
- - !ruby/object:Gem::Version
51
- segments:
52
- - 0
53
- version: "0"
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: sqlite3
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
54
48
  type: :development
55
- version_requirements: *id003
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
56
55
  description: |
57
56
  Wicked PDF uses the shell utility wkhtmltopdf to serve a PDF file to a user from HTML.
58
57
  In other words, rather than dealing with a PDF generation DSL of some sort,
59
58
  you simply write an HTML view as you would normally, and let Wicked take care of the hard stuff.
60
-
61
59
  email: miles.sterrett@gmail.com
62
60
  executables: []
63
-
64
61
  extensions: []
65
-
66
62
  extra_rdoc_files: []
67
-
68
- files:
63
+ files:
69
64
  - README.md
70
65
  - Rakefile
71
66
  - MIT-LICENSE
@@ -116,37 +111,30 @@ files:
116
111
  - test/functional/wicked_pdf_helper_test.rb
117
112
  - test/test_helper.rb
118
113
  - test/unit/wicked_pdf_test.rb
119
- has_rdoc: true
120
114
  homepage: https://github.com/mileszs/wicked_pdf
121
115
  licenses: []
122
-
116
+ metadata: {}
123
117
  post_install_message:
124
118
  rdoc_options: []
125
-
126
- require_paths:
119
+ require_paths:
127
120
  - lib
128
- required_ruby_version: !ruby/object:Gem::Requirement
129
- requirements:
130
- - - ">="
131
- - !ruby/object:Gem::Version
132
- segments:
133
- - 0
134
- version: "0"
135
- required_rubygems_version: !ruby/object:Gem::Requirement
136
- requirements:
137
- - - ">="
138
- - !ruby/object:Gem::Version
139
- segments:
140
- - 0
141
- version: "0"
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - '>='
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
142
131
  requirements: []
143
-
144
132
  rubyforge_project:
145
- rubygems_version: 1.3.6
133
+ rubygems_version: 2.0.0
146
134
  signing_key:
147
- specification_version: 3
135
+ specification_version: 4
148
136
  summary: PDF generator (from HTML) gem for Ruby on Rails
149
- test_files:
137
+ test_files:
150
138
  - test/dummy/app/assets/javascripts/application.js
151
139
  - test/dummy/app/assets/stylesheets/application.css
152
140
  - test/dummy/app/controllers/application_controller.rb