Class: MakePDF::Chrome

Inherits:
MakePDF::CommandBased::Writer show all
Defined in:
lib/make_pdf/chrome.rb

Constant Summary collapse

COMMAND =
'chrome-headless-render-pdf'
DEFAULT_OPTIONS =

options from 'chrome-headless-render-pdf --help'

{ # options from 'chrome-headless-render-pdf --help'
  "chrome-binary": nil,
  "chrome-option": nil,
  "remote-host": nil,
  "remote-port": nil,
  "no-margins": true,
  "include-background": true,
  "landscape": false,
  "window-size": nil,
  "paper-width": nil,
  "paper-height": nil,
  "page-ranges": nil,
  "scale": nil,
  "display-header-footer": false,
  "header-template": nil,
  "footer": nil,
  "js-time-budget": nil,
  "animation-time-budget": nil,
}

Instance Attribute Summary

Attributes inherited from MakePDF::CommandBased::Writer

#command, #options

Attributes included from MakePDF::CommandBased::Arguments

#base

Attributes inherited from PDFWriter

#logger, #output_dir, #source_url

Instance Method Summary collapse

Methods inherited from MakePDF::CommandBased::Writer

#output_for, prefix, #write

Methods included from MakePDF::CommandBased::Arguments

#make_arguments

Methods inherited from PDFWriter

#make_output_filename, #make_pdf_filename, #make_relative_file, #make_source_url, #process

Methods included from PathManip

#relative_path

Constructor Details

#initialize(**options) ⇒ Chrome

Returns a new instance of Chrome.



26
27
28
# File 'lib/make_pdf/chrome.rb', line 26

def initialize(**options)
  super(command: COMMAND, **options.merge(DEFAULT_OPTIONS))
end

Instance Method Details

#map_option_key(key, value) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/make_pdf/chrome.rb', line 30

def map_option_key(key, value)
  case key
  when 'source-url'
    [ '--url', value ]
  when 'output-filename'
    [ '--pdf', value ]
  when DEFAULT_OPTIONS.keys.method(:include?)
    case value
    when false, nil?
      []
    when true, ""
      [ "--#{key.to_s}" ]
    else
      [ "--#{key.to_s}", value ]
    end
  else
    []
  end
end