wicked_pdf 0.11.0 → 1.0.0
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 +4 -4
- data/.gitignore +1 -1
- data/.travis.yml +13 -3
- data/Gemfile +1 -1
- data/README.md +152 -142
- data/Rakefile +24 -12
- data/gemfiles/2.3.gemfile +2 -0
- data/gemfiles/3.1.gemfile +3 -2
- data/gemfiles/3.2.gemfile +3 -2
- data/gemfiles/4.0.gemfile +2 -2
- data/gemfiles/4.1.gemfile +6 -0
- data/gemfiles/4.2.gemfile +6 -0
- data/gemfiles/rails_edge.gemfile +3 -3
- data/generators/wicked_pdf/templates/wicked_pdf.rb +19 -3
- data/generators/wicked_pdf/wicked_pdf_generator.rb +1 -1
- data/lib/generators/wicked_pdf_generator.rb +2 -2
- data/lib/wicked_pdf.rb +241 -212
- data/lib/wicked_pdf/middleware.rb +6 -7
- data/lib/wicked_pdf/pdf_helper.rb +53 -53
- data/lib/wicked_pdf/railtie.rb +14 -14
- data/lib/wicked_pdf/tempfile.rb +2 -2
- data/lib/wicked_pdf/version.rb +2 -2
- data/lib/wicked_pdf/wicked_pdf_helper.rb +30 -15
- data/test/functional/pdf_helper_test.rb +5 -5
- data/test/functional/wicked_pdf_helper_assets_test.rb +35 -8
- data/test/functional/wicked_pdf_helper_test.rb +2 -2
- data/test/test_helper.rb +10 -5
- data/test/unit/wicked_pdf_test.rb +90 -57
- data/wicked_pdf.gemspec +5 -4
- metadata +20 -72
- data/test/dummy/README.rdoc +0 -261
- data/test/dummy/Rakefile +0 -7
- data/test/dummy/app/assets/javascripts/application.js +0 -15
- data/test/dummy/app/assets/stylesheets/application.css +0 -13
- data/test/dummy/app/controllers/application_controller.rb +0 -3
- data/test/dummy/app/helpers/application_helper.rb +0 -2
- data/test/dummy/app/mailers/.gitkeep +0 -0
- data/test/dummy/app/models/.gitkeep +0 -0
- data/test/dummy/app/views/layouts/application.html.erb +0 -14
- data/test/dummy/config.ru +0 -4
- data/test/dummy/config/application.rb +0 -59
- data/test/dummy/config/boot.rb +0 -10
- data/test/dummy/config/database.yml +0 -25
- data/test/dummy/config/environment.rb +0 -5
- data/test/dummy/config/environments/development.rb +0 -37
- data/test/dummy/config/environments/production.rb +0 -67
- data/test/dummy/config/environments/test.rb +0 -37
- data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/test/dummy/config/initializers/inflections.rb +0 -15
- data/test/dummy/config/initializers/mime_types.rb +0 -5
- data/test/dummy/config/initializers/secret_token.rb +0 -7
- data/test/dummy/config/initializers/session_store.rb +0 -8
- data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/test/dummy/config/locales/en.yml +0 -5
- data/test/dummy/config/routes.rb +0 -58
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/lib/assets/.gitkeep +0 -0
- data/test/dummy/log/.gitkeep +0 -0
- data/test/dummy/public/404.html +0 -26
- data/test/dummy/public/422.html +0 -26
- data/test/dummy/public/500.html +0 -25
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +0 -6
data/Rakefile
CHANGED
@@ -5,7 +5,7 @@ require 'rails/version'
|
|
5
5
|
require 'bundler/gem_tasks'
|
6
6
|
|
7
7
|
desc 'Default: run unit tests.'
|
8
|
-
task :default => :
|
8
|
+
task :default => :setup_and_run_tests
|
9
9
|
|
10
10
|
desc 'Test the wicked_pdf plugin.'
|
11
11
|
Rake::TestTask.new(:test) do |t|
|
@@ -15,19 +15,31 @@ Rake::TestTask.new(:test) do |t|
|
|
15
15
|
t.verbose = true
|
16
16
|
end
|
17
17
|
|
18
|
-
desc
|
18
|
+
desc 'Setup and run all tests'
|
19
|
+
task :setup_and_run_tests do
|
20
|
+
unless File.exist?('test/dummy/config/environment.rb')
|
21
|
+
Rake::Task[:dummy_generate].invoke
|
22
|
+
end
|
23
|
+
Rake::Task[:test].invoke
|
24
|
+
end
|
25
|
+
|
26
|
+
desc 'Generate dummy application for test cases'
|
19
27
|
task :dummy_generate do
|
20
|
-
|
21
|
-
|
28
|
+
Rake::Task[:dummy_remove].invoke
|
29
|
+
puts 'Creating dummy application to run tests'
|
22
30
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
31
|
+
prefix = ''
|
32
|
+
if Rails::VERSION::MAJOR != 2
|
33
|
+
prefix = 'new '
|
34
|
+
end
|
35
|
+
|
36
|
+
system("rails #{prefix}test/dummy")
|
37
|
+
FileUtils.rm_r Dir.glob('test/dummy/test/*')
|
38
|
+
end
|
27
39
|
|
28
|
-
|
29
|
-
|
30
|
-
|
40
|
+
desc 'Remove dummy application'
|
41
|
+
task :dummy_remove do
|
42
|
+
FileUtils.rm_r Dir.glob('test/dummy/*')
|
31
43
|
end
|
32
44
|
|
33
45
|
desc 'Generate documentation for the wicked_pdf plugin.'
|
@@ -35,6 +47,6 @@ RDoc::Task.new(:rdoc) do |rdoc|
|
|
35
47
|
rdoc.rdoc_dir = 'rdoc'
|
36
48
|
rdoc.title = 'WickedPdf'
|
37
49
|
rdoc.options << '--line-numbers' << '--inline-source'
|
38
|
-
rdoc.rdoc_files.include('README')
|
50
|
+
rdoc.rdoc_files.include('README.md')
|
39
51
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
40
52
|
end
|
data/gemfiles/2.3.gemfile
CHANGED
data/gemfiles/3.1.gemfile
CHANGED
data/gemfiles/3.2.gemfile
CHANGED
data/gemfiles/4.0.gemfile
CHANGED
data/gemfiles/rails_edge.gemfile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
source "https://rubygems.org"
|
2
2
|
|
3
3
|
gem 'rdoc'
|
4
|
-
gem 'rails', :
|
5
|
-
gem 'wicked_pdf', :
|
6
|
-
gemspec :
|
4
|
+
gem 'rails', git: "https://github.com/rails/rails.git"
|
5
|
+
gem 'wicked_pdf', path: '../'
|
6
|
+
gemspec path: '../'
|
@@ -1,5 +1,21 @@
|
|
1
|
+
# WickedPDF Global Configuration
|
2
|
+
#
|
3
|
+
# Use this to set up shared configuration options for your entire application.
|
4
|
+
# Any of the configuration options shown here can also be applied to single
|
5
|
+
# models by passing arguments to the `render :pdf` call.
|
6
|
+
#
|
7
|
+
# To learn more, check out the README:
|
8
|
+
#
|
9
|
+
# https://github.com/mileszs/wicked_pdf/blob/master/README.md
|
10
|
+
|
1
11
|
WickedPdf.config = {
|
2
|
-
|
3
|
-
|
4
|
-
:
|
12
|
+
# Path to the wkhtmltopdf executable: This usually isn't needed if using
|
13
|
+
# one of the wkhtmltopdf-binary family of gems.
|
14
|
+
# exe_path: '/usr/local/bin/wkhtmltopdf',
|
15
|
+
# or
|
16
|
+
# exe_path: Gem.bin_path('wkhtmltopdf-binary', 'wkhtmltopdf')
|
17
|
+
|
18
|
+
# Layout file to be used for all PDFs
|
19
|
+
# (but can be overridden in `render :pdf` calls)
|
20
|
+
# layout: 'pdf.html',
|
5
21
|
}
|
@@ -2,10 +2,10 @@ if defined?(Rails) && Rails::VERSION::MAJOR != 2
|
|
2
2
|
|
3
3
|
# Rails3 generator invoked with 'rails generate wicked_pdf'
|
4
4
|
class WickedPdfGenerator < Rails::Generators::Base
|
5
|
-
source_root(File.expand_path(File.dirname(__FILE__) +
|
5
|
+
source_root(File.expand_path(File.dirname(__FILE__) + '/../../generators/wicked_pdf/templates'))
|
6
6
|
def copy_initializer
|
7
7
|
copy_file 'wicked_pdf.rb', 'config/initializers/wicked_pdf.rb'
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
end
|
11
|
+
end
|
data/lib/wicked_pdf.rb
CHANGED
@@ -30,38 +30,49 @@ require 'wicked_pdf/middleware'
|
|
30
30
|
|
31
31
|
class WickedPdf
|
32
32
|
DEFAULT_BINARY_VERSION = Gem::Version.new('0.9.9')
|
33
|
-
|
33
|
+
BINARY_VERSION_WITHOUT_DASHES = Gem::Version.new('0.12.0')
|
34
|
+
EXE_NAME = 'wkhtmltopdf'
|
34
35
|
@@config = {}
|
35
36
|
cattr_accessor :config
|
36
37
|
|
37
38
|
def initialize(wkhtmltopdf_binary_path = nil)
|
38
39
|
@exe_path = wkhtmltopdf_binary_path || find_wkhtmltopdf_binary_path
|
39
|
-
|
40
|
-
|
41
|
-
|
40
|
+
fail "Location of #{EXE_NAME} unknown" if @exe_path.empty?
|
41
|
+
fail "Bad #{EXE_NAME}'s path: #{@exe_path}" unless File.exist?(@exe_path)
|
42
|
+
fail "#{EXE_NAME} is not executable" unless File.executable?(@exe_path)
|
42
43
|
|
43
|
-
|
44
|
+
retreive_binary_version
|
44
45
|
end
|
45
46
|
|
46
|
-
def
|
47
|
-
|
48
|
-
stdin, stdout, stderr = Open3.popen3(@exe_path + ' -V')
|
49
|
-
@binary_version = parse_version(stdout.gets(nil))
|
50
|
-
rescue StandardError
|
51
|
-
end
|
47
|
+
def pdf_from_html_file(filepath, options = {})
|
48
|
+
pdf_from_url("file:///#{filepath}", options)
|
52
49
|
end
|
53
50
|
|
54
|
-
def
|
55
|
-
|
56
|
-
|
57
|
-
|
51
|
+
def pdf_from_string(string, options = {})
|
52
|
+
options = options.dup
|
53
|
+
# merge in global config options
|
54
|
+
options.merge!(WickedPdf.config) {|key, option, config| option}
|
55
|
+
string_file = WickedPdfTempfile.new("wicked_pdf.html", options[:temp_path])
|
56
|
+
string_file.binmode
|
57
|
+
string_file.write(string)
|
58
|
+
string_file.close
|
58
59
|
|
59
|
-
|
60
|
-
|
60
|
+
pdf = pdf_from_html_file(string_file.path, options)
|
61
|
+
pdf
|
62
|
+
rescue => e
|
63
|
+
raise "Error: #{e}"
|
64
|
+
ensure
|
65
|
+
string_file.close! if string_file
|
66
|
+
end
|
67
|
+
|
68
|
+
def pdf_from_url(url, options = {})
|
69
|
+
# merge in global config options
|
70
|
+
options.merge!(WickedPdf.config) {|key, option, config| option}
|
71
|
+
generated_pdf_file = WickedPdfTempfile.new("wicked_pdf_generated_file.pdf", options[:temp_path])
|
61
72
|
command = [@exe_path]
|
62
73
|
command << '-q' unless on_windows? # suppress errors on stdout
|
63
74
|
command += parse_options(options)
|
64
|
-
command <<
|
75
|
+
command << url
|
65
76
|
command << generated_pdf_file.path.to_s
|
66
77
|
|
67
78
|
print_command(command.inspect) if in_development_mode?
|
@@ -75,239 +86,257 @@ class WickedPdf
|
|
75
86
|
generated_pdf_file.rewind
|
76
87
|
generated_pdf_file.binmode
|
77
88
|
pdf = generated_pdf_file.read
|
78
|
-
|
89
|
+
fail "PDF could not be generated!\n Command Error: #{err}" if pdf && pdf.rstrip.length == 0
|
79
90
|
pdf
|
80
|
-
rescue
|
91
|
+
rescue => e
|
81
92
|
raise "Failed to execute:\n#{command}\nError: #{e}"
|
82
93
|
ensure
|
83
94
|
generated_pdf_file.close! if generated_pdf_file && !return_file
|
84
95
|
end
|
85
96
|
|
86
|
-
|
87
|
-
temp_path = options.delete(:temp_path)
|
88
|
-
string_file = WickedPdfTempfile.new("wicked_pdf.html", temp_path)
|
89
|
-
string_file.binmode
|
90
|
-
string_file.write(string)
|
91
|
-
string_file.close
|
97
|
+
private
|
92
98
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
raise "Error: #{e}"
|
97
|
-
ensure
|
98
|
-
string_file.close! if string_file
|
99
|
+
def in_development_mode?
|
100
|
+
return Rails.env == 'development' if defined?(Rails)
|
101
|
+
RAILS_ENV == 'development' if defined?(RAILS_ENV)
|
99
102
|
end
|
100
103
|
|
101
|
-
|
104
|
+
def get_binary_version
|
105
|
+
@binary_version
|
106
|
+
end
|
102
107
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
end
|
108
|
+
def on_windows?
|
109
|
+
RbConfig::CONFIG['target_os'] =~ /mswin|mingw/
|
110
|
+
end
|
107
111
|
|
108
|
-
|
109
|
-
|
110
|
-
|
112
|
+
def print_command(cmd)
|
113
|
+
p '*' * 15 + cmd + '*' * 15
|
114
|
+
end
|
111
115
|
|
112
|
-
|
113
|
-
|
114
|
-
|
116
|
+
def retreive_binary_version
|
117
|
+
stdin, stdout, stderr = Open3.popen3(@exe_path + ' -V')
|
118
|
+
@binary_version = parse_version(stdout.gets(nil))
|
119
|
+
rescue StandardError
|
120
|
+
end
|
115
121
|
|
116
|
-
|
117
|
-
|
122
|
+
def parse_version(version_info)
|
123
|
+
match_data = /wkhtmltopdf\s*(\d*\.\d*\.\d*\w*)/.match(version_info)
|
124
|
+
if match_data && (2 == match_data.length)
|
125
|
+
Gem::Version.new(match_data[1])
|
126
|
+
else
|
127
|
+
DEFAULT_BINARY_VERSION
|
118
128
|
end
|
129
|
+
end
|
119
130
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
131
|
+
def parse_options(options)
|
132
|
+
[
|
133
|
+
parse_extra(options),
|
134
|
+
parse_others(options),
|
135
|
+
parse_global(options),
|
136
|
+
parse_outline(options.delete(:outline)),
|
137
|
+
parse_header_footer(:header => options.delete(:header),
|
138
|
+
:footer => options.delete(:footer),
|
139
|
+
:layout => options[:layout]),
|
140
|
+
parse_cover(options.delete(:cover)),
|
141
|
+
parse_toc(options.delete(:toc)),
|
142
|
+
parse_basic_auth(options)
|
143
|
+
].flatten
|
144
|
+
end
|
145
|
+
|
146
|
+
def parse_extra(options)
|
147
|
+
return [] if options[:extra].nil?
|
148
|
+
return options[:extra].split if options[:extra].respond_to?(:split)
|
149
|
+
options[:extra]
|
150
|
+
end
|
128
151
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
parse_cover(options.delete(:cover)),
|
136
|
-
parse_toc(options.delete(:toc)),
|
137
|
-
parse_outline(options.delete(:outline)),
|
138
|
-
parse_margins(options.delete(:margin)),
|
139
|
-
parse_others(options),
|
140
|
-
parse_basic_auth(options)
|
141
|
-
].flatten
|
152
|
+
def parse_basic_auth(options)
|
153
|
+
if options[:basic_auth]
|
154
|
+
user, passwd = Base64.decode64(options[:basic_auth]).split(':')
|
155
|
+
['--username', user, '--password', passwd]
|
156
|
+
else
|
157
|
+
[]
|
142
158
|
end
|
159
|
+
end
|
143
160
|
|
144
|
-
|
145
|
-
|
146
|
-
return
|
147
|
-
return options[:extra]
|
161
|
+
def make_option(name, value, type = :string)
|
162
|
+
if value.is_a?(Array)
|
163
|
+
return value.collect { |v| make_option(name, v, type) }
|
148
164
|
end
|
165
|
+
if type == :name_value
|
166
|
+
parts = value.to_s.split(' ')
|
167
|
+
["--#{name.gsub('_', '-')}", *parts]
|
168
|
+
elsif type == :boolean
|
169
|
+
["--#{name.gsub('_', '-')}"]
|
170
|
+
else
|
171
|
+
["--#{name.gsub('_', '-')}", value.to_s]
|
172
|
+
end
|
173
|
+
end
|
149
174
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
[]
|
156
|
-
end
|
175
|
+
def valid_option(name)
|
176
|
+
if get_binary_version < BINARY_VERSION_WITHOUT_DASHES
|
177
|
+
"--#{name}"
|
178
|
+
else
|
179
|
+
name
|
157
180
|
end
|
181
|
+
end
|
158
182
|
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
["--#{name.gsub('_', '-')}"]
|
183
|
+
def make_options(options, names, prefix = '', type = :string)
|
184
|
+
return [] if options.nil?
|
185
|
+
names.collect do |o|
|
186
|
+
if options[o].blank?
|
187
|
+
[]
|
165
188
|
else
|
166
|
-
|
189
|
+
make_option("#{prefix.blank? ? '' : prefix + '-'}#{o.to_s}",
|
190
|
+
options[o],
|
191
|
+
type)
|
167
192
|
end
|
168
193
|
end
|
194
|
+
end
|
169
195
|
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
196
|
+
def parse_header_footer(options)
|
197
|
+
r = []
|
198
|
+
[:header, :footer].collect do |hf|
|
199
|
+
unless options[hf].blank?
|
200
|
+
opt_hf = options[hf]
|
201
|
+
r += make_options(opt_hf, [:center, :font_name, :left, :right], "#{hf.to_s}")
|
202
|
+
r += make_options(opt_hf, [:font_size, :spacing], "#{hf.to_s}", :numeric)
|
203
|
+
r += make_options(opt_hf, [:line], "#{hf.to_s}", :boolean)
|
204
|
+
if options[hf] && options[hf][:content]
|
205
|
+
@hf_tempfiles = [] unless defined?(@hf_tempfiles)
|
206
|
+
@hf_tempfiles.push(tf = WickedPdfTempfile.new("wicked_#{hf}_pdf.html"))
|
207
|
+
tf.write options[hf][:content]
|
208
|
+
tf.flush
|
209
|
+
options[hf][:html] = {}
|
210
|
+
options[hf][:html][:url] = "file:///#{tf.path}"
|
211
|
+
end
|
212
|
+
unless opt_hf[:html].blank?
|
213
|
+
r += make_option("#{hf.to_s}-html", opt_hf[:html][:url]) unless opt_hf[:html][:url].blank?
|
179
214
|
end
|
180
215
|
end
|
181
|
-
end
|
216
|
+
end unless options.blank?
|
217
|
+
r
|
218
|
+
end
|
182
219
|
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
tf.flush
|
196
|
-
options[hf].delete(:content)
|
197
|
-
options[hf][:html] = {}
|
198
|
-
options[hf][:html][:url] = "file:///#{tf.path}"
|
199
|
-
end
|
200
|
-
unless opt_hf[:html].blank?
|
201
|
-
r += make_option("#{hf.to_s}-html", opt_hf[:html][:url]) unless opt_hf[:html][:url].blank?
|
202
|
-
end
|
203
|
-
end
|
204
|
-
end unless options.blank?
|
205
|
-
r
|
220
|
+
def parse_cover(argument)
|
221
|
+
arg = argument.to_s
|
222
|
+
return [] if arg.blank?
|
223
|
+
# Filesystem path or URL - hand off to wkhtmltopdf
|
224
|
+
if argument.is_a?(Pathname) || (arg[0, 4] == 'http')
|
225
|
+
[valid_option('cover'), arg]
|
226
|
+
else # HTML content
|
227
|
+
@hf_tempfiles ||= []
|
228
|
+
@hf_tempfiles << tf = WickedPdfTempfile.new('wicked_cover_pdf.html')
|
229
|
+
tf.write arg
|
230
|
+
tf.flush
|
231
|
+
[valid_option('cover'), tf.path]
|
206
232
|
end
|
233
|
+
end
|
207
234
|
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
235
|
+
def parse_toc(options)
|
236
|
+
return [] if options.nil?
|
237
|
+
r = [valid_option('toc')]
|
238
|
+
unless options.blank?
|
239
|
+
r += make_options(options, [:font_name, :header_text], 'toc')
|
240
|
+
r += make_options(options, [:xsl_style_sheet])
|
241
|
+
r += make_options(options, [:depth,
|
242
|
+
:header_fs,
|
243
|
+
:text_size_shrink,
|
244
|
+
:l1_font_size,
|
245
|
+
:l2_font_size,
|
246
|
+
:l3_font_size,
|
247
|
+
:l4_font_size,
|
248
|
+
:l5_font_size,
|
249
|
+
:l6_font_size,
|
250
|
+
:l7_font_size,
|
251
|
+
:level_indentation,
|
252
|
+
:l1_indentation,
|
253
|
+
:l2_indentation,
|
254
|
+
:l3_indentation,
|
255
|
+
:l4_indentation,
|
256
|
+
:l5_indentation,
|
257
|
+
:l6_indentation,
|
258
|
+
:l7_indentation], 'toc', :numeric)
|
259
|
+
r += make_options(options, [:no_dots,
|
260
|
+
:disable_links,
|
261
|
+
:disable_back_links], 'toc', :boolean)
|
262
|
+
r += make_options(options, [:disable_dotted_lines,
|
263
|
+
:disable_toc_links], nil, :boolean)
|
221
264
|
end
|
265
|
+
r
|
266
|
+
end
|
222
267
|
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
r +=make_options(options, [ :depth,
|
229
|
-
:header_fs,
|
230
|
-
:l1_font_size,
|
231
|
-
:l2_font_size,
|
232
|
-
:l3_font_size,
|
233
|
-
:l4_font_size,
|
234
|
-
:l5_font_size,
|
235
|
-
:l6_font_size,
|
236
|
-
:l7_font_size,
|
237
|
-
:l1_indentation,
|
238
|
-
:l2_indentation,
|
239
|
-
:l3_indentation,
|
240
|
-
:l4_indentation,
|
241
|
-
:l5_indentation,
|
242
|
-
:l6_indentation,
|
243
|
-
:l7_indentation], "toc", :numeric)
|
244
|
-
r +=make_options(options, [ :no_dots,
|
245
|
-
:disable_links,
|
246
|
-
:disable_back_links], "toc", :boolean)
|
247
|
-
end
|
248
|
-
return r
|
268
|
+
def parse_outline(options)
|
269
|
+
r = []
|
270
|
+
unless options.blank?
|
271
|
+
r = make_options(options, [:outline], '', :boolean)
|
272
|
+
r += make_options(options, [:outline_depth], '', :numeric)
|
249
273
|
end
|
274
|
+
r
|
275
|
+
end
|
250
276
|
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
r = make_options(options, [:outline], "", :boolean)
|
255
|
-
r +=make_options(options, [:outline_depth], "", :numeric)
|
256
|
-
end
|
257
|
-
r
|
258
|
-
end
|
277
|
+
def parse_margins(options)
|
278
|
+
make_options(options, [:top, :bottom, :left, :right], 'margin', :numeric)
|
279
|
+
end
|
259
280
|
|
260
|
-
|
261
|
-
|
281
|
+
def parse_global(options)
|
282
|
+
r = []
|
283
|
+
unless options.blank?
|
284
|
+
r += make_options(options, [:orientation,
|
285
|
+
:dpi,
|
286
|
+
:page_size,
|
287
|
+
:page_width,
|
288
|
+
:title])
|
289
|
+
r += make_options(options, [:lowquality,
|
290
|
+
:grayscale,
|
291
|
+
:no_pdf_compression], '', :boolean)
|
292
|
+
r += make_options(options, [:image_dpi,
|
293
|
+
:image_quality,
|
294
|
+
:page_height], '', :numeric)
|
295
|
+
r += parse_margins(options.delete(:margin))
|
262
296
|
end
|
297
|
+
r
|
298
|
+
end
|
263
299
|
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
:enable_plugins,
|
291
|
-
:disable_internal_links,
|
292
|
-
:disable_external_links,
|
293
|
-
:print_media_type,
|
294
|
-
:disable_smart_shrinking,
|
295
|
-
:use_xserver,
|
296
|
-
:no_background], "", :boolean)
|
297
|
-
r +=make_options(options, [ :no_stop_slow_scripts ], "", nil)
|
298
|
-
end
|
299
|
-
r
|
300
|
+
def parse_others(options)
|
301
|
+
r = []
|
302
|
+
unless options.blank?
|
303
|
+
r += make_options(options, [:proxy,
|
304
|
+
:username,
|
305
|
+
:password,
|
306
|
+
:encoding,
|
307
|
+
:user_style_sheet,
|
308
|
+
:viewport_size])
|
309
|
+
r += make_options(options, [:cookie,
|
310
|
+
:post], '', :name_value)
|
311
|
+
r += make_options(options, [:redirect_delay,
|
312
|
+
:zoom,
|
313
|
+
:page_offset,
|
314
|
+
:javascript_delay], '', :numeric)
|
315
|
+
r += make_options(options, [:book,
|
316
|
+
:default_header,
|
317
|
+
:disable_javascript,
|
318
|
+
:enable_plugins,
|
319
|
+
:disable_internal_links,
|
320
|
+
:disable_external_links,
|
321
|
+
:print_media_type,
|
322
|
+
:disable_smart_shrinking,
|
323
|
+
:use_xserver,
|
324
|
+
:no_background], '', :boolean)
|
325
|
+
r += make_options(options, [:no_stop_slow_scripts], '', nil)
|
300
326
|
end
|
327
|
+
r
|
328
|
+
end
|
301
329
|
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
exe_path ||= possible_locations.map{|l| File.expand_path("#{l}/#{EXE_NAME}") }.find{|location| File.exists? location}
|
311
|
-
exe_path || ''
|
330
|
+
def find_wkhtmltopdf_binary_path
|
331
|
+
possible_locations = (ENV['PATH'].split(':') + %w(/usr/bin /usr/local/bin ~/bin)).uniq
|
332
|
+
exe_path ||= WickedPdf.config[:exe_path] unless WickedPdf.config.empty?
|
333
|
+
exe_path ||= begin
|
334
|
+
detected_path = (defined?(Bundler) ? `bundle exec which wkhtmltopdf` : `which wkhtmltopdf`).chomp
|
335
|
+
detected_path.present? && detected_path
|
336
|
+
rescue
|
337
|
+
nil
|
312
338
|
end
|
339
|
+
exe_path ||= possible_locations.map { |l| File.expand_path("#{l}/#{EXE_NAME}") }.find { |location| File.exist?(location) }
|
340
|
+
exe_path || ''
|
341
|
+
end
|
313
342
|
end
|