Module: Sevgi::Toplevel

Included in:
Sevgi
Defined in:
lib/sevgi/toplevel.rb,
lib/sevgi/toplevel/derender.rb,
lib/sevgi/toplevel/executor.rb,
lib/sevgi/toplevel/function.rb,
lib/sevgi/toplevel/geometry.rb,
lib/sevgi/toplevel/graphics.rb,
lib/sevgi/toplevel/sundries.rb

Overview

Shared implementation for the full Sevgi top-level DSL.

This module is installed by include Sevgi or extend Sevgi; it should not normally be included directly.

See Also:

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.constantsObject (readonly)

Returns the value of attribute constants.



14
15
16
# File 'lib/sevgi/toplevel.rb', line 14

def constants
  @constants
end

Class Method Details

.extended(base) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Note:

Constants are promoted only to modules/classes. Extending an ordinary object installs methods without writing constants to Object.

This method returns an undefined value.

Injects promoted constants when the DSL is extended by a module.

Parameters:

  • base (Object)

    the object or module receiving the DSL methods



50
51
52
53
# File 'lib/sevgi/toplevel.rb', line 50

def self.extended(base)
  super
  inject(base)
end

.included(base) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Injects promoted constants when the DSL is included in a module or class.

Parameters:

  • base (Module)

    the class or module receiving promoted constants



39
40
41
42
# File 'lib/sevgi/toplevel.rb', line 39

def self.included(base)
  super
  inject(base)
end

Instance Method Details

#Decompile(file, id = nil) ⇒ Sevgi::Derender::Node

Converts an SVG/XML file into a derender node.

Parameters:

  • file (String)

    path to the source SVG/XML file

  • id (String, nil) (defaults to: nil)

    optional SVG id selecting a node inside the source

Returns:

  • (Sevgi::Derender::Node)

    selected node in the derender tree

Raises:

  • (Sevgi::ArgumentError)

    when the file cannot be found or the id is absent

See Also:

  • Derender.decompile_file


13
# File 'lib/sevgi/toplevel/derender.rb', line 13

def Decompile(file, id = nil) = Derender.decompile_file(file, id:)

#Derender(file, id = nil) ⇒ String

Converts an SVG/XML file into Sevgi DSL Ruby source.

Parameters:

  • file (String)

    path to the source SVG/XML file

  • id (String, nil) (defaults to: nil)

    optional SVG id selecting a node inside the source

Returns:

  • (String)

    formatted Sevgi DSL source

Raises:

  • (Sevgi::ArgumentError)

    when the file cannot be found or the id is absent

See Also:

  • Derender.derender_file


21
# File 'lib/sevgi/toplevel/derender.rb', line 21

def Derender(file, id = nil) = Derender.derender_file(file, id:)

#Grid(canvas, unit:, multiple:) ⇒ Sevgi::Sundries::Grid

Builds a drawable grid from a graphics canvas.

Parameters:

  • canvas (Sevgi::Graphics::Canvas)

    canvas defining page size and margins

  • unit (Numeric)

    minor grid unit

  • multiple (Integer)

    number of minor units in each major interval

Returns:

  • (Sevgi::Sundries::Grid)

    grid fitted to the canvas

Raises:

  • (Sevgi::ArgumentError)

    when canvas is not a graphics canvas

  • (Sevgi::ArgumentError)

    when unit is not a finite positive number

  • (Sevgi::ArgumentError)

    when multiple is not a positive integer

  • (Sevgi::ArgumentError)

    when canvas dimensions, margins, and grid intervals cannot fit



16
17
18
19
20
21
22
23
# File 'lib/sevgi/toplevel/sundries.rb', line 16

def Grid(canvas, unit:, multiple:)
  ArgumentError.("Must be a Canvas: #{canvas}") unless canvas.is_a?(Graphics::Canvas)

  Sundries::Grid[
    Sundries::Ruler.new(brut: canvas.width, unit:, multiple:, margin: canvas.left),
    Sundries::Ruler.new(brut: canvas.height, unit:, multiple:, margin: canvas.top)
  ]
end

#Load(*files) ⇒ Array<String>

Note:

Load resolves against the active executor scope in the current fiber.

Loads one or more Sevgi files relative to the caller's source file.

Parameters:

  • files (Array<String>)

    Sevgi script files to locate and execute

Returns:

  • (Array<String>)

    the input file list

Raises:

  • (Sevgi::PanicError)

    when called without an active executor scope

  • (Sevgi::Error)

    when a file cannot be located



35
36
37
38
39
40
41
42
43
# File 'lib/sevgi/toplevel/executor.rb', line 35

def Load(*files)
  start = ::File.dirname(caller_locations(1..1).first.path)

  files.each do |file|
    location = F.locate(file, start, exclude: start)

    ::Sevgi::Executor.load(location.file)
  end
end

#Mixin(mod, document = Sevgi::Graphics::Document::Base) { ... } ⇒ void #Mixin(document = Sevgi::Graphics::Document::Base) { ... } ⇒ Module

Overloads:

  • #Mixin(mod, document = Sevgi::Graphics::Document::Base) { ... } ⇒ void

    This method returns an undefined value.

    Adds graphics mixture methods to a document class.

    Parameters:

    • mod (Symbol, String)

      named mixture to mix into the document

    • document (Class) (defaults to: Sevgi::Graphics::Document::Base)

      document class receiving the mixture

    Yields:

    • optional anonymous mixture module body

    Yield Returns:

    • (void)

    Raises:

    • (NameError)

      when a named mixture cannot be resolved

    See Also:

    • Graphics::Mixtures.mixin
  • #Mixin(document = Sevgi::Graphics::Document::Base) { ... } ⇒ Module

    Adds an anonymous graphics mixture to a document class.

    Parameters:

    • document (Class) (defaults to: Sevgi::Graphics::Document::Base)

      document class receiving the mixture

    Yields:

    • anonymous mixture module body

    Yield Returns:

    • (void)

    Returns:

    • (Module)

      anonymous mixture

    Raises:

    • (Sevgi::ArgumentError)

      when no named mixture or block is given

    See Also:

    • Graphics::Mixtures.mixin


24
# File 'lib/sevgi/toplevel/graphics.rb', line 24

def Mixin(...) = Graphics::Mixtures.mixin(...)

#Paper(width, height, name = :custom, unit: "mm") ⇒ Symbol

Defines or validates a named paper profile for DSL use.

Parameters:

  • width (Numeric)

    paper width

  • height (Numeric)

    paper height

  • name (Symbol) (defaults to: :custom)

    paper profile name

  • unit (String, Symbol) (defaults to: "mm")

    size unit

Returns:

  • (Symbol)

    the paper profile name

Raises:

  • (Sevgi::ArgumentError)

    when the profile is invalid or an existing profile differs

See Also:

  • Graphics#paper


35
# File 'lib/sevgi/toplevel/graphics.rb', line 35

def Paper(...) = Graphics.paper(...)

#Paper!(width, height, name = :custom, unit: "mm") ⇒ Symbol

Defines or overwrites a named paper profile for DSL use.

Parameters:

  • width (Numeric)

    paper width

  • height (Numeric)

    paper height

  • name (Symbol) (defaults to: :custom)

    paper profile name

  • unit (String, Symbol) (defaults to: "mm")

    size unit

Returns:

  • (Symbol)

    the paper profile name

Raises:

  • (Sevgi::ArgumentError)

    when the profile is invalid or the paper name is reserved

See Also:

  • Graphics#paper!


46
# File 'lib/sevgi/toplevel/graphics.rb', line 46

def Paper!(...) = Graphics.paper!(...)