Skip to content

Instantly share code, notes, and snippets.

@padde
Created November 2, 2011 12:20
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save padde/1333491 to your computer and use it in GitHub Desktop.
Save padde/1333491 to your computer and use it in GitHub Desktop.
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