Class: WkhtmltopdfRunner::Runner
- Inherits:
-
Object
- Object
- WkhtmltopdfRunner::Runner
- Defined in:
- lib/wkhtmltopdf_runner/runner.rb
Instance Method Summary collapse
- #config ⇒ Object (also: #configuration)
-
#configure {|config| ... } ⇒ Object
Configure client with a block of settings.
- #pdf_from_file(file, options = {}, &block) ⇒ Object
- #pdf_from_string(string, options = {}, &block) ⇒ Object
- #pdf_from_url(url, options = {}) ⇒ Object
- #run(url, file, options = {}) ⇒ Object
Instance Method Details
#config ⇒ Object Also known as: configuration
43 44 45 |
# File 'lib/wkhtmltopdf_runner/runner.rb', line 43 def config @config ||= Configuration.new end |
#configure {|config| ... } ⇒ Object
Configure client with a block of settings.
49 50 51 52 |
# File 'lib/wkhtmltopdf_runner/runner.rb', line 49 def configure yield(config) if block_given? true end |
#pdf_from_file(file, options = {}, &block) ⇒ Object
24 25 26 |
# File 'lib/wkhtmltopdf_runner/runner.rb', line 24 def pdf_from_file(file, = {}, &block) pdf_from_url("file://#{file.path}", , &block) end |
#pdf_from_string(string, options = {}, &block) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/wkhtmltopdf_runner/runner.rb', line 28 def pdf_from_string(string, = {}, &block) Tempfile.open(['file-', '.html']) do |html_file| html_file.write(string) html_file.rewind pdf_from_file(html_file, , &block) end end |
#pdf_from_url(url, options = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/wkhtmltopdf_runner/runner.rb', line 8 def pdf_from_url(url, = {}) Tempfile.open(['file-', '.pdf']) do |pdf_file| pdf_file.binmode run(url, pdf_file, ) pdf_file.rewind if block_given? yield(pdf_file) return true end pdf_file.read end end |
#run(url, file, options = {}) ⇒ Object
37 38 39 40 41 |
# File 'lib/wkhtmltopdf_runner/runner.rb', line 37 def run(url, file, = {}) WkhtmltopdfRunner::Cmd .new(url: url, file: file, config: config, options: ) .run end |