Module: Sumi::Toplevel
- Included in:
- Sumi
- Defined in:
- toplevel/lib/sumi/toplevel.rb,
toplevel/lib/sumi/toplevel/derender.rb,
toplevel/lib/sumi/toplevel/executor.rb,
toplevel/lib/sumi/toplevel/function.rb,
toplevel/lib/sumi/toplevel/geometry.rb,
toplevel/lib/sumi/toplevel/graphics.rb,
toplevel/lib/sumi/toplevel/sundries.rb
Overview
Shared implementation for the full Sumi top-level DSL.
This module is installed by include Sumi or extend Sumi. Consumers do not
normally be included directly.
Instance Method Summary collapse
- #Canvas ⇒ Object
-
#Decompile(content, id: nil, omit: nil) ⇒ Sumi::Derender::Node
Converts inline SVG/XML content into a derender node.
-
#DecompileFile(file, id: nil, omit: nil) ⇒ Sumi::Derender::Node
Converts an SVG/XML file into a derender node.
-
#Derender(content, id: nil, omit: nil) ⇒ String
Converts inline SVG/XML content into Sumi DSL Ruby source.
-
#DerenderFile(file, id: nil, omit: nil) ⇒ String
Converts an SVG/XML file into Sumi DSL Ruby source.
-
#Document ⇒ Class
Document class.
-
#Document!(name, preambles: [], attributes: {}) ⇒ Class
Defines or replaces a document profile.
-
#Evaluate(content, element, id: nil, omit: nil) ⇒ Sumi::Graphics::Element?
Evaluates inline SVG/XML content under a graphics element, including the selected node.
-
#EvaluateChildren(content, element, id: nil, omit: nil) ⇒ Array<Sumi::Graphics::Element>
Evaluates only the selected node's children from inline SVG/XML content under a graphics element.
-
#EvaluateChildrenFile(file, element, id: nil, omit: nil) ⇒ Array<Sumi::Graphics::Element>
Evaluates only the selected node's children from an SVG/XML file under a graphics element.
-
#EvaluateFile(file, element, id: nil, omit: nil) ⇒ Sumi::Graphics::Element?
Evaluates an SVG/XML file under a graphics element, including the selected node.
-
#Grid(canvas, unit:, multiple:) ⇒ Sumi::Sundries::Grid
Builds a drawable grid fitted inside a graphics canvas.
-
#Load(*files) ⇒ Array<String>
Loads one or more Sumi files relative to the caller's source file.
- #Mixin ⇒ Object
-
#Paper(width, height, name = :custom, unit: "mm") ⇒ Symbol, String
Defines or validates a named paper profile for DSL use.
-
#Paper!(width, height, name = :custom, unit: "mm") ⇒ Symbol, String
Defines or overwrites a named paper profile for DSL use.
-
#Ruler(brut:, unit:, multiple:, margins: [0.0]) ⇒ Sumi::Sundries::Ruler
Fits major and minor intervals into a span without drawing SVG elements.
-
#SVG(document = :default, canvas = Undefined, **attributes) { ... } ⇒ Sumi::Graphics::Document::Proto
Builds an SVG document through the full Sumi top-level DSL.
Instance Method Details
#Canvas(paper, **overrides) ⇒ Sumi::Graphics::Canvas #Canvas(width:, height:, unit: "mm", name: :custom, margins: []) ⇒ Sumi::Graphics::Canvas
26 |
# File 'toplevel/lib/sumi/toplevel/graphics.rb', line 26 def Canvas(...) = Graphics.canvas(...) |
#Decompile(content, id: nil, omit: nil) ⇒ Sumi::Derender::Node
Converts inline SVG/XML content into a derender node.
16 |
# File 'toplevel/lib/sumi/toplevel/derender.rb', line 16 def Decompile(content, id: nil, omit: nil) = Derender.decompile(content, id:, omit:) |
#DecompileFile(file, id: nil, omit: nil) ⇒ Sumi::Derender::Node
Converts an SVG/XML file into a derender node.
28 |
# File 'toplevel/lib/sumi/toplevel/derender.rb', line 28 def DecompileFile(file, id: nil, omit: nil) = Derender.decompile_file(file, id:, omit:) |
#Derender(content, id: nil, omit: nil) ⇒ String
Converts inline SVG/XML content into Sumi DSL Ruby source. The returned String is ordinary Ruby source. Review and integrate it statically rather than using Ruby's raw dynamic evaluation methods.
41 |
# File 'toplevel/lib/sumi/toplevel/derender.rb', line 41 def Derender(content, id: nil, omit: nil) = Derender.derender(content, id:, omit:) |
#DerenderFile(file, id: nil, omit: nil) ⇒ String
Converts an SVG/XML file into Sumi DSL Ruby source. The returned String is ordinary Ruby source. Review and integrate it statically rather than using Ruby's raw dynamic evaluation methods.
55 |
# File 'toplevel/lib/sumi/toplevel/derender.rb', line 55 def DerenderFile(file, id: nil, omit: nil) = Derender.derender_file(file, id:, omit:) |
#Document(name) ⇒ Class #Document(name, preambles: Undefined, attributes: Undefined) ⇒ Class #Document(preambles: Undefined, attributes: Undefined) ⇒ Class
Returns document class.
52 |
# File 'toplevel/lib/sumi/toplevel/graphics.rb', line 52 def Document(...) = Graphics.document(...) |
#Document!(name, preambles: [], attributes: {}) ⇒ Class
Defines or replaces a document profile.
62 63 64 |
# File 'toplevel/lib/sumi/toplevel/graphics.rb', line 62 def Document!(name, preambles: [], attributes: {}) Graphics.document!(name, preambles:, attributes:) end |
#Evaluate(content, element, id: nil, omit: nil) ⇒ Sumi::Graphics::Element?
Evaluates inline SVG/XML content under a graphics element, including the selected node.
67 |
# File 'toplevel/lib/sumi/toplevel/derender.rb', line 67 def Evaluate(content, element, id: nil, omit: nil) = Derender.evaluate(content, element, id:, omit:) |
#EvaluateChildren(content, element, id: nil, omit: nil) ⇒ Array<Sumi::Graphics::Element>
Evaluates only the selected node's children from inline SVG/XML content under a graphics element.
79 80 81 |
# File 'toplevel/lib/sumi/toplevel/derender.rb', line 79 def EvaluateChildren(content, element, id: nil, omit: nil) Derender.evaluate_children(content, element, id:, omit:) end |
#EvaluateChildrenFile(file, element, id: nil, omit: nil) ⇒ Array<Sumi::Graphics::Element>
Evaluates only the selected node's children from an SVG/XML file under a graphics element.
94 95 96 |
# File 'toplevel/lib/sumi/toplevel/derender.rb', line 94 def EvaluateChildrenFile(file, element, id: nil, omit: nil) Derender.evaluate_children_file(file, element, id:, omit:) end |
#EvaluateFile(file, element, id: nil, omit: nil) ⇒ Sumi::Graphics::Element?
Evaluates an SVG/XML file under a graphics element, including the selected node.
109 |
# File 'toplevel/lib/sumi/toplevel/derender.rb', line 109 def EvaluateFile(file, element, id: nil, omit: nil) = Derender.evaluate_file(file, element, id:, omit:) |
#Grid(canvas, unit:, multiple:) ⇒ Sumi::Sundries::Grid
Builds a drawable grid fitted inside a graphics canvas.
The canvas margins are minimum clearances. Any span left after fitting
whole major intervals is shared equally between the opposite margins, so
their requested difference is preserved. The returned grid starts at
(0, 0). Sundries::Grid#canvas exposes the fitted page margins.
34 35 36 37 38 39 40 41 42 |
# File 'toplevel/lib/sumi/toplevel/sundries.rb', line 34 def Grid(canvas, unit:, multiple:) ArgumentError.("Must be a Canvas: #{canvas}") unless canvas.is_a?(Graphics::Canvas) Sundries::Grid.new( x: Sundries::Ruler.new(brut: canvas.width, unit:, multiple:, margins: [canvas.left, canvas.right]), y: Sundries::Ruler.new(brut: canvas.height, unit:, multiple:, margins: [canvas.top, canvas.bottom]), canvas: ) end |
#Load(*files) ⇒ Array<String>
Load resolves against the active executor scope in the current fiber.
Ordinary library code uses Ruby require. Load is available only during Sumi script execution.
Loads one or more Sumi files relative to the caller's source file.
93 94 95 96 97 98 99 100 101 |
# File 'toplevel/lib/sumi/toplevel/executor.rb', line 93 def Load(*files) start = ::Sumi.__send__(:load_directory, caller_locations(1)) files.each do |file| location = F.locate(file, start) ::Sumi::Executor.__send__(:load, location.file) end end |
#Mixin(mod, document = Sumi::Graphics::Document::Base) ⇒ nil #Mixin(mod, document = Sumi::Graphics::Document::Base) { ... } ⇒ Module #Mixin(document = Sumi::Graphics::Document::Base) { ... } ⇒ Module
109 |
# File 'toplevel/lib/sumi/toplevel/graphics.rb', line 109 def Mixin(...) = Graphics::Mixtures.mixin(...) |
#Paper(width, height, name = :custom, unit: "mm") ⇒ Symbol, String
121 |
# File 'toplevel/lib/sumi/toplevel/graphics.rb', line 121 def Paper(...) = Graphics.paper(...) |
#Paper!(width, height, name = :custom, unit: "mm") ⇒ Symbol, String
133 |
# File 'toplevel/lib/sumi/toplevel/graphics.rb', line 133 def Paper!(...) = Graphics.paper!(...) |
#Ruler(brut:, unit:, multiple:, margins: [0.0]) ⇒ Sumi::Sundries::Ruler
Fits major and minor intervals into a span without drawing SVG elements.
16 |
# File 'toplevel/lib/sumi/toplevel/sundries.rb', line 16 def Ruler(...) = Sundries::Ruler.new(...) |
#SVG(document = :default, canvas = Undefined, **attributes) { ... } ⇒ Sumi::Graphics::Document::Proto
Builds an SVG document through the full Sumi top-level DSL.
78 79 80 |
# File 'toplevel/lib/sumi/toplevel/graphics.rb', line 78 def SVG(document = :default, canvas = Undefined, **attributes, &block) Graphics.SVG(document, canvas, **attributes, &block) end |