Class: DragonflyPuppeteer::Generators::Pdf

Inherits:
Object
  • Object
show all
Defined in:
lib/dragonfly_puppeteer/generators/pdf.rb

Defined Under Namespace

Classes: UnsupportedFormat

Instance Method Summary collapse

Instance Method Details

#call(content, source, opts = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/dragonfly_puppeteer/generators/pdf.rb', line 9

def call(content, source, opts = {})
  format = 'pdf'

  pdf_opts = extract_pdf_opts(opts)
  goto_opts = extract_goto_opts(opts)
  media_type = extract_media_type(opts)
  http_headers = extract_http_headers(opts)
  delay = extract_delay(opts)

  file_name = extract_file_name(opts)

  node_command = content.env.fetch(:node_command, 'node')

  content.shell_generate(ext: format) do |path|
    pdf_opts[:path] = path
    "#{node_command} #{script} #{Shellwords.escape(source)} '#{pdf_opts.to_json}' '#{goto_opts.to_json}' #{media_type} '#{http_headers.to_json}' #{delay}"
  end
  content.add_meta('format' => 'pdf', 'name' => "#{file_name}.pdf")
end

#update_url(url_attributes, source, opts = {}) ⇒ Object



29
30
31
32
# File 'lib/dragonfly_puppeteer/generators/pdf.rb', line 29

def update_url(url_attributes, source, opts = {})
  file_name = extract_file_name(opts)
  url_attributes.name = "#{file_name}.pdf"
end