Class: Sevgi::Graphics::Document::Proto

Inherits:
Element
  • Object
show all
Defined in:
lib/sevgi/graphics/document.rb

Overview

Base document root element class.

Direct Known Subclasses

Base

Instance Attribute Summary

Attributes inherited from Element

#attributes, #children, #contents, #name, #parent

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Element

element, #initialize, root, root?, valid?

Constructor Details

This class inherits a constructor from Sevgi::Graphics::Element

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Sevgi::Graphics::Element

Class Method Details

.attributesHash{Symbol => Object}

Returns effective inherited root attributes for this document class. Profile update suffixes are applied from the oldest configured ancestor to this class.

Returns:

  • (Hash{Symbol => Object})

    inherited root attributes without update suffixes

Raises:

  • (Sevgi::ArgumentError)

    when a non-Proto class has no configured ancestor



498
499
500
501
502
503
504
505
# File 'lib/sevgi/graphics/document.rb', line 498

def self.attributes
  return {} if self == Proto

  ArgumentError.("Document class has no configured profile: #{self}") unless profile
  return superclass.attributes unless instance_variable_defined?(:@profile)

  Attributes.new(superclass.attributes).tap { it.merge!(@profile.attributes) }.to_h
end

.preamblesArray<String>?

Returns inherited preamble lines for this document class.

Returns:

  • (Array<String>, nil)

Raises:

  • (Sevgi::ArgumentError)

    when a non-Proto class has no configured ancestor



510
511
512
513
514
515
516
517
# File 'lib/sevgi/graphics/document.rb', line 510

def self.preambles
  return if self == Proto

  ArgumentError.("Document class has no configured profile: #{self}") unless profile
  return superclass.preambles unless instance_variable_defined?(:@profile)

  @profile.preambles || superclass.preambles
end

.profileSevgi::Graphics::Document::Profile?

Returns the nearest immutable profile metadata in the class hierarchy.

Returns:



468
469
470
471
472
# File 'lib/sevgi/graphics/document.rb', line 468

def self.profile
  return @profile if instance_variable_defined?(:@profile)

  superclass.profile if superclass.respond_to?(:profile)
end

Instance Method Details

#call(**options) ⇒ String

Renders this document after its optional pre-render checks.

Examples:

Render a document directly with separate check and renderer options

document = Sevgi::Graphics.SVG(:minimal) { rect width: 3 }
document.call(lint: false, style: :inline)

Parameters:

Options Hash (**options):

  • :lint (Boolean) — default: true

    run document lint checks

  • :validate (Boolean) — default: true

    run SVG standard validation

Returns:

  • (String)

    SVG document source

Raises:

  • (Sevgi::ArgumentError)

    when an 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:



487
488
489
490
491
492
# File 'lib/sevgi/graphics/document.rb', line 487

def call(**options)
  checks = DEFAULTS.merge(options.select { |key, _| DEFAULTS.key?(key) })
  self.PreRender(**checks) if respond_to?(:PreRender)
  render_options = options.reject { |key, _| DEFAULTS.key?(key) }
  self.Render(**render_options)
end