Class: PDFService::PhantomJSRenderer

Inherits:
Object
  • Object
show all
Defined in:
lib/pdf_service/phantom_js_renderer.rb

Constant Summary collapse

RASTERIZE_SCRIPT_PATH =
Pathname(__FILE__).dirname.join('phantomjs_rasterize.js').to_s.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(script: RASTERIZE_SCRIPT_PATH, logger: NullLogger.new, binary: 'phantomjs') ⇒ PhantomJSRenderer

Returns a new instance of PhantomJSRenderer.



6
7
8
9
10
11
# File 'lib/pdf_service/phantom_js_renderer.rb', line 6

def initialize(script: RASTERIZE_SCRIPT_PATH, logger: NullLogger.new, binary: 'phantomjs')
  @script = script.freeze
  @logger = logger
  @binary = binary.freeze
  Kernel.warn("Warning! PhantomJS is not available in PATH #{@binary}") if `which #{binary}`.strip.empty?
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



12
13
14
# File 'lib/pdf_service/phantom_js_renderer.rb', line 12

def logger
  @logger
end

Instance Method Details

#rasterize(url, output, format: 'A4') ⇒ Object



14
15
16
17
# File 'lib/pdf_service/phantom_js_renderer.rb', line 14

def rasterize(url, output, format: 'A4')
  options = [url, output, format]
  phantomjs(@script, url, options)
end