Module: Sumi::Sundries::Imprint

Extended by:
Imprint
Included in:
Imprint
Defined in:
sundries/lib/sumi/sundries/imprint.rb

Overview

Converts SVG and declarations to PDFs through the native Toji CLI.

Constant Summary collapse

Error =

A missing or unsuccessful Toji producer.

Class.new(::Sumi::Error)

Instance Method Summary collapse

Instance Method Details

#available? ⇒ Boolean

Reports whether the Toji executable is installed on PATH.

Returns:

  • (Boolean)


20
# File 'sundries/lib/sumi/sundries/imprint.rb', line 20

def available? = F.executable?(COMMAND)

#call(svg, output, declaration:, **options) {|svg| ... } ⇒ String

Produces and atomically replaces one PDF through the native CLI. Input paths and output staging remain private to this call.

Parameters:

  • svg (String) —

    SVG source

  • output (String, #to_path) —

    destination path

  • declaration (Hash) —

    JSON authoring declaration

  • options (Hash) —

    ordinary export options

Options Hash (**options):

  • :width (Numeric, nil) —

    output width in CSS pixels

  • :height (Numeric, nil) —

    output height in CSS pixels

  • :dpi (Numeric) — default: 96.0 —

    positive CSS pixel density

  • :css (String, nil) —

    export-only CSS

  • :preview (String, nil) —

    separate PNG thumbnail bytes

Yields:

  • (svg) —

    transforms the source once before production

Yield Parameters:

  • svg (String) —

    SVG after optional CSS insertion

Yield Returns:

  • (String) —

    source to render

Returns:

  • (String) —

    expanded destination path

Raises:



57
58
59
60
61
62
# File 'sundries/lib/sumi/sundries/imprint.rb', line 57

def call(svg, output, declaration:, **options, &block)
  ArgumentError.("Imprint declaration must be a Hash") unless declaration.is_a?(::Hash)
  unknown = options.keys - %i[css dpi height width preview]
  ArgumentError.("Unknown Imprint option: #{unknown.first}") unless unknown.empty?
  Export.call(svg, output, format: :pdf, declaration:, fallback: false, **options, &block)
end

#fingerprint ⇒ Hash{String => Object}?

Returns the selected executable's content identity for output caches. PATH is resolved on each call. Absence returns nil.

Returns:

  • (Hash{String => Object}, nil) —

    executable SHA-256 and native dependency report

Raises:

  • (SystemCallError) —

    when the executable cannot be read

  • (Sumi::Sundries::Imprint::Error) —

    when the version command fails or its report is invalid



27
28
29
30
31
32
33
34
35
36
# File 'sundries/lib/sumi/sundries/imprint.rb', line 27

def fingerprint
  path = F.executable(COMMAND)
  return unless path
  process = run(path, "--version")
  report = JSON.parse(process.out)
  Error.("Invalid Toji version report") unless report.is_a?(Hash) && report["contract"] == 1
  {"sha256" => Digest::SHA256.file(path).hexdigest, "runtime" => report}
rescue JSON::ParserError => e
  Error.("Invalid Toji version report: #{e.message}")
end