Class: Svgr::Document::Recolor

Inherits:
Object
  • Object
show all
Defined in:
lib/svgr/document/recolor.rb

Class Method Summary collapse

Class Method Details

.recolor(content, hex_value) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/svgr/document/recolor.rb', line 25

def recolor(content, hex_value)
  svg = Nokogiri::XML(content)
  svg.css("path, circle, ellipse, line, polyline, polygon, rect").each do |element|
    element["fill"] = hex_value if element["fill"] && element["fill"] != "none"
    element["stroke"] = hex_value if element["stroke"] && element["stroke"] != "none"
  end
  svg
end

.start(argv) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/svgr/document/recolor.rb', line 9

def start(argv)
  hex_value = argv[0]

  if !hex_value || argv.size != 1
    puts "Usage: svgr document:recolor <HEXVALUE>"
    exit(1)
  end

  svg_content = $stdin.read
  recolored_svg = recolor(svg_content, hex_value)

  # Write the output
  output = recolored_svg.to_xml
  puts output
end