Project

svgen

0.0
No commit activity in last 3 years
No release in over 3 years
SVG generator
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.5
>= 0
~> 2.14.1

Runtime

~> 3.2.2
 Project Readme

SVGen

SVG generator

Install

$ gem install svgen

Usage

rect, circle, text

require "svgen"

svg = SVGen::SVG.new(width: 600, height: 400) do |svg|
  svg.rect(width: 300, height: 200, fill: "blue")
  svg.circle(cx: 100, cy: 100, r: 50, fill: "red")
  svg.text("Sample Text", x: 20, y: 20)
end
svg.generate
#=>
# <svg width="600" height="300" xmlns="http://www.w3.org/2000/svg">
#   <rect width="300" height="200" fill="blue"/>
#   <circle cx="100" cy="100" r="50" fill="red"/>
#   <text x="20" cy="20">Sample Text</text>
# </svg>

group

require "svgen"

svg = SVGen::SVG.new(width: 600, height: 400) do |svg|
  svg.g(stroke: "red", "stroke-width" => 5) do |g|
    g.rect(x: 50, y: 50, width: 100, height: 100)
    g.circle(cx: 200, cy: 200, r: 50)
  end
end
svg.generate
#=>
# <svg width="600" height="300" xmlns="http://www.w3.org/2000/svg">
#   <g stroke="red" stroke-width="5">
#     <rect x="50" y="50" width="100" height="100"/>
#     <circle cx="200" cy="200" r="50"/>
#   </g>
# </svg>