Class: WeasyRb::Executor

Inherits:
Object
  • Object
show all
Defined in:
lib/weasy_rb/executor.rb

Overview

Executes WeasyPrint commands using Open3

Defined Under Namespace

Classes: Result

Instance Method Summary collapse

Instance Method Details

#execute(command, html_content) ⇒ Result

Execute WeasyPrint command with HTML input rubocop:disable Metrics/MethodLength

Parameters:

  • command (Array<String>)

    Command array to execute

  • html_content (String)

    HTML content to pipe to stdin

Returns:

  • (Result)

    Execution result



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/weasy_rb/executor.rb', line 20

def execute(command, html_content)
  validate_weasyprint_availability

  stdout, stderr, status = capture_command_output(command, html_content)

  Result.new(
    success: status.success?,
    output: stdout,
    error: stderr,
    exit_status: status.exitstatus
  )
rescue Errno::ENOENT
  raise CommandError, "WeasyPrint is not installed or not available in PATH"
rescue StandardError => e
  raise CommandError, "Failed to execute WeasyPrint: #{e.message}"
end