Module: Sevgi::Graphics::Mixtures::Underscore

Defined in:
lib/sevgi/graphics/mixtures/underscore.rb

Overview

DSL helpers for floating text, comments, and inherited non-rendering context.

Instance Method Summary collapse

Instance Method Details

#_(*contents) ⇒ Sevgi::Graphics::Element

Creates a floating content element.

Parameters:

  • contents (Array<Object>)

    text or content objects

Returns:



14
15
16
# File 'lib/sevgi/graphics/mixtures/underscore.rb', line 14

def _(*contents)
  Element(:_, *contents)
end

#AncestralHash

Merges -context metadata from the document root, ancestors, and this element. Only the direct root-to-self ancestor chain participates; sibling subtrees are ignored. When the same key is present on multiple chain elements, the nearest element to the receiver wins. Context remains available in memory but is omitted from rendered SVG. It is unrelated to the _: XML namespace syntax preserved by Derender.

Examples:

Inherit drawing context without rendering it

Sevgi::Graphics.SVG "-context": {tone: "tomato"} do
  rect fill: Ancestral()[:tone]
end

Returns:

  • (Hash)

    merged context



41
42
43
44
45
46
47
48
# File 'lib/sevgi/graphics/mixtures/underscore.rb', line 41

def Ancestral
  chain = []
  TraverseUp { |element| chain.unshift(element) }

  {}.tap do |result|
    chain.each { |element| result.merge!(element[CONTEXT]) if element.has?(CONTEXT) }
  end
end

#Comment(comment) ⇒ Sevgi::Graphics::Element

Adds an XML comment.

Parameters:

  • comment (Object)

    comment text

Returns:

Raises:

  • (Sevgi::ArgumentError)

    when comment cannot be stringified as valid XML or would form malformed markup



22
23
24
25
26
27
28
29
# File 'lib/sevgi/graphics/mixtures/underscore.rb', line 22

def Comment(comment)
  comment = XML.text(comment, context: "XML comment")

  ArgumentError.("XML comment must not contain '--'") if comment.include?("--")
  ArgumentError.("XML comment must not end with '-'") if comment.end_with?("-")

  _(Content.verbatim("<!-- #{comment} -->"))
end