Class: WeasyPDF::CommandBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/weasy_pdf/command_builder.rb

Overview

Pure value transformation: binary + resolved options → shell command Array. No global state — callers resolve configuration (base_url, etc.) before passing options in, so this class is testable without WeasyPDF.configuration.

Instance Method Summary collapse

Constructor Details

#initialize(binary, options = {}) ⇒ CommandBuilder

Returns a new instance of CommandBuilder.



8
9
10
11
# File 'lib/weasy_pdf/command_builder.rb', line 8

def initialize(binary, options = {})
  @binary = binary
  @options = options
end

Instance Method Details

#build(input_path, output_path) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/weasy_pdf/command_builder.rb', line 13

def build(input_path, output_path)
  cmd = [@binary]
  cmd += ["--encoding", @options[:encoding]] if @options[:encoding]
  cmd += ["--zoom", @options[:zoom].to_s] if @options[:zoom] && @options[:zoom] != 1
  cmd += ["--media-type", @options[:media_type]] if @options[:media_type]
  cmd += ["--base-url", @options[:base_url].to_s] if @options[:base_url]
  Array(@options[:stylesheets]).each { |s| cmd += ["--stylesheet", s] }
  cmd + [input_path, output_path]
end