Class: Vectory::InkscapeWrapper

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/vectory/inkscape_wrapper.rb

Overview

InkscapeWrapper using Ukiryu for platform-adaptive command execution

This class provides backward compatibility with the original InkscapeWrapper while using Ukiryu under the hood for shell detection, escaping, and execution.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.convert(content:, input_format:, output_format:, output_class:, plain: false) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/vectory/inkscape_wrapper.rb', line 16

def convert(content:, input_format:, output_format:, output_class:,
plain: false)
  instance.convert(
    content: content,
    input_format: input_format,
    output_format: output_format,
    output_class: output_class,
    plain: plain,
  )
end

Instance Method Details

#convert(content:, input_format:, output_format:, output_class:, plain: false) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/vectory/inkscape_wrapper.rb', line 28

def convert(content:, input_format:, output_format:, output_class:,
plain: false)
  with_temp_files(content, input_format, output_format) do |input_path, output_path|
    # Get the tool
    tool = get_inkscape_tool

    # Build parameters
    params = build_export_params(input_path, output_path, output_format, plain)

    # Execute export command
    result = tool.execute(:export,
                          execution_timeout: Configuration.instance.timeout,
                          **params)

    raise_conversion_error(result) unless result.success?

    # Check if output file exists at specified path
    unless File.exist?(output_path)
      # Raise error with stderr details if output file not found
      # This handles cases where Inkscape returns exit code 0 but fails to create output
      raise Vectory::ConversionError,
            "Output file not found. " \
            "Expected: #{output_path}\n" \
            "Command: '#{result.command}',\n" \
            "Exit status: '#{result.status}',\n" \
            "stdout: '#{result.stdout.strip}',\n" \
            "stderr: '#{result.stderr.strip}'."
    end

    output_class.from_path(output_path)
  end
end

#height(content, format) ⇒ Object



61
62
63
# File 'lib/vectory/inkscape_wrapper.rb', line 61

def height(content, format)
  query_integer(content, format, :height)
end

#width(content, format) ⇒ Object



65
66
67
# File 'lib/vectory/inkscape_wrapper.rb', line 65

def width(content, format)
  query_integer(content, format, :width)
end