Module: Sevgi::Graphics::Document
- Defined in:
- lib/sevgi/graphics/document.rb,
lib/sevgi/graphics/document/base.rb,
lib/sevgi/graphics/document/html.rb,
lib/sevgi/graphics/document/default.rb,
lib/sevgi/graphics/document/minimal.rb,
lib/sevgi/graphics/document/inkscape.rb
Overview
SVG document profile factory.
Defined Under Namespace
Classes: Base, Default, HTML, Inkscape, Minimal, Profile, Proto
Constant Summary collapse
- DEFAULTS =
Default render-time checks.
{lint: true, validate: true}.freeze
Class Method Summary collapse
-
.call(document, canvas = Undefined) { ... } ⇒ Sevgi::Graphics::Document::Proto
Builds a root SVG element from a document profile.
-
.define(name = Undefined, preambles: Undefined, attributes: Undefined, overwrite: false) ⇒ Class
Defines or returns a document profile class.
Class Method Details
.call(document, canvas = Undefined) { ... } ⇒ Sevgi::Graphics::Document::Proto
Builds a root SVG element from a document profile.
90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/sevgi/graphics/document.rb', line 90 def self.call(document, canvas = Undefined, **, &block) klass = case document when ::Class document if document <= Proto else Profile[document] end ArgumentError.("Unknown document profile: #{document}") unless klass klass.root(**klass.attributes, **canvas_attributes(canvas), **, &block) end |
.define(name = Undefined, preambles: Undefined, attributes: Undefined, overwrite: false) ⇒ Class
Defines or returns a document profile class. Profile metadata is captured before class or thread-atomic registry mutation. Mutable non-container attribute values are stringified once during capture. Successful named definitions return the canonical class stored by the registry, including when identical definitions race.
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/sevgi/graphics/document.rb', line 126 def self.define(name = Undefined, preambles: Undefined, attributes: Undefined, overwrite: false) return anonymous(attributes:, preambles:) if name == Undefined return lookup(name) if preambles == Undefined && attributes == Undefined name = Profile.normalize!(name) if (current = Profile[name]) reject_conflict(name, current, attributes:, preambles:) unless overwrite return current unless overwrite end attributes, preambles = defaults(attributes:, preambles:) Class.new(Base) { document(name, preambles:, attributes:, overwrite:) } Registry[name] end |