Module: Sumi::Graphics::Document
- Defined in:
- graphics/lib/sumi/graphics/document.rb,
graphics/lib/sumi/graphics/document/base.rb,
graphics/lib/sumi/graphics/document/html.rb,
graphics/lib/sumi/graphics/document/default.rb,
graphics/lib/sumi/graphics/document/minimal.rb,
graphics/lib/sumi/graphics/document/inkscape.rb,
showcase/lib/sumi/showcase/passive.rb
Overview
SVG document profile factory and process-global named-profile registry.
A profile owns SVG root attributes and optional preamble lines, but not canvas size. Built-in and named profiles can be passed to SVG. An anonymous profile class is useful when library code needs one-off metadata without adding a global name.
| Profile | Preamble | Root metadata | Additional DSL |
|---|---|---|---|
:minimal |
none | none | common document DSL |
:default |
XML declaration | SVG namespace | common document DSL |
:html |
none | SVG namespace | common document DSL |
:inkscape |
XML declaration | SVG and editor namespaces with crisp edges | Draw, Hatch, and editor/RDF helpers |
The Inkscape root adds Sumi, Inkscape, and Sodipodi namespaces plus shape-rendering="crispEdges". Every
selectable profile has the same validation and lint lifecycle. :minimal changes serialization metadata, not
checking policy. Base is the public common extension layer rather than a selectable profile. Minimal and
Default are sibling concrete profiles: Minimal contributes no metadata and is not the semantic base of the other
profiles. Targeting Base through Mixtures.mixin changes every descendant profile process-wide.
Subclass Base first to keep an extension scoped.
Defined Under Namespace
Classes: Base, Default, HTML, Inkscape, Minimal, Profile, Proto
Class Method Summary collapse
-
.call(document, canvas = Undefined, **attributes) { ... } ⇒ Sumi::Graphics::Document::Proto
Builds a root SVG element from a document profile.
-
.define(name = Undefined, preambles: Undefined, attributes: Undefined, overwrite: false) ⇒ Class
Defines, looks up, or returns an anonymous document profile class.
-
.exist?(name) ⇒ Boolean
Reports whether a normalizable document profile name is registered.
-
.fetch(name) ⇒ Class
Returns a registered document class by profile name.
-
.keys ⇒ Array<Symbol>
Returns registered document profile names.
-
.profile(name) ⇒ Sumi::Graphics::Document::Profile
Returns immutable metadata for a registered document profile.
Class Method Details
.call(document, canvas = Undefined, **attributes) { ... } ⇒ Sumi::Graphics::Document::Proto
Builds a root SVG element from a document profile.
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'graphics/lib/sumi/graphics/document.rb', line 60 def self.call(document, canvas = Undefined, **attributes, &block) klass = case document when ::Class document if document <= Proto else fetch(document) end ArgumentError.("Unknown document profile: #{document}") unless klass klass.root(klass.attributes, canvas_attributes(canvas), attributes, &block) end |
.define(name = Undefined, preambles: Undefined, attributes: Undefined, overwrite: false) ⇒ Class
Defines, looks up, or returns an anonymous document profile class.
A name without metadata performs lookup. A name plus either metadata keyword defines or compatibly reuses a named profile. Omitting the name creates an anonymous class and leaves the registry unchanged. Named profiles are process-global. Use them for shared vocabulary rather than per-call configuration. Profile metadata is captured before class or thread-atomic registry mutation. Mutable non-container attribute values are stringified once, attribute names and nested Hash keys are normalized, and nil attributes are omitted during capture. Successful named definitions return the canonical class stored by the registry, including when identical definitions race.
134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'graphics/lib/sumi/graphics/document.rb', line 134 def self.define(name = Undefined, preambles: Undefined, attributes: Undefined, overwrite: false) overwrite!(overwrite) return anonymous(attributes:, preambles:) if name == Undefined return fetch(name) if preambles == Undefined && attributes == Undefined name = Name.normalize!(name) current = reuse(name, attributes:, preambles:, overwrite:) return current if current attributes, preambles = defaults(attributes:, preambles:) Class.new(Base) { document(name, preambles:, attributes:, overwrite:) } Registry[name] end |
.exist?(name) ⇒ Boolean
Reports whether a normalizable document profile name is registered. Invalid converters return false and do not change the registry.
91 92 93 94 |
# File 'graphics/lib/sumi/graphics/document.rb', line 91 def self.exist?(name) name = Name.normalize(name) name ? !Registry[name].nil? : false end |
.fetch(name) ⇒ Class
Returns a registered document class by profile name.
80 81 82 83 |
# File 'graphics/lib/sumi/graphics/document.rb', line 80 def self.fetch(name) name = Name.normalize!(name) Registry[name] || ArgumentError.("Unknown document profile: #{name}") end |
.keys ⇒ Array<Symbol>
Returns registered document profile names.
98 |
# File 'graphics/lib/sumi/graphics/document.rb', line 98 def self.keys = Registry.available.keys.freeze |
.profile(name) ⇒ Sumi::Graphics::Document::Profile
Returns immutable metadata for a registered document profile.
104 |
# File 'graphics/lib/sumi/graphics/document.rb', line 104 def self.profile(name) = fetch(name).profile |