_
Add floating encoded text or content at the current point in the tree.
_ "© 2026 Acme Studio"
The DSL has two related vocabularies. Lowercase calls such as rect, circle, and linearGradient are SVG element
names. The full sumi gem recognizes standard elements. It checks their attributes, content, and nesting before
writing the document.
Sumi's own drawing words usually begin with a capital letter, which keeps operations such as Tile, Rotate, and
Include visually distinct from SVG. A few deliberate lowercase words, including css, layer, and base, appear
here too. Ordinary Ruby methods and exhaustive signatures belong in the API reference.
Use SVG element names directly and nest containers naturally:
SVG :minimal do
g id: "badge" do
circle cx: 12, cy: 12, r: 10
text "S", x: 12, y: 16, "text-anchor": "middle"
end
end.Out
Use Element for foreign XML, qualified names, or a name that collides with Ruby. See
Documents for the validation lifecycle and the
MDN SVG element reference for the standard
element vocabulary.
An attribute name that starts with - stores internal element data. Sumi keeps the value in memory, but does not write
it to SVG. Use -context with Ancestral. Duplicate and
Disidentify use -id to retain a source id without rendering it.
Some words appear in more than one group. Include, for example, belongs to both composition and round trip. Grid
belongs to layout and script tools.
Choose a document profile and control when Sumi prepares or renders it.
Build an SVG tree, then move, group, or reuse its branches.
Query the current element and move through its parents or children.
Draw common shape and line patterns without hand-writing path data.
Attach SVG transforms without assembling transform strings.
Arrange repeated work with alignment, tiling, grids, and pages.
Convert SVG/XML, load files, and reuse callable modules.
Validate SVG structure and inspect element identity before output.
Render, print, save, and export drawings.
Add Inkscape pages and metadata, including RDF licenses.
Work with the top-level commands available in .sumi scripts.
_ · A · B · C · D · E · F · G · H · I · L · M · N · O · P · R · S · T · V · W
_
Add floating encoded text or content at the current point in the tree.
_ "© 2026 Acme Studio"
Adopt
Move an existing subtree under a new parent.
toolbar = g id: "toolbar"
export = text "Export", x: 8, y: 16
export.Adopt toolbar
AdoptFirst
Move an existing subtree to the first position under a parent.
legend = g { text "Online", x: 12, y: 4 }
status = circle r: 4, fill: "seagreen"
status.AdoptFirst legend
Align
Center an element by comparing an inner and outer box.
label = Sumi::Geometry::Rect[32, 12]
card = Sumi::Geometry::Rect[120, 48]
title = text "BOARDING", x: 0, y: 10
title.Align :center, inner: label, outer: card
See geometry alignment.
Ancestral
Read merged -context data from the current element and its ancestors. The leading - keeps this data in memory and out of SVG output. The nearest element wins when keys repeat.
g "-context": {radius: 10, tone: "tomato"} do
g "-context": {tone: "gold"} do
context = self.Ancestral # internal, not rendered
circle r: context[:radius], fill: context[:tone]
end
end
Append
Move existing elements to the end of a new parent's children.
button = g id: "checkout"
icon = circle cx: 8, cy: 8, r: 6, fill: "seagreen"
label = text "Pay now", x: 20, y: 12
button.Append icon, label
ArcBy
Draw an SVG elliptical arc to a relative endpoint.
ArcBy x: 4, y: 12, dx: 20, dy: 0, rx: 10, ry: 6, sweep: true, fill: "none", stroke: "black"
ArcTo
Draw an SVG elliptical arc between absolute endpoints.
ArcTo x1: 4, y1: 12, x2: 24, y2: 12, rx: 10, ry: 6, sweep: true, fill: "none", stroke: "black"
base
Register shared drawing steps that run before a callable module's public methods.
Build an anonymous callable with SVG.Module { ... }. For an existing or explicitly
declared module, use extend SVG::Module. Use extend SVG::Modules for
an owned module tree.
Public instance methods are drawing steps; private and protected methods are helpers. Each invocation uses a fresh callable receiver rather than the document object.
status = SVG.Module do
base { circle r: 8, fill: "seagreen" }
def call = path d: "M -4 0 L -1 3 L 5 -4", fill: "none", stroke: "white"
end
SVG :minimal do
Call status
end.Render
Call
Run a configured Ruby module as a drawing step on the current element.
Build an anonymous callable with SVG.Module { ... }. For an existing or explicitly
declared module, use extend SVG::Module. Use extend SVG::Modules for
an owned module tree.
Public instance methods are drawing steps; private and protected methods are helpers. Each invocation uses a fresh callable receiver rather than the document object.
price = SVG.Module do
def call(value) = text "$#{value}", x: 8, y: 16
end
SVG :minimal do
Call price, 48
end.Render
See callable modules.
Canvas
Build a canvas from a paper profile or explicit dimensions and margins.
canvas = Canvas width: 80, height: 50, margins: 5
SVG :minimal, canvas do
rect width: canvas.inner.width, height: canvas.inner.height
end.Render
CData
Join the element's direct text values for SVG validation.
label = text "Total", "$48"
label.CData # => "Total\n$48"
Classes
Read distinct CSS class names without changing the element.
row = g class: [:invoice, "overdue invoice"]
text row.Classes.join(" "), y: 12
Classify
Add CSS class tokens without duplicating existing values.
row = g class: "invoice-row"
row.Classify :overdue, "needs-review"
Comment
Insert a safely encoded XML comment.
Comment "Invoice totals calculated on 2026-07-14"
css
Turn a Ruby hash into a readable SVG style element.
css ".alert" => {fill: "tomato", stroke: "white", "stroke-width": 2}
circle class: "alert", cx: 10, cy: 10, r: 8
Document
Define, validate, or look up a document profile without replacing a conflicting definition.
Document :catalog_icon, attributes: {viewBox: "0 0 24 24"}
SVG :catalog_icon do
circle cx: 12, cy: 12, r: 10
end.Render
Document!
Explicitly replace a named document profile.
Document! :catalog_badge, attributes: {viewBox: "0 0 80 32"}
SVG :catalog_badge do
rect width: 80, height: 32, rx: 4
end.Render
Decompile
Parse inline SVG/XML into an inspectable immutable Derender node.
node = Decompile '<rect id="mark" width="4" height="2"/>', id: "mark"
node.attributes
DecompileFile
Parse an SVG/XML file into an inspectable immutable Derender node.
DecompileFile "shape.svg", id: "mark"
Defaults
Fill only attributes that the element does not already have.
avatar = circle fill: "gold"
avatar.Defaults r: 16, fill: "gray", stroke: "white"
Derender
Convert inline SVG/XML or a selected id into formatted Sumi source.
Derender '<rect id="mark" width="4"/>', id: "mark"
See the Derender guide.
DerenderFile
Convert an SVG/XML file or selected id into formatted Sumi source.
DerenderFile "shape.svg", id: "mark"
See the Derender guide.
Disidentify
Move rendered id values to -id data while retaining their source identity. The leading - keeps the values in memory and out of SVG output.
art = g id: "art" do
circle id: "dot", r: 2
end
art.Disidentify
art[:"-id"] # => "art"
Draw
Draw one or more Geometry objects into the current SVG element.
Draw Sumi::Geometry::Line.([4, 4], [76, 4]), class: %w[guide trim]
See drawing geometry.
Duplicate
Copy an independent subtree and optionally translate or customize it. Copied id values move to -id; the leading - keeps them in memory and out of SVG output.
source = circle id: "dot", r: 2
source.Duplicate dx: 8 do |node|
node[:id] = "dot-copy" if node[:"-id"]
end
DuplicateX
Copy an element and translate the copy along the x axis.
dot = circle r: 2
dot.DuplicateX 8
DuplicateY
Copy an element and translate the copy along the y axis.
dot = circle r: 2
dot.DuplicateY 8
Element
Build an explicitly named XML element when a bare Ruby call is unsuitable.
Element "custom:mark", "hello", "custom:kind": "spark"
Evaluate
Import an inline SVG/XML node directly under an existing SVG element.
drawing = SVG :minimal
Evaluate '<circle id="mark" r="2"/>', drawing, id: "mark"
EvaluateChildren
Import only the children of an inline SVG/XML node under an existing SVG element.
drawing = SVG :minimal
EvaluateChildren '<g id="marks"><circle r="2"/></g>', drawing, id: "marks"
EvaluateChildrenFile
Import only a selected file node's children under an existing SVG element.
drawing = SVG :minimal
EvaluateChildrenFile "shape.svg", drawing, id: "group"
EvaluateFile
Import a selected SVG/XML file node directly under an existing SVG element.
drawing = SVG :minimal
EvaluateFile "shape.svg", drawing, id: "mark"
Flip
Append a two-axis reflection to the element's SVG transform list.
line = path d: "M 0 0 L 8 3"
line.Flip
FlipX
Reflect an element horizontally with an SVG scale transform.
line = path d: "M 0 0 L 8 3"
line.FlipX
FlipY
Reflect an element vertically with an SVG scale transform.
line = path d: "M 0 0 L 8 3"
line.FlipY
Forward
Pass the current element as the first argument to another receiver.
Forward proc { |node| node.Classify "forwarded" }, :call
Grid
Fit a major/minor grid inside a Canvas while preserving its margins.
canvas = SVG.Canvas width: 80, height: 50, margins: 5
grid = Grid canvas, unit: 1, multiple: 10
SVG :inkscape, grid.canvas do
Draw grid.x.major.lines, class: %w[guide horizontal]
Draw grid.y.major.lines, class: %w[guide vertical]
end.Render
See fitted grids.
Group
Render a callable module inside a regular group with stable wrapper attributes.
Build an anonymous callable with SVG.Module { ... }. For an existing or explicitly
declared module, use extend SVG::Module. Use extend SVG::Modules for
an owned module tree.
Public instance methods are drawing steps; private and protected methods are helpers. Each invocation uses a fresh callable receiver rather than the document object.
mark = SVG.Module do
def call = path d: "M 0 8 L 5 13 L 16 0", fill: "none", stroke: "seagreen"
end
SVG :inkscape do
Group mark, attributes: {id: "approval-mark"}
end.Render
Hatch
Sweep parallel Geometry lines through a closed shape and draw them.
no_print = Sumi::Geometry::Rect[48, 18, position: [6, 6]]
Hatch no_print, angle: 30, step: 3, class: %w[guide no-print]
See sweeps and hatching.
HLineBy
Draw a relative horizontal path segment from a starting point.
HLineBy x: 2, y: 4, length: 12, stroke: "black"
HLineTo
Draw a horizontal path segment to an absolute x coordinate.
HLineTo x1: 2, y1: 4, x2: 14, stroke: "black"
Identifiers
Snapshot rendered ids and expose duplicate-id collisions.
art = g do
circle id: "dot", r: 2
end
art.Identifiers["dot"].Classify "indexed"
Imprint
Declare PDF page metadata and editable paint controls without changing the SVG.
g id: "outline" do
rect width: 10, height: 10, fill: "none", stroke: "black"
end
Imprint do
Page name: "Practice", tags: ["guide"]
Target "ink", selectors: ["#outline"]
Param "display", targets: ["ink"], property: "display",
schema: {type: "string", enum: %w[inline none]}
Param "opacity", targets: ["ink"], property: "stroke-opacity",
schema: {type: "number", minimum: 0, maximum: 1}
end
See editable PDF export.
Include
Import one selected SVG/XML node, optionally omitting unwanted attributes.
Include "shape.svg", "mark", omit: :id
See direct evaluation.
IncludeChildren
Import only the children of a selected SVG/XML node.
IncludeChildren "shape.svg", "group"
See direct evaluation.
InkscapeTemplateInfo
Add Inkscape's reusable-template name, description, and author metadata.
InkscapeTemplateInfo name: "Badge", desc: "A tiny badge", author: "Sumi"
Is?
Ask whether the current element has a particular SVG/XML name.
dot = circle r: 2
dot.Is? :circle # => true
layer
Build a generic group, or an Inkscape layer when using the Inkscape profile.
layer id: "ink" do
path d: "M 0 0 L 8 3"
end
Layer
Render a callable module inside an Inkscape layer.
Build an anonymous callable with SVG.Module { ... }. For an existing or explicitly
declared module, use extend SVG::Module. Use extend SVG::Modules for
an owned module tree.
Public instance methods are drawing steps; private and protected methods are helpers. Each invocation uses a fresh callable receiver rather than the document object.
labels = SVG.Module do
def call = text "DRAFT", x: 8, y: 16
end
SVG :inkscape do
Layer labels, attributes: {id: "annotations"}
end.Render
layer!
Build a generic group, or an Inkscape layer marked insensitive to editor interaction.
layer! id: "locked" do
rect width: 8, height: 4
end
Layer!
Render a callable module inside a locked Inkscape layer.
Build an anonymous callable with SVG.Module { ... }. For an existing or explicitly
declared module, use extend SVG::Module. Use extend SVG::Modules for
an owned module tree.
Public instance methods are drawing steps; private and protected methods are helpers. Each invocation uses a fresh callable receiver rather than the document object.
guides = SVG.Module do
def call = LineTo x1: 4, y1: 4, x2: 76, y2: 4, class: %w[guide trim]
end
SVG :inkscape do
Layer! guides, attributes: {id: "print-guides"}
end.Render
License
Add RDF work metadata with an explicit license URL.
License title: "Badge", creator: "Sumi", license: "https://example.test/license"
License_CC0
Mark a work with Creative Commons Zero metadata.
License_CC0 title: "Public badge", creator: "Sumi"
License_CC_BY
Add Creative Commons Attribution 4.0 metadata.
License_CC_BY title: "Badge", creator: "Sumi"
License_CC_BY_NC
Add Creative Commons Attribution-NonCommercial 4.0 metadata.
License_CC_BY_NC title: "Badge", creator: "Sumi"
License_CC_BY_NC_ND
Add Attribution-NonCommercial-NoDerivatives metadata.
License_CC_BY_NC_ND title: "Badge", creator: "Sumi"
License_CC_BY_NC_SA
Add Attribution-NonCommercial-ShareAlike metadata.
License_CC_BY_NC_SA title: "Badge", creator: "Sumi"
License_CC_BY_ND
Add Creative Commons Attribution-NoDerivatives metadata.
License_CC_BY_ND title: "Badge", creator: "Sumi"
License_CC_BY_SA
Add Creative Commons Attribution-ShareAlike metadata.
License_CC_BY_SA title: "Badge", creator: "Sumi"
License_LAL
Add Free Art License metadata.
License_LAL title: "Badge", creator: "Sumi"
LineBy
Draw a relative line from a screen-space angle and length.
LineBy x: 2, y: 2, angle: 30, length: 12, stroke: "black"
LineTo
Draw a line path between two absolute points.
LineTo x1: 2, y1: 2, x2: 14, y2: 8, stroke: "black"
Lint
Reject structural problems such as duplicate rendered ids.
badge = g do
circle id: "outline", r: 2
end
badge.Lint
Load
Evaluate another .sumi file relative to the active script while preserving the load stack.
Load "part"
SVG :minimal do
circle r: PART_RADIUS
end.Render
See script loading.
Matrix
Append an explicit six-value SVG transformation matrix.
shape = rect width: 4, height: 2
shape.Matrix 1, 0.2, 0, 1, 6, 3
Mixin
Add a named or anonymous DSL extension to a document profile.
profile = SVG.Document attributes: {}
Mixin profile do
define_method(:Badge) { circle r: 4 }
end
SVG profile do
Badge()
end.Render
Module
Build an anonymous callable with public drawing steps and private or protected helpers.
Build an anonymous callable with SVG.Module { ... }. For an existing or explicitly
declared module, use extend SVG::Module. Use extend SVG::Modules for
an owned module tree.
Public instance methods are drawing steps; private and protected methods are helpers. Each invocation uses a fresh callable receiver rather than the document object.
label = SVG.Module do
def call(value) = draw value
private
def draw(value) = text value
end
SVG :minimal do
Call label, "Ready"
end.Render
See callable modules.
NS?
Ask whether a namespace is declared on the element or an ancestor.
self.NS? :inkscape # => true
Orphan
Detach an element and retain it as an independent subtree root.
spare = circle r: 2
spare.Orphan
g { spare.Adopt self }
Out
Render a checked document to standard output.
SVG :minimal do
circle r: 3
end.Out
Pages
Declare explicit Inkscape pages inside a namedview.
front = {x: 0, y: 0, width: 100, height: 60, label: "front"}
Pages front
PagesTabular
Generate a rectangular grid of Inkscape pages.
PagesTabular rows: 2, cols: 2, width: 100, height: 60, gap: 5
Paper
Register or verify an idempotent named paper profile.
Paper 90, 50, :catalog_card
SVG :minimal, :catalog_card do
rect width: 90, height: 50
end.Render
Paper!
Explicitly replace a custom named paper profile.
Paper! 90, 50, :catalog_card
SVG :minimal, :catalog_card do
rect width: 90, height: 50
end.Render
PDF
Render and export the document as a PDF through the optional native stack.
SVG width: 20, height: 20 do
circle cx: 10, cy: 10, r: 8
end.PDF "example.pdf"
See export setup.
PNG
Render and export the document as a PNG through the optional native stack.
SVG width: 20, height: 20 do
circle cx: 10, cy: 10, r: 8
end.PNG "example.png"
See export setup.
Prepend
Move existing elements to the beginning of a new parent's children.
card = g { text "Boarding pass", x: 12, y: 24 }
background = rect width: 120, height: 40, rx: 4, fill: "ivory"
card.Prepend background
PreRender
Run selected validation and lint checks explicitly before rendering.
drawing = SVG :minimal do
rect width: 4, height: 2
end
drawing.PreRender validate: true, lint: true
drawing.Render
RDF
Build an RDF metadata container inside an Inkscape document.
RDF { Element :"cc:Work", "rdf:about": "" }
RDFWork
Describe a work with common Dublin Core and Creative Commons metadata.
RDFWork title: "Badge", creator: "Sumi"
Render
Serialize a document, element, or subtree as SVG/XML without running the document checks.
drawing = SVG :minimal do
circle r: 3
end
drawing.Render
RenderChildren
Serialize only an element's children, leaving out the element itself.
drawing = SVG :minimal do
circle r: 2
rect width: 3, height: 2
end
drawing.RenderChildren
Root
Return the topmost element of the current tree, including a detached subtree.
dot = circle r: 2
dot.Root.equal? self # => true
Root?
Report whether the element is the document root.
dot = circle r: 2
self.Root? # => true
dot.Root? # => false
Rotate
Append an SVG rotation, optionally around an explicit center.
shape = rect width: 8, height: 3
shape.Rotate 25, 4, 1.5
RotateLeft
Rotate an element left by a quarter turn.
line = path d: "M 0 0 L 8 3"
line.RotateLeft
RotateRight
Rotate an element right by a quarter turn.
line = path d: "M 0 0 L 8 3"
line.RotateRight
Ruler
Fit major and minor intervals into a span without drawing SVG elements.
ruler = Ruler brut: 180, unit: 1, multiple: 10
SVG do
ruler.ds.each { |x| line x1: x, y1: 0, x2: x, y2: 6 }
end.Render
See Rulers.
Save
Render a checked document to an SVG file.
SVG :minimal do
circle r: 3
end.Save "example.svg"
Scale
Append a one- or two-axis SVG scale transform.
dot = circle r: 3
dot.Scale 1.5, 0.75
sumi
Run a .sumi script as a Rake file task with arguments and dependency tracking.
sumi "drawing", "front", theme: :dark
See Rake integration.
Skew
Append horizontal and vertical SVG skew transforms together.
shape = rect width: 8, height: 3
shape.Skew 12, -4
SkewX
Append a horizontal SVG skew transform.
shape = rect width: 8, height: 3
shape.SkewX 12
SkewY
Append a vertical SVG skew transform.
shape = rect width: 8, height: 3
shape.SkewY 12
square
Draw a square through the familiar SVG rect vocabulary.
square x: 2, y: 2, length: 8, rx: 1
Stay
Stop a traversal immediately and return a selected value.
g id: "target" do
circle r: 2
end
found = Traverse { |node| Stay node if node[:id] == "target" }
found.Classify "selected"
SVG
Create an SVG document from a profile, canvas, and drawing block.
SVG :minimal do
circle r: 4
end.Render
Symbol
Build a titled SVG symbol with an id derived from its human-readable name.
Symbol "status dot" do
circle r: 2
end
symbol!
Build an SVG symbol element directly, including in profiles without a wrapper.
symbol! id: "hidden" do
circle r: 2
end
Symbols
Collect symbols declared by a callable module into a defs element.
Build an anonymous callable with SVG.Module { ... }. For an existing or explicitly
declared module, use extend SVG::Module. Use extend SVG::Modules for
an owned module tree.
Public instance methods are drawing steps; private and protected methods are helpers. Each invocation uses a fresh callable receiver rather than the document object.
icons = SVG.Module do
def dot = circle r: 2
def tick = path d: "M 0 2 L 2 4 L 6 0"
end
Symbols icons
Tile
Define one template and place references across a two-dimensional grid.
Tile "seat-map", nx: 4, ny: 3, dx: 8, dy: 8 do
rect width: 5, height: 5, rx: 1
end
TileX
Define one template and place references at a fixed horizontal interval.
TileX "ticket-holes", n: 8, d: 6 do
circle r: 1, fill: "white"
end
TileY
Define one template and place references at a fixed vertical interval.
TileY "timeline", n: 5, d: 10 do
circle r: 2, fill: "seagreen"
end
Translate
Append a two-axis SVG translation.
dot = circle r: 2
dot.Translate 8, 4
TranslateX
Append a horizontal SVG translation.
dot = circle r: 2
dot.TranslateX 8
TranslateY
Append a vertical SVG translation.
dot = circle r: 2
dot.TranslateY 8
Traverse
Walk an element and its descendants in document order.
g do
circle r: 2
rect width: 3, height: 2
end
Traverse { |node| node.Classify "visited" }
TraverseUp
Walk from an element toward the root through its ancestors.
g do
dot = circle r: 2
dot.TraverseUp { |node| node[:data_seen] = true }
end
Validate
Check SVG element, attribute, namespace, and content rules immediately.
badge = circle r: 3, fill: "tomato"
badge.Validate
VLineBy
Draw a relative vertical path segment from a starting point.
VLineBy x: 4, y: 2, length: 12, stroke: "black"
VLineTo
Draw a vertical path segment to an absolute y coordinate.
VLineTo x1: 4, y1: 2, y2: 14, stroke: "black"
With
Run a block with a sanitized generated id and return the original element.
marker = circle r: 2
marker.With "status dot" do |id|
marker[:id] = id
end
Within
Evaluate a block in another element's DSL context while retaining the caller.
target = g id: "target"
dot = circle r: 2
dot.Within receiver: target do
rect width: 4, height: 2
end
Write
Write rendered SVG to a named destination without the Save convenience checks.
SVG :minimal do
circle r: 3
end.Write "example.svg"