Module: Sevgi::Graphics::Mixtures::Export

Defined in:
lib/sevgi/graphics/mixtures/export.rb

Overview

DSL helpers for native SVG export formats.

Instance Method Summary collapse

Instance Method Details

#PDF(path = nil, **kwargs) {|svg| ... } ⇒ String

Exports the document as PDF. Relative paths are expanded, missing parent directories are created after export validation, and an existing file is replaced. An existing directory target uses the caller-derived default PDF name.

Parameters:

  • path (String, #to_path, nil) (defaults to: nil)

    output path or existing directory

  • kwargs (Hash)

    export options

Options Hash (**kwargs):

  • :default (String, #to_path, nil)

    caller-derived output name used when path is nil or a directory

  • :width (Numeric, nil)

    finite positive target width in CSS pixels

  • :height (Numeric, nil)

    finite positive target height in CSS pixels

  • :dpi (Numeric) — default: 96.0

    finite positive CSS pixel density

  • :css (String, nil)

    CSS inserted before rendering

Yields:

  • (svg)

    transforms SVG source before rendering

Yield Parameters:

  • svg (String)

    rendered SVG source

Yield Returns:

  • (String)

    transformed SVG source

Returns:

  • (String)

    expanded output path

Raises:

  • (Sevgi::ArgumentError)

    when a path, default, option name, CSS value, or transformed SVG is invalid

  • (Sevgi::ValidationError)

    when validation is enabled and the document violates the SVG standard

  • (Sevgi::Graphics::LintError)

    when linting is enabled and the document has structural conflicts

  • (Sevgi::MissingComponentError)

    when sevgi/sundries is unavailable

  • (Sevgi::MissingComponentError)

    when native export gems are unavailable

  • (Sevgi::Sundries::Export::ExportError)

    when native export fails

  • (SystemCallError)

    when the output directory or file cannot be created or written



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/sevgi/graphics/mixtures/export.rb', line 48

def PDF(path = nil, **kwargs, &block)
  kwargs = Options.(kwargs)
  begin
    require "sevgi/sundries"

  rescue ::LoadError => e
    raise unless e.path == "sevgi/sundries"

    MissingComponentError.("sevgi/sundries")
  end

  Export(path, **kwargs, format: :pdf, &block)
end

#PNG(path = nil, **kwargs) {|svg| ... } ⇒ String

Exports the document as PNG. Relative paths are expanded, missing parent directories are created after export validation, and an existing file is replaced. An existing directory target uses the caller-derived default PNG name.

Parameters:

  • path (String, #to_path, nil) (defaults to: nil)

    output path or existing directory

  • kwargs (Hash)

    export options

Options Hash (**kwargs):

  • :default (String, #to_path, nil)

    caller-derived output name used when path is nil or a directory

  • :width (Numeric, nil)

    finite positive target width in output pixels

  • :height (Numeric, nil)

    finite positive target height in output pixels

  • :dpi (Numeric) — default: 96.0

    finite positive CSS pixel density

  • :css (String, nil)

    CSS inserted before rendering

Yields:

  • (svg)

    transforms SVG source before rendering

Yield Parameters:

  • svg (String)

    rendered SVG source

Yield Returns:

  • (String)

    transformed SVG source

Returns:

  • (String)

    expanded output path

Raises:

  • (Sevgi::ArgumentError)

    when a path, default, option name, CSS value, or transformed SVG is invalid

  • (Sevgi::ValidationError)

    when validation is enabled and the document violates the SVG standard

  • (Sevgi::Graphics::LintError)

    when linting is enabled and the document has structural conflicts

  • (Sevgi::MissingComponentError)

    when sevgi/sundries is unavailable

  • (Sevgi::MissingComponentError)

    when native export gems are unavailable

  • (Sevgi::Sundries::Export::ExportError)

    when native export fails

  • (SystemCallError)

    when the output directory or file cannot be created or written



83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/sevgi/graphics/mixtures/export.rb', line 83

def PNG(path = nil, **kwargs, &block)
  kwargs = Options.(kwargs)
  begin
    require "sevgi/sundries"

  rescue ::LoadError => e
    raise unless e.path == "sevgi/sundries"

    MissingComponentError.("sevgi/sundries")
  end

  Export(path, **kwargs, format: :png, &block)
end