Module: Sevgi::Graphics::Mixtures::Symbols

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

Overview

DSL helpers for expanding callable modules into SVG symbols.

Instance Method Summary collapse

Instance Method Details

#Symbols(mod, *args, attributes: {}, ids: nil, **kwargs) { ... } ⇒ Sevgi::Graphics::Element

Renders module callables as symbols under defs. Named modules default the defs id to their final constant name; anonymous modules omit the id unless supplied. Base blocks run once in the defs element before symbols are created. Positional arguments, keyword arguments, and the block are forwarded to each callable.

Examples:

Expand named drawing methods into reusable symbols

icons = Module.new do
  extend Sevgi::Graphics::Module
  def dot = circle r: 2
  def tick = path d: "M 0 2 L 2 4 L 6 0"
end
Sevgi::Graphics.SVG(:minimal) { Symbols icons }

Parameters:

  • mod (Module)

    module extended with Sevgi::Graphics::Module

  • args (Array<Object>)

    callable arguments

  • attributes (Hash) (defaults to: {})

    defs attributes; String and Symbol names are normalized and must not collide

  • ids (#call, nil) (defaults to: nil)

    optional callable mapping each method name to a symbol id

  • kwargs (Hash)

    callable keyword arguments

Yields:

  • forwarded to each callable

Yield Returns:

  • (Object)

    callable-defined block result

Returns:

Raises:

  • (Sevgi::ArgumentError)

    when mod is not a callable drawing module, attributes is not a Hash, or ids is not callable



89
90
91
# File 'lib/sevgi/graphics/mixtures/symbols.rb', line 89

def Symbols(mod, *args, attributes: {}, ids: nil, **kwargs, &block)
  Expansion.new(self, mod).call(*args, attributes:, ids:, **kwargs, &block)
end