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:

Defined Under Namespace

Modules: Function

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.

This method returns an undefined value.

Injects promoted constants when the DSL is extended.

Parameters:

  • base (Object)

    the object or module receiving promoted constants



47
48
49
50
# File 'lib/sevgi/toplevel.rb', line 47

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.

Parameters:

  • base (Module)

    the class or module receiving promoted constants



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

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 (Numeric)

    number of minor units in each major interval

Returns:

  • (Sevgi::Sundries::Grid)

    grid fitted to the canvas

Raises:

  • (Sevgi::ArgumentError)

    when canvas, unit, multiple, or fitting span is invalid



13
14
15
16
17
18
19
20
# File 'lib/sevgi/toplevel/sundries.rb', line 13

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>

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



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

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!(...)