Class: Sevgi::Graphics::Content Abstract
- Inherits:
-
Object
- Object
- Sevgi::Graphics::Content
- Defined in:
- lib/sevgi/graphics/auxiliary/content.rb
Overview
Subclasses implement #render and expose their own construction API.
Extensible protocol for renderable text-like content inside an SVG element. Use Content.cdata, Content.css, Content.encoded, or Content.verbatim for built-in content, or subclass Content and implement #render for a custom serialization. Content owns an immutable deep snapshot: strings and containers are copied, mutable leaf objects are stringified once during construction, and #content returns caller-owned copies. Later mutations cannot change rendering or invalidate the construction-time XML checks.
Defined Under Namespace
Classes: CData, CSS, Encoded, Verbatim
Class Method Summary collapse
-
.cdata(content) ⇒ Sevgi::Graphics::Content::CData
Builds CDATA content.
-
.css(content) ⇒ Sevgi::Graphics::Content::CSS
Builds CSS content.
-
.encoded(content) ⇒ Sevgi::Graphics::Content::Encoded
Builds XML text-encoded content.
-
.verbatim(content) ⇒ Sevgi::Graphics::Content::Verbatim
Builds verbatim content.
Instance Method Summary collapse
-
#content ⇒ Object
Returns a recursively independent, caller-owned payload snapshot.
-
#initialize(content) ⇒ void
constructor
private
Creates immutable content from a deep payload snapshot.
-
#render(_output, _depth) ⇒ Object
abstract
Appends this content's serialized XML lines to rendering output.
-
#to_s ⇒ String
Returns content as a string.
Constructor Details
#initialize(content) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates immutable content from a deep payload snapshot. Strings and containers are copied recursively; mutable non-container objects are stringified once during construction. The caller's objects are never retained.
116 117 118 119 |
# File 'lib/sevgi/graphics/auxiliary/content.rb', line 116 def initialize(content) @content = Snapshot.capture(content) XML.validate(@content) end |
Class Method Details
.cdata(content) ⇒ Sevgi::Graphics::Content::CData
158 |
# File 'lib/sevgi/graphics/auxiliary/content.rb', line 158 def self.cdata(...) = CData.send(:new, ...) |
.css(content) ⇒ Sevgi::Graphics::Content::CSS
167 |
# File 'lib/sevgi/graphics/auxiliary/content.rb', line 167 def self.css(...) = CSS.send(:new, ...) |
.encoded(content) ⇒ Sevgi::Graphics::Content::Encoded
176 |
# File 'lib/sevgi/graphics/auxiliary/content.rb', line 176 def self.encoded(...) = Encoded.send(:new, ...) |
.verbatim(content) ⇒ Sevgi::Graphics::Content::Verbatim
185 |
# File 'lib/sevgi/graphics/auxiliary/content.rb', line 185 def self.verbatim(...) = Verbatim.send(:new, ...) |
Instance Method Details
#content ⇒ Object
Returns a recursively independent, caller-owned payload snapshot.
107 |
# File 'lib/sevgi/graphics/auxiliary/content.rb', line 107 def content = Snapshot.copy(@content) |
#render(_output, _depth) ⇒ Object
Subclasses implement content rendering.
Appends this content's serialized XML lines to rendering output.
The output collaborator responds to append(depth, *lines), where depth is an Integer or nil and every line
is a String containing valid serialized XML text. The rendering engine ignores both append and render return
values. Custom content is responsible for escaping data that it inserts into markup.
141 |
# File 'lib/sevgi/graphics/auxiliary/content.rb', line 141 def render(_output, _depth) = PanicError.("#{self.class}#render must be implemented") |
#to_s ⇒ String
Returns content as a string.
145 |
# File 'lib/sevgi/graphics/auxiliary/content.rb', line 145 def to_s = XML.text(payload) |