Module: Sevgi::Graphics::Mixtures::Render

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

Overview

DSL helpers for rendering SVG documents and children.

Instance Method Summary collapse

Instance Method Details

#Render(**options) ⇒ String

Renders this element as SVG source. Elements with inline text content may also contain inline children such as tspan; the renderer keeps those descendants in the same text line. Whitespace inside content objects is preserved as given, and encoded content is XML-escaped unless a verbatim content object is used. SVG style elements use block content; same-named elements under a foreign default namespace retain ordinary inline text formatting.

Examples:

Keep every attribute on the element's opening line

SVG(:minimal) { rect id: "card", width: 80, height: 40 }.Render(style: :inline)

Parameters:

  • options (Hash)

    renderer options

Options Hash (**options):

  • :indent (String) — default: " "

    XML-whitespace indentation unit

  • :linelength (Integer) — default: 140

    non-negative line length that switches hybrid attributes to block style

  • :style (Symbol) — default: :hybrid

    attribute layout: :hybrid, :inline, or :block

Returns:

  • (String)

    SVG source

Raises:

  • (Sevgi::ArgumentError)

    when options, preambles, names, attributes, or content are invalid XML



377
# File 'lib/sevgi/graphics/mixtures/render.rb', line 377

def Render(**) = Renderer.(self, **)

#RenderChildren(separator = "\n\n", **options) ⇒ String

Renders only this element's children. Child render output omits document preambles and preserves each child's text whitespace and inline mixed-content formatting.

Examples:

Render child fragments with block-style attributes

Sevgi::Graphics.SVG(:minimal) { rect id: "one" }.RenderChildren(style: :block, indent: "\t")

Parameters:

  • separator (String) (defaults to: "\n\n")

    separator between child documents

  • options (Hash)

    renderer options applied to every child fragment

Options Hash (**options):

  • :indent (String) — default: " "

    XML-whitespace indentation unit

  • :linelength (Integer) — default: 140

    non-negative line length that switches hybrid attributes to block style

  • :style (Symbol) — default: :hybrid

    attribute layout: :hybrid, :inline, or :block

Returns:

  • (String)

    rendered child fragments

Raises:

  • (Sevgi::ArgumentError)

    when separator, options, or rendered child data is invalid



392
393
394
395
396
397
398
# File 'lib/sevgi/graphics/mixtures/render.rb', line 392

def RenderChildren(separator = "\n\n", **options)
  ArgumentError.("SVG fragment separator must be a String") unless separator.is_a?(::String)

  separator = XML.text(separator, context: "SVG fragment separator")
  Renderer.send(:validate, **options)
  children.map { Renderer.fragment(it, **options) }.join(separator)
end