Class: Sumi::Graphics::Content Abstract
- Inherits:
-
Object
- Object
- Sumi::Graphics::Content
- Defined in:
- graphics/lib/sumi/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) ⇒ Sumi::Graphics::Content::CData
Builds CDATA content.
-
.css(content) ⇒ Sumi::Graphics::Content::CSS
Builds CSS content.
-
.encoded(content) ⇒ Sumi::Graphics::Content::Encoded
Builds XML text-encoded content.
-
.verbatim(content) ⇒ Sumi::Graphics::Content::Verbatim
Builds verbatim content.
Instance Method Summary collapse
-
#content ⇒ Object
Returns a recursively independent, caller-owned payload snapshot.
-
#empty? ⇒ Boolean
Reports whether the captured payload is empty.
-
#eql?(other) ⇒ Boolean
(also: #==)
Reports strict content equality by concrete class and captured payload.
-
#hash ⇒ Integer
Returns a hash compatible with strict equality.
-
#render(_output, _depth) ⇒ Object
abstract
Appends this content's serialized XML lines to rendering output.
-
#to_s ⇒ String
Returns content as a string.
Class Method Details
.cdata(content) ⇒ Sumi::Graphics::Content::CData
44 |
# File 'graphics/lib/sumi/graphics/auxiliary/content.rb', line 44 def self.cdata(...) = CData.send(:new, ...) |
.css(content) ⇒ Sumi::Graphics::Content::CSS
53 |
# File 'graphics/lib/sumi/graphics/auxiliary/content.rb', line 53 def self.css(...) = CSS.send(:new, ...) |
.encoded(content) ⇒ Sumi::Graphics::Content::Encoded
62 |
# File 'graphics/lib/sumi/graphics/auxiliary/content.rb', line 62 def self.encoded(...) = Encoded.send(:new, ...) |
.verbatim(content) ⇒ Sumi::Graphics::Content::Verbatim
71 |
# File 'graphics/lib/sumi/graphics/auxiliary/content.rb', line 71 def self.verbatim(...) = Verbatim.send(:new, ...) |
Instance Method Details
#content ⇒ Object
Returns a recursively independent, caller-owned payload snapshot.
75 |
# File 'graphics/lib/sumi/graphics/auxiliary/content.rb', line 75 def content = Snapshot.copy(@content) |
#empty? ⇒ Boolean
Reports whether the captured payload is empty.
91 |
# File 'graphics/lib/sumi/graphics/auxiliary/content.rb', line 91 def empty? = payload.respond_to?(:empty?) ? payload.empty? : to_s.empty? |
#eql?(other) ⇒ Boolean Also known as: ==
Reports strict content equality by concrete class and captured payload.
96 |
# File 'graphics/lib/sumi/graphics/auxiliary/content.rb', line 96 def eql?(other) = self.class == other.class && payload.eql?(other.send(:payload)) |
#hash ⇒ Integer
Returns a hash compatible with strict equality.
100 |
# File 'graphics/lib/sumi/graphics/auxiliary/content.rb', line 100 def hash = [self.class, payload].hash |
#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.
113 |
# File 'graphics/lib/sumi/graphics/auxiliary/content.rb', line 113 def render(_output, _depth) = PanicError.("#{self.class}#render must be implemented") |
#to_s ⇒ String
Returns content as a string.
117 |
# File 'graphics/lib/sumi/graphics/auxiliary/content.rb', line 117 def to_s = XML.text(payload) |