Module: Sumi::Graphics::Mixtures::Symbols

Defined in:
graphics/lib/sumi/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) { ... } ⇒ Sumi::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 Sumi::Graphics::Module
  def dot = circle r: 2
  def tick = path d: "M 0 2 L 2 4 L 6 0"
end
Sumi::Graphics.SVG(:minimal) { Symbols icons }

Parameters:

  • mod (Module) —

    module extended with Sumi::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:

  • (Sumi::ArgumentError) —

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



88
89
90
# File 'graphics/lib/sumi/graphics/mixtures/symbols.rb', line 88

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