svg_optimizer 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of svg_optimizer might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/svg_optimizer/plugins/cleanup_id.rb +4 -3
- data/lib/svg_optimizer/plugins/collapse_groups.rb +1 -1
- data/lib/svg_optimizer/plugins/remove_description.rb +1 -1
- data/lib/svg_optimizer/plugins/remove_editor_namespace.rb +1 -1
- data/lib/svg_optimizer/plugins/remove_empty_attribute.rb +1 -1
- data/lib/svg_optimizer/plugins/remove_empty_container.rb +1 -1
- data/lib/svg_optimizer/plugins/remove_title.rb +1 -1
- data/lib/svg_optimizer/plugins/remove_unused_namespace.rb +4 -1
- data/lib/svg_optimizer/plugins/remove_useless_stroke_and_fill.rb +10 -6
- data/lib/svg_optimizer/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59eadfc68915559182e085a2f122874d2248fb2a
|
4
|
+
data.tar.gz: 35e56a3a5085279f4736bac7b8742d2ae677945e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 632f0a5d429a6f9c5f3696af63adb973034f4d4c8d9c9f78764d21916186948094d5102ed21c867161c19cfc7fa6678e8b06570727eca69cd3a576643d6d26b8
|
7
|
+
data.tar.gz: c66b98f89cf0dab885246af11ed53ab20eef217f7ce12c900964820811dc399de942531de48f73517e51c5b5c2180cd09b0f24df483f15c48394162f5a7b5697
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# SvgOptimizer
|
2
2
|
|
3
|
-
[](https://travis-ci.org/fnando/svg_optimizer)
|
4
4
|
[](https://codeclimate.com/github/fnando/svg_optimizer)
|
5
5
|
[](https://codeclimate.com/github/fnando/svg_optimizer/coverage)
|
6
6
|
[](https://rubygems.org/gems/svg_optimizer)
|
@@ -6,16 +6,16 @@ module SvgOptimizer
|
|
6
6
|
LETTERS = %w[
|
7
7
|
a b c d e f g h i j k l m n o p q r s t u v w x y z
|
8
8
|
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
|
9
|
-
]
|
9
|
+
].freeze
|
10
10
|
|
11
|
-
IDS = LETTERS.concat(LETTERS.combination(2).to_a)
|
11
|
+
IDS = LETTERS.dup.concat(LETTERS.combination(2).to_a).freeze
|
12
12
|
|
13
13
|
def ids
|
14
14
|
@ids ||= IDS.dup
|
15
15
|
end
|
16
16
|
|
17
17
|
def process
|
18
|
-
# If there a <script> or <style>, don't mess with ids.
|
18
|
+
# If there's a <script> or <style>, don't mess with ids.
|
19
19
|
return if xml.css("script, style").any?
|
20
20
|
|
21
21
|
# Replace the ids otherwise.
|
@@ -41,6 +41,7 @@ module SvgOptimizer
|
|
41
41
|
def remove_unused_id(node, has_url_refs, has_href_refs)
|
42
42
|
return if has_url_refs
|
43
43
|
return if has_href_refs
|
44
|
+
|
44
45
|
node.remove_attribute("id")
|
45
46
|
end
|
46
47
|
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module SvgOptimizer
|
4
4
|
module Plugins
|
5
5
|
class RemoveEmptyContainer < Base
|
6
|
-
ELEMENTS = %w[a defs g marker mask missing-glyph pattern switch symbol]
|
6
|
+
ELEMENTS = %w[a defs g marker mask missing-glyph pattern switch symbol].freeze
|
7
7
|
SELECTOR = ELEMENTS.map {|element| %[#{element}:empty] }.join(", ")
|
8
8
|
|
9
9
|
def process
|
@@ -4,13 +4,16 @@ module SvgOptimizer
|
|
4
4
|
module Plugins
|
5
5
|
class RemoveUnusedNamespace < Base
|
6
6
|
def process
|
7
|
-
xml
|
7
|
+
xml
|
8
|
+
.root
|
9
|
+
.namespace_definitions
|
8
10
|
.select(&:prefix)
|
9
11
|
.each(&method(:remove_unused_ns))
|
10
12
|
end
|
11
13
|
|
12
14
|
def remove_unused_ns(ns)
|
13
15
|
return if xml.xpath("//#{ns.prefix}:*").any?
|
16
|
+
|
14
17
|
source = xml.root.to_s.gsub(/ *xmlns:#{ns.prefix}=".*?"/, "")
|
15
18
|
xml.root = Nokogiri::XML(source).root
|
16
19
|
end
|
@@ -4,8 +4,8 @@ module SvgOptimizer
|
|
4
4
|
module Plugins
|
5
5
|
class RemoveUselessStrokeAndFill < Base
|
6
6
|
SELECTOR = %w[circle ellipse line path polygon polyline rect].join(",")
|
7
|
-
STROKE_ATTRS = %w[stroke stroke-opacity stroke-width stroke-dashoffset]
|
8
|
-
FILL_ATTRS = %w[fill-opacity fill-rule]
|
7
|
+
STROKE_ATTRS = %w[stroke stroke-opacity stroke-width stroke-dashoffset].freeze
|
8
|
+
FILL_ATTRS = %w[fill-opacity fill-rule].freeze
|
9
9
|
|
10
10
|
def process
|
11
11
|
return if xml.css("style, script").any?
|
@@ -24,12 +24,12 @@ module SvgOptimizer
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def remove_stroke(node)
|
27
|
-
STROKE_ATTRS.each {
|
27
|
+
STROKE_ATTRS.each {|attr| node.delete(attr) }
|
28
28
|
node["stroke"] = "none" if decline_inherited_stroke?(node)
|
29
29
|
end
|
30
30
|
|
31
31
|
def remove_fill(node)
|
32
|
-
FILL_ATTRS.each {
|
32
|
+
FILL_ATTRS.each {|attr| node.delete(attr) }
|
33
33
|
node["fill"] = "none" if decline_inherited_fill?(node)
|
34
34
|
end
|
35
35
|
|
@@ -44,19 +44,23 @@ module SvgOptimizer
|
|
44
44
|
def remove_stroke?(node)
|
45
45
|
return true if (inherited_attribute(node, "stroke") || "none") == "none"
|
46
46
|
return true if inherited_attribute(node, "stroke-opacity") == "0"
|
47
|
-
|
47
|
+
|
48
|
+
inherited_attribute(node, "stroke-width") == "0"
|
48
49
|
end
|
49
50
|
|
50
51
|
def remove_fill?(node)
|
51
52
|
fill = inherited_attribute(node, "fill")
|
53
|
+
|
52
54
|
return true if fill == "none"
|
53
55
|
return true if inherited_attribute(node, "fill-opacity") == "0"
|
54
|
-
|
56
|
+
|
57
|
+
!fill
|
55
58
|
end
|
56
59
|
|
57
60
|
def inherited_attribute(node, attr)
|
58
61
|
return if node.nil? || node.document?
|
59
62
|
return node[attr] if node.has_attribute?(attr)
|
63
|
+
|
60
64
|
inherited_attribute(node.parent, attr)
|
61
65
|
end
|
62
66
|
end
|