Module: Sumi::Graphics::Mixtures::Render

Defined in:
graphics/lib/sumi/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 can 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. Elements with the same name in a foreign 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:

  • (Sumi::ArgumentError) —

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



214
# File 'graphics/lib/sumi/graphics/mixtures/render.rb', line 214

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

Sumi::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:



229
230
231
232
233
234
235
# File 'graphics/lib/sumi/graphics/mixtures/render.rb', line 229

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")
  Options.validate(**options)
  children.map { Renderer.fragment(it, **options) }.join(separator)
end