wicked_pdf 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9ab8593ac44c5682cf136c152de88154d721bb05
4
- data.tar.gz: a999e4080b0f2a76c4488058e4ccf24e69cb9d1d
3
+ metadata.gz: 7ecacd0a1f535b9b873927974eb6d03f4faaa1e9
4
+ data.tar.gz: 637c15c9aff67ac734148b74a27edff75219f6a8
5
5
  SHA512:
6
- metadata.gz: 1dc2bb0b82be7d2071dd92648cee85e6ab8f539cce32b3eb92d78ab4758926e156aead56847d6a2663ea9909f79d3f53c37f6b63bf3b01d0d2343efd37b3d3c6
7
- data.tar.gz: 1595873318fa389a248d5d85203a9fc397a3670d36c3ac73032362bb06f5c38f5c9dbbe78bd5e3c11c233fcfb1ad06b530dbc8ef2bdbe29582b20308605e8158
6
+ metadata.gz: d7e4d7a62b6134e46dad45c5dee5284030cf9fc69ba115d8200602b591dbf4b69d8d37bde7b79719a973c76e5a5b2c3ddd02eb74fd13fd8a302bb3e8d234871f
7
+ data.tar.gz: 8fb6793c9939c2d217f4dde048d648d95dfab7f83b2f15ea589e43c94d802ecd98b32da4f57bed1d954183397ff8adc553800a337c7a405c54fd55e68419a3be
data/.travis.yml CHANGED
@@ -1,12 +1,14 @@
1
1
  language:
2
2
  - ruby
3
3
  bundler_args: --verbose
4
+ sudo: required
4
5
  rvm:
5
6
  - 1.9.2
6
7
  - 1.9.3
7
8
  - 2.0
8
9
  - 2.1
9
10
  - 2.2
11
+ - ruby-head
10
12
  gemfile:
11
13
  - gemfiles/3.0.gemfile
12
14
  - gemfiles/3.1.gemfile
@@ -52,3 +54,4 @@ matrix:
52
54
  gemfile: gemfiles/rails_edge.gemfile
53
55
  - rvm: 2.2.0
54
56
  gemfile: gemfiles/rails_edge.gemfile
57
+ - rvm: ruby-head
data/CHANGLOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
  All notable changes to this project will be documented in this file.
