Module: Sumi::SVG

Defined in:
toplevel/lib/sumi/svg.rb

Overview

Public SVG facade installed by require "sumi".

Capitalized methods are SVG DSL operations and constructors: SVG.Canvas creates a canvas, SVG.Document defines a document profile, SVG.Module builds a callable drawing module, and SVG.Paper registers a paper size. Double-colon names are Ruby constants and types, such as Canvas, Document, and Module. The global SVG(...) method builds a drawing. There is intentionally no stuttering SVG.SVG(...) form.

Lowercase constructors remain on Graphics for focused component use. Script execution belongs to execute and is not part of this SVG-domain facade.

Examples:

Compose a drawing through the facade

SVG.Paper 85, 55, :card
canvas = SVG.Canvas :card, margins: 4
profile = SVG.Document attributes: {viewBox: "0 0 85 55"}

drawing = SVG profile, canvas do
  rect width: 85, height: 55, rx: 3
end

drawing.Render

Distinguish an operation from its result type

canvas = SVG.Canvas width: 24, height: 24, unit: :px
canvas.is_a?(SVG::Canvas) #=> true

See Also:

Constant Summary collapse

Attributes =

SVG attribute collection and normalization API.

Graphics::Attributes
Canvas =

Canvas value type returned by Canvas.

Graphics::Canvas
Content =

Explicit SVG content serialization types.

Graphics::Content
Document =

Document profiles and document classes.

Graphics::Document
Element =

Base SVG/XML element type.

Graphics::Element
LintError =

Duplicate-id and structural lint failure.

Graphics::LintError
Margin =

CSS-like canvas margin value.

Graphics::Margin
Mixtures =

Graphics mixtures available for document composition.

Graphics::Mixtures
Module =

Contract for one callable drawing module.

Graphics::Module
Modules =

Recursive contract for namespaces of callable drawing modules.

Graphics::Modules
Paper =

Immutable paper-size value and profile registry.

Graphics::Paper
VERSION =

Current Sumi toolkit version.

Sumi::VERSION

Class Method Summary collapse

Class Method Details

.Canvas ⇒ Sumi::Graphics::Canvas

Builds a canvas from a paper profile or explicit dimensions.

Returns:

See Also:



62
# File 'toplevel/lib/sumi/svg.rb', line 62

def self.Canvas(...) = Sumi.Canvas(...)

.Decompile ⇒ Sumi::Derender::Node

Converts inline SVG/XML into an immutable Derender node.

Returns:

See Also:



67
# File 'toplevel/lib/sumi/svg.rb', line 67

def self.Decompile(...) = Sumi.Decompile(...)

.DecompileFile ⇒ Sumi::Derender::Node

Converts an SVG/XML file into an immutable Derender node.

Returns:

See Also:



72
# File 'toplevel/lib/sumi/svg.rb', line 72

def self.DecompileFile(...) = Sumi.DecompileFile(...)

.Derender ⇒ String

Converts inline SVG/XML into formatted Sumi DSL source.

Returns:

  • (String) —

    formatted Sumi DSL source

See Also:



77
# File 'toplevel/lib/sumi/svg.rb', line 77

def self.Derender(...) = Sumi.Derender(...)

.DerenderFile ⇒ String

Converts an SVG/XML file into formatted Sumi DSL source.

Returns:

  • (String) —

    formatted Sumi DSL source

See Also:



82
# File 'toplevel/lib/sumi/svg.rb', line 82

def self.DerenderFile(...) = Sumi.DerenderFile(...)

.Document ⇒ Class

Defines, validates, or looks up a document profile.

Returns:

  • (Class) —

    document class

See Also:



87
# File 'toplevel/lib/sumi/svg.rb', line 87

def self.Document(...) = Sumi.Document(...)

.Document! ⇒ Class

Defines or replaces a document profile.

Returns:

  • (Class) —

    document class

See Also:



