Module: Sevgi::Graphics::Mixtures::Save

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

Overview

DSL helpers for writing rendered SVG output.

Instance Method Summary collapse

Instance Method Details

#Out(**kwargs) ⇒ nil

Writes rendered SVG to standard output.

Parameters:

Returns:

  • (nil)

Raises:

  • (Sevgi::ArgumentError)

    when a render option or XML-bound value 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

See Also:



51
52
53
# File 'lib/sevgi/graphics/mixtures/save.rb', line 51

def Out(**kwargs)
  F.out(self.(**kwargs))
end

#Save(path = nil, default: nil, backup_suffix: nil, **kwargs) {|content| ... } ⇒ String?

Saves rendered SVG when its content differs from the destination. Relative destinations are expanded before being returned. When a non-empty backup suffix is given, an existing destination is copied immediately before replacement; unchanged saves leave both files untouched. Missing parent directories are created. An existing directory target uses the default file name.

Examples:

Save to a relative destination

path = Sevgi::Graphics.SVG(:minimal).Save("build/drawing.svg")
path == File.expand_path("build/drawing.svg") # => true

Parameters:

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

    output path or existing directory

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

    default output path

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

    suffix used for an existing-file backup

  • kwargs (Hash)

    pre-render and renderer options accepted by Document::Proto#call

Yields:

  • (content)

    optionally normalizes old and new content for change detection

Yield Parameters:

  • content (String)

    old or new SVG source

Yield Returns:

  • (String)

    normalized SVG source

Returns:

  • (String, nil)

    expanded path when written, or nil when unchanged

Raises:

  • (Sevgi::ArgumentError)

    when a selected path/default, render option, or XML-bound value 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

  • (SystemCallError)

    when the destination or backup cannot be created, read, or written

See Also:



75
76
77
78
79
80
# File 'lib/sevgi/graphics/mixtures/save.rb', line 75

def Save(path = nil, default: nil, backup_suffix: nil, **kwargs, &filter)
  default = F.subext(EXT, caller_locations(1..1).first.path) if default.nil?
  path = Path.resolve(path, default:, context: "Save")

  Writer.(path, self.(**kwargs), backup_suffix:, &filter)
end

#Write(path, **kwargs) {|content| ... } ⇒ String?

Writes rendered SVG to a path. Missing parent directories are created. Unlike #Save, a directory is not treated as a request for a default file name.

Parameters:

  • path (String, #to_path)

    output file path

  • kwargs (Hash)

    pre-render and renderer options accepted by Document::Proto#call

Yields:

  • (content)

    optionally normalizes old and new content for change detection

Yield Parameters:

  • content (String)

    old or new SVG source

Yield Returns:

  • (String)

    normalized SVG source

Returns:

  • (String, nil)

    expanded path when written, or nil when unchanged

Raises:

  • (Sevgi::ArgumentError)

    when path, a render option, or an XML-bound value 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

  • (SystemCallError)

    when the destination cannot be read or written

See Also:



96
97
98
99
100
101
# File 'lib/sevgi/graphics/mixtures/save.rb', line 96

def Write(path, **kwargs, &filter)
  path = Path.(path, context: "Write path")
  ArgumentError.("Write path must name a file") if ::File.directory?(path)

  Writer.(path, self.(**kwargs), &filter)
end