3
3
  This project adheres to [Semantic Versioning](http://semver.org/).
4
4
 
5
+ ## [master] - Unpublished
6
+ ### Changed
7
+ - The default dpi is now 72. Previously the default would be whatever your `wkhtmltopdf` version specified as the default. This change [speeds up generation of documents that contain `border-radius` dramatically](https://github.com/wkhtmltopdf/wkhtmltopdf/issues/1510)
8
+
5
9
  ## [1.0.0] - 2015-11-03
6
10
  ### Changed
7
11
  - Accepted that `WickedPDF` cannot guarantee backwards compatibility with older versions of `wkthmltopdf`, and decided to publish a new version with the MAJOR number incremented, signaling that this may have breaking changes for some people, but providing a path forward for progress. This release number also signals that this is a mature (and relatively stable) project, and should be deemed ready for production (since it has been used in production since ~2009, and downloaded over a *million* times on [RubyGems.org](https://rubygems.org/gems/wicked_pdf)).
data/README.md CHANGED
@@ -35,6 +35,8 @@ gem 'wkhtmltopdf-binary'
35
35
 
36
36
  To your Gemfile and run `bundle install`.
37
37
 
38
+ This wrapper may trail in versions, at the moment it wraps the 0.9 version of `wkhtmltopdf` while there is 0.12 version available. Some of the advanced options listed below is not available with 0.9.
39
+
38
40
  If your wkhtmltopdf executable is not on your webserver's path, you can configure it in an initializer:
39
41
 
40
42
  ```ruby
@@ -145,6 +147,7 @@ class ThingsController < ApplicationController
145
147
  print_media_type: true,
146
148
  disable_smart_shrinking: true,
147
149
  use_xserver: true,
150
+ background: false, # backround needs to be true to enable background colors to render
148
151
  no_background: true,
149
152
  viewport_size: 'TEXT', # available only with use_xserver or patched QT
150
153
  extra: '', # directly inserted into the command to wkhtmltopdf
data/lib/wicked_pdf.rb CHANGED
@@ -164,11 +164,11 @@ class WickedPdf
164
164
  end
165
165
  if type == :name_value
166
166
  parts = value.to_s.split(' ')
167
- ["--#{name.gsub('_', '-')}", *parts]
167
+ ["--#{name.tr('_', '-')}", *parts]
168
168
  elsif type == :boolean
169
- ["--#{name.gsub('_', '-')}"]
169
+ ["--#{name.tr('_', '-')}"]
170
170
  else
171
- ["--#{name.gsub('_', '-')}", value.to_s]
171
+ ["--#{name.tr('_', '-')}", value.to_s]
172
172
  end
173
173
  end
174
174
 
@@ -1,13 +1,13 @@
1
1
  class WickedPdf
2
2
  class Middleware
3
3
  def initialize(app, options = {}, conditions = {})
4
- @app = app
5
- @options = (WickedPdf.config || {}).merge(options)
4
+ @app = app
5
+ @options = (WickedPdf.config || {}).merge(options)
6
6
  @conditions = conditions
7
7
  end
8
8
 
9
9
  def call(env)
10
- @request = Rack::Request.new(env)
10
+ @request = Rack::Request.new(env)
11
11
  @render_pdf = false
12
12
 
13
13
  set_request_to_render_as_pdf(env) if render_as_pdf?
@@ -25,10 +25,10 @@ class WickedPdf
25
25
  headers.delete('ETag')
26
26
  headers.delete('Cache-Control')
27
27
 
28
- headers['Content-Length'] = (body.respond_to?(:bytesize) ? body.bytesize : body.size).to_s
29
- headers['Content-Type'] = 'application/pdf'
28
+ headers['Content-Length'] = (body.respond_to?(:bytesize) ? body.bytesize : body.size).to_s
29
+ headers['Content-Type'] = 'application/pdf'
30
30
  if @options.fetch(:disposition, '') == 'attachment'
31
- headers['Content-Disposition'] = 'attachment'
31
+ headers['Content-Disposition'] = 'attachment'
32
32
  headers['Content-Transfer-Encoding'] = 'binary'
33
33
  end
34
34
  end
@@ -53,7 +53,12 @@ module PdfHelper
53
53
  end
54
54
 
55
55
  def make_pdf(options = {})
56
- render_opts = { :template => options[:template], :layout => options[:layout], :formats => options[:formats], :handlers => options[:handlers] }
56
+ render_opts = {
57
+ :template => options[:template],
58
+ :layout => options[:layout],
59
+ :formats => options[:formats],
60
+ :handlers => options[:handlers]
61
+ }
57
62
  render_opts.merge!(:locals => options[:locals]) if options[:locals]
58
63
  render_opts.merge!(:file => options[:file]) if options[:file]
59
64
  html_string = render_to_string(render_opts)
@@ -67,8 +72,15 @@ module PdfHelper
67
72
  options[:layout] ||= false
68
73
  options[:template] ||= File.join(controller_path, action_name)
69
74
  options[:disposition] ||= 'inline'
75
+ options[:dpi] ||= '72'
70
76
  if options[:show_as_html]
71
- render_opts = { :template => options[:template], :layout => options[:layout], :formats => options[:formats], :handlers => options[:handlers], :content_type => 'text/html' }
77
+ render_opts = {
78
+ :template => options[:template],
79
+ :layout => options[:layout],
80
+ :formats => options[:formats],
81
+ :handlers => options[:handlers],
82
+ :content_type => 'text/html'
83
+ }
72
84
  render_opts.merge!(:locals => options[:locals]) if options[:locals]
73
85
  render_opts.merge!(:file => options[:file]) if options[:file]
74
86
  render(render_opts)
@@ -87,7 +99,12 @@ module PdfHelper
87
99
  @hf_tempfiles = [] unless defined?(@hf_tempfiles)
88
100
  @hf_tempfiles.push(tf = WickedPdfTempfile.new("wicked_#{hf}_pdf.html"))
89
101
  options[hf][:html][:layout] ||= options[:layout]
90
- render_opts = { :template => options[hf][:html][:template], :layout => options[hf][:html][:layout], :formats => options[hf][:html][:formats], :handlers => options[hf][:html][:handlers] }
102
+ render_opts = {
103
+ :template => options[hf][:html][:template],
104
+ :layout => options[hf][:html][:layout],
105
+ :formats => options[hf][:html][:formats],
106
+ :handlers => options[hf][:html][:handlers]
107
+ }
91
108
  render_opts.merge!(:locals => options[hf][:html][:locals]) if options[hf][:html][:locals]
92
109
  render_opts.merge!(:file => options[hf][:html][:file]) if options[:file]
93
110
  tf.write render_to_string(render_opts)
@@ -1,3 +1,3 @@
1
1
  class WickedPdf
2
- VERSION = '1.0.1'
2
+ VERSION = '1.0.2'
3
3
  end
@@ -22,9 +22,7 @@ module WickedPdfHelper
22
22
  "url(#{Regexp.last_match[1]})"
23
23
  else
24
24
  asset = Regexp.last_match[1]
25
- if asset_exists?(asset)
26
- "url(#{wicked_pdf_asset_path(asset)})"
27
- end
25
+ "url(#{wicked_pdf_asset_path(asset)})" if asset_exists?(asset)
28
26
  end
29
27
  end.html_safe
30
28
  end
data/test/test_helper.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # Configure Rails Environment
2
2
  ENV['RAILS_ENV'] = 'test'
3
3
 
4
- require File.expand_path('../dummy/config/environment.rb', __FILE__)
4
+ require File.expand_path('../dummy/config/environment.rb', __FILE__)
5
5
 
6
6
  require 'test/unit'
7
7
  require 'mocha'
@@ -95,12 +95,12 @@ class WickedPdfTest < ActiveSupport::TestCase
95
95
 
96
96
  [:header, :footer].each do |hf|
97
97
  [:center, :font_name, :left, :right].each do |o|
98
- assert_equal "--#{hf}-#{o.to_s.gsub('_', '-')} header_footer",
98
+ assert_equal "--#{hf}-#{o.to_s.tr('_', '-')} header_footer",
99
99
  wp.get_parsed_options(hf => { o => 'header_footer' }).strip
100
100
  end
101
101
 
102
102
  [:font_size, :spacing].each do |o|
103
- assert_equal "--#{hf}-#{o.to_s.gsub('_', '-')} 12",
103
+ assert_equal "--#{hf}-#{o.to_s.tr('_', '-')} 12",
104
104
  wp.get_parsed_options(hf => { o => '12' }).strip
105
105
  end
106
106
 
@@ -116,7 +116,7 @@ class WickedPdfTest < ActiveSupport::TestCase
116
116
  toc_option = wp.get_valid_option('toc')
117
117
 
118
118
  [:font_name, :header_text].each do |o|
119
- assert_equal "#{toc_option} --toc-#{o.to_s.gsub('_', '-')} toc",
119
+ assert_equal "#{toc_option} --toc-#{o.to_s.tr('_', '-')} toc",
120
120
  wp.get_parsed_options(:toc => { o => 'toc' }).strip
121
121
  end
122
122
 
@@ -125,12 +125,12 @@ class WickedPdfTest < ActiveSupport::TestCase
125
125
  :l5_font_size, :l6_font_size, :l7_font_size, :l1_indentation, :l2_indentation,
126
126
  :l3_indentation, :l4_indentation, :l5_indentation, :l6_indentation, :l7_indentation
127
127
  ].each do |o|
128
- assert_equal "#{toc_option} --toc-#{o.to_s.gsub('_', '-')} 5",
128
+ assert_equal "#{toc_option} --toc-#{o.to_s.tr('_', '-')} 5",
129
129
  wp.get_parsed_options(:toc => { o => 5 }).strip
130
130
  end
131
131
 
132
132
  [:no_dots, :disable_links, :disable_back_links].each do |o|
133
- assert_equal "#{toc_option} --toc-#{o.to_s.gsub('_', '-')}",
133
+ assert_equal "#{toc_option} --toc-#{o.to_s.tr('_', '-')}",
134
134
  wp.get_parsed_options(:toc => { o => true }).strip
135
135
  end
136
136
  end
@@ -167,18 +167,18 @@ class WickedPdfTest < ActiveSupport::TestCase
167
167
  :orientation, :page_size, :proxy, :username, :password, :dpi,
168
168
  :encoding, :user_style_sheet
169
169
  ].each do |o|
170
- assert_equal "--#{o.to_s.gsub('_', '-')} opts", wp.get_parsed_options(o => 'opts').strip
170
+ assert_equal "--#{o.to_s.tr('_', '-')} opts", wp.get_parsed_options(o => 'opts').strip
171
171
  end
172
172
 
173
173
  [:cookie, :post].each do |o|
174
- assert_equal "--#{o.to_s.gsub('_', '-')} name value", wp.get_parsed_options(o => 'name value').strip
174
+ assert_equal "--#{o.to_s.tr('_', '-')} name value", wp.get_parsed_options(o => 'name value').strip
175
175
 
176
- nv_formatter = proc { |number| "--#{o.to_s.gsub('_', '-')} par#{number} val#{number}" }
176
+ nv_formatter = proc { |number| "--#{o.to_s.tr('_', '-')} par#{number} val#{number}" }
177
177
  assert_equal "#{nv_formatter.call(1)} #{nv_formatter.call(2)}", wp.get_parsed_options(o => ['par1 val1', 'par2 val2']).strip
178
178
  end
179
179
 
180
180
  [:redirect_delay, :zoom, :page_offset].each do |o|
181
- assert_equal "--#{o.to_s.gsub('_', '-')} 5", wp.get_parsed_options(o => 5).strip
181
+ assert_equal "--#{o.to_s.tr('_', '-')} 5", wp.get_parsed_options(o => 5).strip
182
182
  end
183
183
 
184
184
  [
@@ -186,7 +186,7 @@ class WickedPdfTest < ActiveSupport::TestCase
186
186
  :enable_plugins, :disable_internal_links, :disable_external_links,
187
187
  :print_media_type, :disable_smart_shrinking, :use_xserver, :no_background
188
188
  ].each do |o|
189
- assert_equal "--#{o.to_s.gsub('_', '-')}", wp.get_parsed_options(o => true).strip
189
+ assert_equal "--#{o.to_s.tr('_', '-')}", wp.get_parsed_options(o => true).strip
190
190
  end
191
191
  end
192
192
 
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: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Z. Sterrett
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-19 00:00:00.000000000 Z
11
+ date: 2015-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -186,3 +186,4 @@ test_files:
186
186
  - test/functional/wicked_pdf_helper_test.rb
187
187
  - test/test_helper.rb
188
188
  - test/unit/wicked_pdf_test.rb
189
+ has_rdoc: