Class: Sevgi::Graphics::Content
- Inherits:
-
Object
- Object
- Sevgi::Graphics::Content
- Defined in:
- lib/sevgi/graphics/auxiliary/content.rb
Overview
Renderable text-like content inside an SVG element. 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.
-
.contents(*args) ⇒ Array<Sevgi::Graphics::Content>
Wraps content arguments, encoding non-content values.
-
.css(content) ⇒ Sevgi::Graphics::Content::CSS
Builds CSS content.
-
.encoded(content) ⇒ Sevgi::Graphics::Content::Encoded
Builds XML text-encoded content.
-
.text(contents) ⇒ String
Joins content lines with newlines.
-
.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
Creates immutable content from a deep payload snapshot.
-
#initialize_copy(original) ⇒ void
private
Copies content payload ownership for duplicated element trees.
-
#render(_renderer, _depth) ⇒ void
abstract
Renders content with a renderer.
-
#to_s ⇒ String
Returns content as a string.
Constructor Details
#initialize(content) ⇒ void
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.
87 88 89 90 |
# File 'lib/sevgi/graphics/auxiliary/content.rb', line 87 def initialize(content) @content = Snapshot.capture(content) XML.validate(@content) end |
Class Method Details
.cdata(content) ⇒ Sevgi::Graphics::Content::CData
124 |
# File 'lib/sevgi/graphics/auxiliary/content.rb', line 124 def self.cdata(...) = CData.new(...) |
.contents(*args) ⇒ Array<Sevgi::Graphics::Content>
Wraps content arguments, encoding non-content values. Mutable non-content values are stringified by encoded content during construction, before XML text escaping.
132 |
# File 'lib/sevgi/graphics/auxiliary/content.rb', line 132 def self.contents(*args) = args.map { it.is_a?(Content) ? it : encoded(it) } |
.css(content) ⇒ Sevgi::Graphics::Content::CSS
141 |
# File 'lib/sevgi/graphics/auxiliary/content.rb', line 141 def self.css(...) = CSS.new(...) |
.encoded(content) ⇒ Sevgi::Graphics::Content::Encoded
150 |
# File 'lib/sevgi/graphics/auxiliary/content.rb', line 150 def self.encoded(...) = Encoded.new(...) |
.text(contents) ⇒ String
Joins content lines with newlines.
155 |
# File 'lib/sevgi/graphics/auxiliary/content.rb', line 155 def self.text(contents) = Array(contents).join("\n") |
.verbatim(content) ⇒ Sevgi::Graphics::Content::Verbatim
164 |
# File 'lib/sevgi/graphics/auxiliary/content.rb', line 164 def self.verbatim(...) = Verbatim.new(...) |
Instance Method Details
#content ⇒ Object
Returns a recursively independent, caller-owned payload snapshot.
79 |
# File 'lib/sevgi/graphics/auxiliary/content.rb', line 79 def content = Snapshot.copy(@content) |
#initialize_copy(original) ⇒ 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.
This method returns an undefined value.
Copies content payload ownership for duplicated element trees.
96 97 98 99 |
# File 'lib/sevgi/graphics/auxiliary/content.rb', line 96 def initialize_copy(original) @content = Snapshot.capture(original.content) super end |
#render(_renderer, _depth) ⇒ void
Subclasses implement content rendering.
This method returns an undefined value.
Renders content with a renderer.
107 |
# File 'lib/sevgi/graphics/auxiliary/content.rb', line 107 def render(_renderer, _depth) = PanicError.("#{self.class}#render must be implemented") |
#to_s ⇒ String
Returns content as a string.
111 |
# File 'lib/sevgi/graphics/auxiliary/content.rb', line 111 def to_s = XML.text(payload) |