3 require "rexml/document"
6 INKSCAPE = '/usr/bin/inkscape'
10 svg = Document.new(File.new("#{SRC}/#{file}", 'r'))
11 svg.root.each_element("//g[contains(@inkscape:label,'plate')]") do |icon|
12 filename = icon.attributes["label"]
13 filename = `echo -n #{filename} | sed -e 's/plate\-//g'`
14 puts "#{file} #{filename}.png"
15 icon.each_element("rect") do |box|
16 if box.attributes['inkscape:label'] == '22x22'
17 dir = "#{box.attributes['width']}x#{box.attributes['height']}/"
18 cmd = "#{INKSCAPE} -i #{box.attributes['id']} -e #{dir}/#{filename}.png #{SRC}/#{file} > /dev/null 2>&1"
19 File.makedirs(dir) unless File.exists?(dir)
22 elsif box.attributes['inkscape:label'] == '24x24'
23 dir = "#{box.attributes['width']}x#{box.attributes['height']}/"
24 cmd = "#{INKSCAPE} -i #{box.attributes['id']} -e #{dir}/#{filename}.png #{SRC}/#{file} > /dev/null 2>&1"
25 File.makedirs(dir) unless File.exists?(dir)
34 if (ARGV[0].nil?) #render all SVGs
35 puts "Rendering from SVGs in #{SRC}"
36 Dir.foreach(SRC) do |file|
37 renderit(file) if file.match(/svg$/)
39 puts "\nrendered all SVGs"
40 else #only render the SVG passed
41 file = "#{ARGV[0]}.svg"
42 if (File.exists?("#{SRC}/#{file}"))
44 puts "\nrendered #{file}"
46 puts "[E] No such file (#{file})"