Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Make SVG with builder
# encoding: utf-8
require 'rubygems'
require 'builder'
svg_doctype = [
:DOCTYPE,
:svg,
:PUBLIC,
"-//W3C//DTD SVG 1.1//EN",
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"
]
svg_options = {
:xmlns => "http://www.w3.org/2000/svg",
:"xmlns:xlink" => "http://www.w3.org/1999/xlink",
:"xmlns:ev" => "http://www.w3.org/2001/xml-events",
:version => "1.1",
:baseProfile => "full",
:width => "1000px",
:height => "1000px"
}
output = String.new
svg = Builder::XmlMarkup.new indent: 2, target: output
svg.instruct!
svg.declare! *svg_doctype
svg.svg(svg_options) do
svg.circle cx: 500, cy: 500, r: 200, style: "fill:red; stroke:black; stroke-width:10"
end
File.open('output.svg', 'w') { |f| f.write output }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment