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
-
#_(*contents) ⇒ Sevgi::Graphics::Element
Creates a floating content element.
-
#Ancestral ⇒ Hash
Merges internal attributes from the document root, ancestors, and this element.
-
#Comment(comment) ⇒ Sevgi::Graphics::Element
Adds an XML comment.
Instance Method Details
#_(*contents) ⇒ Sevgi::Graphics::Element
Creates a floating content element.
11 12 13 |
# File 'lib/sevgi/graphics/mixtures/underscore.rb', line 11 def _(*contents) Element(:_, *contents) end |
#Ancestral ⇒ Hash
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.
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.
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 |