92
# File 'toplevel/lib/sumi/svg.rb', line 92

def self.Document!(...) = Sumi.Document!(...)

.Evaluate ⇒ Sumi::Graphics::Element?

Includes an inline SVG/XML node under a graphics element.

Returns:

See Also:



97
# File 'toplevel/lib/sumi/svg.rb', line 97

def self.Evaluate(...) = Sumi.Evaluate(...)

.EvaluateChildren ⇒ Array<Sumi::Graphics::Element>

Includes only an inline SVG/XML node's children under a graphics element.

Returns:

See Also:



102
# File 'toplevel/lib/sumi/svg.rb', line 102

def self.EvaluateChildren(...) = Sumi.EvaluateChildren(...)

.EvaluateChildrenFile ⇒ Array<Sumi::Graphics::Element>

Includes only an SVG/XML file node's children under a graphics element.

Returns:

See Also:



107
# File 'toplevel/lib/sumi/svg.rb', line 107

def self.EvaluateChildrenFile(...) = Sumi.EvaluateChildrenFile(...)

.EvaluateFile ⇒ Sumi::Graphics::Element?

Includes an SVG/XML file node under a graphics element.

Returns:

See Also:



112
# File 'toplevel/lib/sumi/svg.rb', line 112

def self.EvaluateFile(...) = Sumi.EvaluateFile(...)

.Grid ⇒ Sumi::Sundries::Grid

Fits a drawable grid to a graphics canvas.

Returns:

See Also:



117
# File 'toplevel/lib/sumi/svg.rb', line 117

def self.Grid(...) = Sumi.Grid(...)

.Load ⇒ Array<String>

Loads nested .sumi files through the active executor scope.

Returns:

  • (Array<String>) —

    requested file names

See Also:



127
# File 'toplevel/lib/sumi/svg.rb', line 127

def self.Load(...) = Sumi.Load(...)

.Mixin ⇒ Module?

Extends a document profile with a named or anonymous graphics mixture.

Returns:

  • (Module, nil) —

    anonymous mixture when supplied, otherwise nil

See Also:



132
# File 'toplevel/lib/sumi/svg.rb', line 132

def self.Mixin(...) = Sumi.Mixin(...)

.Module {|mod| ... } ⇒ Module

Builds an anonymous callable drawing module. The callable contract is installed before the optional definition runs, so base and drawing-method tracking are available throughout the block. The definition keeps its ordinary Ruby lexical constant scope.

Examples:

Build a callable drawing module

label = SVG.Module do
  base { circle r: 8, fill: "seagreen" }
  def call(value) = text value
end

SVG(:minimal) { Call label, "OK" }

Yields:

  • (mod) —

    optionally defines the callable module

Yield Parameters:

  • mod (Module) —

    module being defined

Yield Returns:

  • (Object) —

    ignored definition result

Returns:

See Also:



149
150
151
152
153
154
# File 'toplevel/lib/sumi/svg.rb', line 149

def self.Module(&definition)
  mod = ::Module.new
  mod.extend(Graphics::Module)
  mod.module_eval(&definition) if definition
  mod
end

.Paper ⇒ Symbol, String

Defines or validates a named paper profile.

Returns:

  • (Symbol, String) —

    original paper profile name

See Also:



159
# File 'toplevel/lib/sumi/svg.rb', line 159

def self.Paper(...) = Sumi.Paper(...)

.Paper! ⇒ Symbol, String

Defines or overwrites a named paper profile.

Returns:

  • (Symbol, String) —

    original paper profile name

See Also:



164
# File 'toplevel/lib/sumi/svg.rb', line 164

def self.Paper!(...) = Sumi.Paper!(...)

.Ruler ⇒ Sumi::Sundries::Ruler

Fits major and minor intervals into a span.

Returns:

See Also:



122
# File 'toplevel/lib/sumi/svg.rb', line 122

def self.Ruler(...) = Sumi.Ruler(...)