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.

Parameters:

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

    output path or directory

  • kwargs (Hash)

    export options

Yields:

  • (svg)

    transforms SVG source before rendering

Yield Parameters:

  • svg (String)

    rendered SVG source

Yield Returns:

  • (String)

    transformed SVG source

Returns:

  • (String)

    output path

Raises:

  • (Sevgi::MissingComponentError)

    when sevgi/sundries is unavailable

  • (Sevgi::MissingComponentError)

    when native export gems are unavailable

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

    when native export fails



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/sevgi/graphics/mixtures/export.rb', line 18

def PDF(path = nil, **kwargs, &block)
  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.

Parameters:

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

    output path or directory

  • kwargs (Hash)

    export options

Yields:

  • (svg)

    transforms SVG source before rendering

Yield Parameters:

  • svg (String)

    rendered SVG source

Yield Returns:

  • (String)

    transformed SVG source

Returns:

  • (String)

    output path

Raises:

  • (Sevgi::MissingComponentError)

    when sevgi/sundries is unavailable

  • (Sevgi::MissingComponentError)

    when native export gems are unavailable

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

    when native export fails



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/sevgi/graphics/mixtures/export.rb', line 41

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

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

    MissingComponentError.("sevgi/sundries")
  end

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