Module: Sumi::Derender
- Defined in:
- derender/lib/sumi/derender.rb,
derender/lib/sumi/derender/node.rb,
derender/lib/sumi/derender/version.rb,
derender/lib/sumi/derender/document.rb,
derender/lib/sumi/derender/elements.rb,
derender/lib/sumi/derender/internal.rb,
derender/lib/sumi/derender/evaluator.rb,
derender/lib/sumi/derender/attributes.rb,
derender/lib/sumi/derender/elements/any.rb,
derender/lib/sumi/derender/elements/root.rb,
derender/lib/sumi/derender/elements/text.rb,
derender/lib/sumi/derender/elements/style.rb,
derender/lib/sumi/derender/elements/comment.rb,
derender/lib/sumi/derender/elements/instruction.rb
Overview
Brings editor-authored SVG/XML into programmatic Sumi workflows.
Some vector geometry is easier to create in a visual editor than to reconstruct as Ruby. Examples include a Bezier-heavy logo and a hand-adjusted illustration. Derender preserves that SVG/XML tree as inspectable data, or graphics elements under an existing document. This lets editor-authored geometry participate in programmatic composition, styling, layout, and output. Use it when SVG/XML is a real input artifact, not as an intermediate authoring format for ordinary Sumi drawing code.
Generated source uses bare DSL calls only for recognized element names that cannot dispatch to an existing Ruby or
Sumi method. Other XML names use the explicit Element DSL word so executing generated source preserves the XML
tree without invoking same-named Ruby methods.
Evaluation APIs treat SVG/XML as data: they build graphics element trees directly and do not execute generated Ruby source. The String returned by source-generation APIs is ordinary Ruby source. Review and integrate it statically rather than passing it to Ruby's raw dynamic evaluation methods. Malformed, rootless, or unmatched input is rejected with ArgumentError. Processing instructions retain their target, data, and order as inert XML markup. Custom entity references in the selected subtree are rejected before inclusion changes a target. Predefined and numeric references remain valid. Whole-document conversion rejects nodes after the root. Explicit id selection ignores unrelated document siblings. Input uses the XML encoding declaration or byte-order mark. Generated source and rendered XML use UTF-8. The XML declaration retains its version and standalone flag, with any encoding field changed to UTF-8.
Namespace dispatch treats qualified and foreign elements as ordinary XML nodes. Their element identity, namespace
declarations, qualified attributes, significant text, and nested svg elements survive source generation and direct
evaluation. CSS specialization applies only to unqualified style elements in no namespace or the default SVG
namespace. The document-root strategy also requires an unqualified svg at the root of the conversion.
Simple CSS rules use the readable css({...}) DSL form. At-rules, duplicate declarations, and other CSS that cannot
be represented losslessly as a Hash remain owned raw style content.
Attribute omission uses exact, case-sensitive names across the selected subtree. ID selection happens first.
namespace declarations remain intact, and omitting the style attribute does not omit style elements.
Defined Under Namespace
Classes: Node
Constant Summary collapse
- VERSION =
Current version of the Sumi derender gem.
"1.0.0"
Class Method Summary collapse
-
.decompile(content, id: nil, omit: nil) ⇒ Sumi::Derender::Node
Converts SVG/XML content into an immutable derender result.
-
.decompile_file(file, id: nil, omit: nil) ⇒ Sumi::Derender::Node
Converts an SVG/XML file into an immutable derender result.
-
.derender(content, id: nil, omit: nil) ⇒ String
Converts SVG/XML content into Sumi DSL Ruby source.
-
.derender_file(file, id: nil, omit: nil) ⇒ String
Converts an SVG/XML file into Sumi DSL Ruby source.
-
.evaluate(content, element, id: nil, omit: nil) ⇒ Sumi::Graphics::Element?
Evaluates SVG/XML content under a graphics element, including the selected node.
-
.evaluate_children(content, element, id: nil, omit: nil) ⇒ Array<Sumi::Graphics::Element>
Evaluates only the selected node's children under a graphics element.
-
.evaluate_children_file(file, element, id: nil, omit: nil) ⇒ Array<Sumi::Graphics::Element>
Evaluates only the selected node's children from an SVG/XML file under a graphics element.
-
.evaluate_file(file, element, id: nil, omit: nil) ⇒ Sumi::Graphics::Element?
Evaluates an SVG/XML file under a graphics element, including the selected node.
Class Method Details
.decompile(content, id: nil, omit: nil) ⇒ Sumi::Derender::Node
Converts SVG/XML content into an immutable derender result.
77 |
# File 'derender/lib/sumi/derender.rb', line 77 def self.decompile(content, id: nil, omit: nil) = Document.new(content).decompile(id, omit:) |
.decompile_file(file, id: nil, omit: nil) ⇒ Sumi::Derender::Node
Converts an SVG/XML file into an immutable derender result.
90 |
# File 'derender/lib/sumi/derender.rb', line 90 def self.decompile_file(file, id: nil, omit: nil) = Document.load_file(file).decompile(id, omit:) |
.derender(content, id: nil, omit: nil) ⇒ String
Namespace-aware dispatch preserves ordinary foreign/qualified nodes and nested SVG elements.
Unsafe bare Ruby names are emitted through the explicit Element DSL word.
Converts SVG/XML content into Sumi DSL Ruby source. The returned String is ordinary Ruby source. Review and integrate it statically rather than using Ruby's raw dynamic evaluation methods.
109 |
# File 'derender/lib/sumi/derender.rb', line 109 def self.derender(content, id: nil, omit: nil) = Document.new(content).decompile(id, omit:).derender |
.derender_file(file, id: nil, omit: nil) ⇒ String
Namespace-aware dispatch preserves ordinary foreign/qualified nodes and nested SVG elements.
Unsafe bare Ruby names are emitted through the explicit Element DSL word.
Converts an SVG/XML file into Sumi DSL Ruby source. The returned String is ordinary Ruby source. Review and integrate it statically rather than using Ruby's raw dynamic evaluation methods.
126 |
# File 'derender/lib/sumi/derender.rb', line 126 def self.derender_file(file, id: nil, omit: nil) = Document.load_file(file).decompile(id, omit:).derender |
.evaluate(content, element, id: nil, omit: nil) ⇒ Sumi::Graphics::Element?
Namespace-aware dispatch preserves ordinary foreign/qualified nodes and nested SVG elements.
Evaluates SVG/XML content under a graphics element, including the selected node.
145 146 147 |
# File 'derender/lib/sumi/derender.rb', line 145 def self.evaluate(content, element, id: nil, omit: nil) Document.new(content).decompile(id, omit:).evaluate(element) end |
.evaluate_children(content, element, id: nil, omit: nil) ⇒ Array<Sumi::Graphics::Element>
Namespace-aware dispatch preserves ordinary foreign/qualified nodes and nested SVG elements.
Evaluates only the selected node's children under a graphics element.
165 166 167 |
# File 'derender/lib/sumi/derender.rb', line 165 def self.evaluate_children(content, element, id: nil, omit: nil) Document.new(content).decompile(id, omit:).evaluate_children(element) end |
.evaluate_children_file(file, element, id: nil, omit: nil) ⇒ Array<Sumi::Graphics::Element>
Namespace-aware dispatch preserves ordinary foreign/qualified nodes and nested SVG elements.
Evaluates only the selected node's children from an SVG/XML file under a graphics element.
200 201 202 |
# File 'derender/lib/sumi/derender.rb', line 200 def self.evaluate_children_file(file, element, id: nil, omit: nil) Document.load_file(file).decompile(id, omit:).evaluate_children(element) end |
.evaluate_file(file, element, id: nil, omit: nil) ⇒ Sumi::Graphics::Element?
Namespace-aware dispatch preserves ordinary foreign/qualified nodes and nested SVG elements.
Evaluates an SVG/XML file under a graphics element, including the selected node.
183 184 185 |
# File 'derender/lib/sumi/derender.rb', line 183 def self.evaluate_file(file, element, id: nil, omit: nil) Document.load_file(file).decompile(id, omit:).evaluate(element) end |