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

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

Overview

DSL helpers for floating text, comments, and inherited internal attributes.

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:



11
12
13
# File 'lib/sevgi/graphics/mixtures/underscore.rb', line 11

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

#AncestralHash

Merges internal attributes 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.

Returns:

  • (Hash)

    merged internal attributes



32
33
34
35
36
37
38
39
# File 'lib/sevgi/graphics/mixtures/underscore.rb', line 32

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

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

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

Adds an XML comment.

Parameters:

  • comment (Object)

    comment text

Returns:

Raises:

  • (Sevgi::ArgumentError)

    when comment text would produce malformed XML



19
20
21
22
23
24
25
26
# File 'lib/sevgi/graphics/mixtures/underscore.rb', line 19

def Comment(comment)
  comment = comment.to_s

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

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