Introduction
Sumi creates SVG with Ruby. Install the command-line toolkit. Then save and run the first drawing.
Install and run
For macOS and Linux, install the complete toolkit through Homebrew:
brew install roktas/tap/toji roktas/tap/sumi
Save this script as badge.sumi:
#!/usr/bin/env -S ruby -S sumi
SVG width: 120, height: 60 do
rect x: 4, y: 4, width: 112, height: 52, rx: 8, fill: "gold"
circle cx: 60, cy: 30, r: 16, fill: "tomato"
end.Save "badge.svg"
Run the script:
sumi badge.sumi
Open badge.svg in a browser. The gold panel contains a centered red circle.
Omitting the profile uses :default, which supplies the SVG namespace for a standalone file.
For Ruby application use, see Usage. That page explains the shared drawing syntax and the different script and library operations.
See a complete drawing
The example tabs use the same files as the test suite. The Ruby tab contains the script. The SVG tab contains its output.
LED_COUNT = 10
LED_GAP = 2
LED_WIDTH = 10
TOTAL_WIDTH = (LED_COUNT * (LED_WIDTH + LED_GAP)) + 8
dim = proc do |led, x:, **|
led[:"fill-opacity"] = 0.3 if x >= 7
end
SVG width: TOTAL_WIDTH, height: 30, viewBox: "0 0 #{TOTAL_WIDTH} 30" do
rect x: 2, y: 2, width: TOTAL_WIDTH - 4, height: 26,
rx: 4, fill: "none", stroke: "#666"
TileX "led", n: LED_COUNT, d: LED_WIDTH + LED_GAP, o: 5, proc: dim do
rect y: 5, width: LED_WIDTH, height: 20, rx: 3, fill: "green"
end
end.Save
LED_COUNT = 10
LED_GAP = 2
LED_WIDTH = 10
TOTAL_WIDTH = (LED_COUNT * (LED_WIDTH + LED_GAP)) + 8
dim = proc do |led, x:, **|
led[:"fill-opacity"] = 0.3 if x >= 7
end
SVG width: TOTAL_WIDTH, height: 30, viewBox: "0 0 #{TOTAL_WIDTH} 30" do
rect x: 2, y: 2, width: TOTAL_WIDTH - 4, height: 26,
rx: 4, fill: "none", stroke: "#d8d8d8"
TileX "led", n: LED_COUNT, d: LED_WIDTH + LED_GAP, o: 5, proc: dim do
rect y: 5, width: LED_WIDTH, height: 20, rx: 3, fill: "#7bd88f"
end
end.Save
<?xml version="1.0" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg" width="128" height="30" viewBox="0 0 128 30">
<rect x="2" y="2" width="124" height="26" rx="4" fill="none" stroke="#666"/>
<defs>
<g id="led">
<rect y="5" width="10" height="20" rx="3" fill="green"/>
</g>
</defs>
<use id="led-1" href="#led" class="tile-col-1 tile-col-first" x="5"/>
<use id="led-2" href="#led" class="tile-col-2" x="17"/>
<use id="led-3" href="#led" class="tile-col-3" x="29"/>
<use id="led-4" href="#led" class="tile-col-4" x="41"/>
<use id="led-5" href="#led" class="tile-col-5" x="53"/>
<use id="led-6" href="#led" class="tile-col-6" x="65"/>
<use id="led-7" href="#led" class="tile-col-7" x="77"/>
<use id="led-8" href="#led" class="tile-col-8" x="89" fill-opacity="0.3"/>
<use id="led-9" href="#led" class="tile-col-9" x="101" fill-opacity="0.3"/>
<use id="led-10" href="#led" class="tile-col-10 tile-col-last" x="113" fill-opacity="0.3"/>
</svg>
<?xml version="1.0" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg" width="128" height="30" viewBox="0 0 128 30">
<rect x="2" y="2" width="124" height="26" rx="4" fill="none" stroke="#d8d8d8"/>
<defs>
<g id="led">
<rect y="5" width="10" height="20" rx="3" fill="#7bd88f"/>
</g>
</defs>
<use id="led-1" href="#led" class="tile-col-1 tile-col-first" x="5"/>
<use id="led-2" href="#led" class="tile-col-2" x="17"/>
<use id="led-3" href="#led" class="tile-col-3" x="29"/>
<use id="led-4" href="#led" class="tile-col-4" x="41"/>
<use id="led-5" href="#led" class="tile-col-5" x="53"/>
<use id="led-6" href="#led" class="tile-col-6" x="65"/>
<use id="led-7" href="#led" class="tile-col-7" x="77"/>
<use id="led-8" href="#led" class="tile-col-8" x="89" fill-opacity="0.3"/>
<use id="led-9" href="#led" class="tile-col-9" x="101" fill-opacity="0.3"/>
<use id="led-10" href="#led" class="tile-col-10 tile-col-last" x="113" fill-opacity="0.3"/>
</svg>
Run an example
If Sumi is installed on your system, run the example from the checkout:
sumi showcase/srv/meter.sumi
To use the gem versions locked by the checkout, run the command through Bundler:
bundle exec sumi showcase/srv/meter.sumi
The script writes showcase/srv/meter.svg because it ends with Save. To write SVG to standard output instead,
use Out in the script.
Installation details
This installs the sumi executable and Ruby. It also installs the Cairo, librsvg, and HexaPDF export stack. The
package includes the headless pdfcpu and Poppler tools. Inkscape remains an optional external backend.
When Sumi is a dependency of a Ruby application, add the umbrella gem to its bundle instead:
gem "sumie", git: "https://github.com/roktas/sumi.git", tag: "v1.0.0", require: "sumi"
The umbrella gem is the right choice for most applications and drawing scripts. It installs the script runner, the
SVG facade, the Appendix development extras, and all runtime components.
Choose a gem
Libraries that need fewer dependencies can install focused component gems:
| Scenario | Install | Require |
|---|---|---|
| Build and render SVG only | sumi-graphics | require "sumi/graphics" |
| Build and validate SVG without the full toolkit | sumi-graphics sumi-standard | require "sumi/graphics" |
| Use geometry values and transformations without the DSL | sumi-geometry | require "sumi/geometry" |
| Convert SVG or XML back into Sumi source | sumi-derender | require "sumi/derender" |
| Use grids, rulers, tiles, or export integrations | sumi-sundries | require "sumi/sundries" |
Package the agent skill or lint .sumi source | sumi-appendix | require "sumi/appendix" or the RuboCop plugin |
For example, a service that only builds SVG can install sumi-graphics and use
Sumi::Graphics.SVG(...). The full SVG facade and the sumi executable belong to the umbrella gem. Add
sumi-standard to validate element and attribute names. Bundler installs shared support gems such as
sumi-function as transitive dependencies.
SVG-only library use needs no native graphics packages. The Homebrew package already installs the PDF and PNG
dependencies. Applications that install gems directly must provide the optional cairo, rsvg2, and hexapdf gems
and their system libraries. See the
sumi-sundries package guide for those prerequisites.
The full installation also packages Sumi's agent skill. Run sumi --skill to locate it, then follow the
Appendix setup guide.
Continue with Documents to choose a canvas and document profile, or browse the tested Examples for complete drawings.