svgr 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/svgr +2 -0
- data/lib/svgr/document/recolor.rb +36 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b8780a8f57f04ba0f269de4d0c36b3d4f49f6a0afd3965bdff81133ae40deac8
|
4
|
+
data.tar.gz: 243c8772a968c49afee686e50efb4a1291daa395cc97dffe2c3feca5c785f96a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3518dc3fcc3e31e2a81baacbc820149f26f7ea01e6ca3fb091dd31061f47e527306a1471a34b85d0f429e96538af78256f3f20a74d9bc0a70b928e5f745e6d64
|
7
|
+
data.tar.gz: 1ddc2d25637571d643cb7b90a824f4f1103fd1109c97555041ff752e604f4b111c84253c1664169b396032fde414ee51dddb35f054aaff095d4ab686d7bb0e24
|
data/bin/svgr
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require "optparse"
|
4
4
|
require_relative "../lib/svgr/arrange/grid"
|
5
5
|
require_relative "../lib/svgr/document/resize"
|
6
|
+
require_relative "../lib/svgr/document/recolor"
|
6
7
|
|
7
8
|
module Svgr
|
8
9
|
def self.start(argv)
|
@@ -11,6 +12,7 @@ module Svgr
|
|
11
12
|
subcommands = {
|
12
13
|
"arrange:grid" => ->(args) { Svgr::Arrange::Grid.start(args) },
|
13
14
|
"document:resize" => ->(args) { Svgr::Document::Resize.start(args) },
|
15
|
+
"document:recolor" => ->(args) { Svgr::Document::Recolor.start(args) }
|
14
16
|
}
|
15
17
|
|
16
18
|
opt_parser = OptionParser.new do |opts|
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "nokogiri"
|
4
|
+
|
5
|
+
module Svgr
|
6
|
+
module Document
|
7
|
+
class Recolor
|
8
|
+
class << self
|
9
|
+
def start(argv)
|
10
|
+
hex_value = argv[0]
|
11
|
+
|
12
|
+
if !hex_value || argv.size != 1
|
13
|
+
puts "Usage: svgr document:recolor <HEXVALUE>"
|
14
|
+
exit(1)
|
15
|
+
end
|
16
|
+
|
17
|
+
svg_content = $stdin.read
|
18
|
+
recolored_svg = recolor(svg_content, hex_value)
|
19
|
+
|
20
|
+
# Write the output
|
21
|
+
output = recolored_svg.to_xml
|
22
|
+
puts output
|
23
|
+
end
|
24
|
+
|
25
|
+
def recolor(content, hex_value)
|
26
|
+
svg = Nokogiri::XML(content)
|
27
|
+
svg.css("path, circle, ellipse, line, polyline, polygon, rect").each do |element|
|
28
|
+
element["fill"] = hex_value if element["fill"] && element["fill"] != "none"
|
29
|
+
element["stroke"] = hex_value if element["stroke"] && element["stroke"] != "none"
|
30
|
+
end
|
31
|
+
svg
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: svgr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nassredean Nasseri
|
@@ -89,6 +89,7 @@ extra_rdoc_files: []
|
|
89
89
|
files:
|
90
90
|
- bin/svgr
|
91
91
|
- lib/svgr/arrange/grid.rb
|
92
|
+
- lib/svgr/document/recolor.rb
|
92
93
|
- lib/svgr/document/resize.rb
|
93
94
|
homepage: https://github.com/nassredean/svgr
|
94
95
|
licenses:
|