svg_optimizer 0.2.5 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of svg_optimizer might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/{LICENSE.txt → LICENSE.md} +0 -0
- data/README.md +32 -17
- data/lib/svg_optimizer/plugins/cleanup_id.rb +1 -1
- data/lib/svg_optimizer/plugins/remove_editor_namespace.rb +1 -0
- data/lib/svg_optimizer/plugins/remove_empty_attribute.rb +1 -3
- data/lib/svg_optimizer/plugins/remove_empty_container.rb +12 -4
- data/lib/svg_optimizer/plugins/remove_empty_text_node.rb +1 -3
- data/lib/svg_optimizer/plugins/remove_title.rb +1 -1
- data/lib/svg_optimizer/plugins/remove_useless_stroke_and_fill.rb +15 -11
- data/lib/svg_optimizer/version.rb +1 -1
- data/lib/svg_optimizer.rb +5 -1
- metadata +40 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 385024a89793a95b04290dbea791b71007a8d27387a02939865f4ed6f2528c72
|
4
|
+
data.tar.gz: 8e1e9581f7516362b09bc2221a889043e3ae1b1ad442e73a7b178be26e3e1d8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 699299880bf18dab73133899f59dcfa541a46ab45f3f0d2aeb48eb478caec60bdc2ce07c5093b5ab99e6c09118a966fa1009ba656ac7db0ef768a22a54774222
|
7
|
+
data.tar.gz: 1862ba8ad388c1523d7e69ff2e139efef59e4d3ede808d6ac9cabfd112c94b35a706563b1efaf10302386acce25812b02ba2b33ba3a2ab3bb45dc459963748d8
|
data/{LICENSE.txt → LICENSE.md}
RENAMED
File without changes
|
data/README.md
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
# SvgOptimizer
|
2
2
|
|
3
|
-
[![
|
3
|
+
[![Tests](https://github.com/fnando/svg_optimizer/workflows/ruby-tests/badge.svg)](https://github.com/fnando/svg_optimizer)
|
4
4
|
[![Code Climate](https://codeclimate.com/github/fnando/svg_optimizer/badges/gpa.svg)](https://codeclimate.com/github/fnando/svg_optimizer)
|
5
|
-
[![Test Coverage](https://codeclimate.com/github/fnando/svg_optimizer/badges/coverage.svg)](https://codeclimate.com/github/fnando/svg_optimizer/coverage)
|
6
5
|
[![Gem](https://img.shields.io/gem/v/svg_optimizer.svg)](https://rubygems.org/gems/svg_optimizer)
|
7
6
|
[![Gem](https://img.shields.io/gem/dt/svg_optimizer.svg)](https://rubygems.org/gems/svg_optimizer)
|
8
7
|
|
@@ -10,17 +9,15 @@ Some small optimizations for SVG files.
|
|
10
9
|
|
11
10
|
## Installation
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
And then execute:
|
18
|
-
|
19
|
-
$ bundle
|
12
|
+
```bash
|
13
|
+
gem install svg_optimizer
|
14
|
+
```
|
20
15
|
|
21
|
-
Or
|
16
|
+
Or add the following line to your project's Gemfile:
|
22
17
|
|
23
|
-
|
18
|
+
```ruby
|
19
|
+
gem "svg_optimizer"
|
20
|
+
```
|
24
21
|
|
25
22
|
## Usage
|
26
23
|
|
@@ -53,16 +50,34 @@ class MyPlugin < SvgOptimizer::Plugins::Base
|
|
53
50
|
end
|
54
51
|
```
|
55
52
|
|
56
|
-
The default list of plugins is stored at `SvgOptimizer::DEFAULT_PLUGINS`. To use
|
53
|
+
The default list of plugins is stored at `SvgOptimizer::DEFAULT_PLUGINS`. To use
|
54
|
+
your new plugin, just do something like this:
|
57
55
|
|
58
56
|
```ruby
|
59
57
|
SvgOptimizer.optimize(xml, SvgOptimizer::DEFAULT_PLUGINS + [MyPlugin])
|
60
58
|
```
|
61
59
|
|
60
|
+
## Maintainer
|
61
|
+
|
62
|
+
- [Nando Vieira](https://github.com/fnando)
|
63
|
+
|
64
|
+
## Contributors
|
65
|
+
|
66
|
+
- https://github.com/fnando/svg_optimizer/contributors
|
67
|
+
|
62
68
|
## Contributing
|
63
69
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
70
|
+
For more details about how to contribute, please read
|
71
|
+
https://github.com/fnando/svg_optimizer/blob/main/CONTRIBUTING.md.
|
72
|
+
|
73
|
+
## License
|
74
|
+
|
75
|
+
The gem is available as open source under the terms of the
|
76
|
+
[MIT License](https://opensource.org/licenses/MIT). A copy of the license can be
|
77
|
+
found at https://github.com/fnando/svg_optimizer/blob/main/LICENSE.md.
|
78
|
+
|
79
|
+
## Code of Conduct
|
80
|
+
|
81
|
+
Everyone interacting in the svg_optimizer project's codebases, issue trackers,
|
82
|
+
chat rooms and mailing lists is expected to follow the
|
83
|
+
[code of conduct](https://github.com/fnando/svg_optimizer/blob/main/CODE_OF_CONDUCT.md).
|
@@ -3,7 +3,17 @@
|
|
3
3
|
module SvgOptimizer
|
4
4
|
module Plugins
|
5
5
|
class RemoveEmptyContainer < Base
|
6
|
-
ELEMENTS = %w[
|
6
|
+
ELEMENTS = %w[
|
7
|
+
a
|
8
|
+
defs
|
9
|
+
g
|
10
|
+
marker
|
11
|
+
mask
|
12
|
+
missing-glyph
|
13
|
+
pattern
|
14
|
+
switch
|
15
|
+
symbol
|
16
|
+
].freeze
|
7
17
|
SELECTOR = ELEMENTS.map {|element| %[#{element}:empty] }.join(", ")
|
8
18
|
|
9
19
|
def process
|
@@ -12,9 +22,7 @@ module SvgOptimizer
|
|
12
22
|
end
|
13
23
|
end
|
14
24
|
|
15
|
-
private
|
16
|
-
|
17
|
-
def remove_node(node)
|
25
|
+
private def remove_node(node)
|
18
26
|
node.children.empty? && node.remove
|
19
27
|
remove_node(node.parent) if node.parent
|
20
28
|
end
|
@@ -4,7 +4,12 @@ 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[
|
7
|
+
STROKE_ATTRS = %w[
|
8
|
+
stroke
|
9
|
+
stroke-opacity
|
10
|
+
stroke-width
|
11
|
+
stroke-dashoffset
|
12
|
+
].freeze
|
8
13
|
FILL_ATTRS = %w[fill-opacity fill-rule].freeze
|
9
14
|
|
10
15
|
def process
|
@@ -15,40 +20,39 @@ module SvgOptimizer
|
|
15
20
|
end
|
16
21
|
end
|
17
22
|
|
18
|
-
private
|
19
|
-
|
20
|
-
def remove_useless_attributes(node)
|
23
|
+
private def remove_useless_attributes(node)
|
21
24
|
return if inherited_attribute(node, "id")
|
25
|
+
|
22
26
|
remove_stroke(node) if remove_stroke?(node)
|
23
27
|
remove_fill(node) if remove_fill?(node)
|
24
28
|
end
|
25
29
|
|
26
|
-
def remove_stroke(node)
|
30
|
+
private def remove_stroke(node)
|
27
31
|
STROKE_ATTRS.each {|attr| node.delete(attr) }
|
28
32
|
node["stroke"] = "none" if decline_inherited_stroke?(node)
|
29
33
|
end
|
30
34
|
|
31
|
-
def remove_fill(node)
|
35
|
+
private def remove_fill(node)
|
32
36
|
FILL_ATTRS.each {|attr| node.delete(attr) }
|
33
37
|
node["fill"] = "none" if decline_inherited_fill?(node)
|
34
38
|
end
|
35
39
|
|
36
|
-
def decline_inherited_stroke?(node)
|
40
|
+
private def decline_inherited_stroke?(node)
|
37
41
|
(inherited_attribute(node.parent, "stroke") || "none") != "none"
|
38
42
|
end
|
39
43
|
|
40
|
-
def decline_inherited_fill?(node)
|
44
|
+
private def decline_inherited_fill?(node)
|
41
45
|
!inherited_attribute(node, "fill") || node.has_attribute?("fill")
|
42
46
|
end
|
43
47
|
|
44
|
-
def remove_stroke?(node)
|
48
|
+
private def remove_stroke?(node)
|
45
49
|
return true if (inherited_attribute(node, "stroke") || "none") == "none"
|
46
50
|
return true if inherited_attribute(node, "stroke-opacity") == "0"
|
47
51
|
|
48
52
|
inherited_attribute(node, "stroke-width") == "0"
|
49
53
|
end
|
50
54
|
|
51
|
-
def remove_fill?(node)
|
55
|
+
private def remove_fill?(node)
|
52
56
|
fill = inherited_attribute(node, "fill")
|
53
57
|
|
54
58
|
return true if fill == "none"
|
@@ -57,7 +61,7 @@ module SvgOptimizer
|
|
57
61
|
!fill
|
58
62
|
end
|
59
63
|
|
60
|
-
def inherited_attribute(node, attr)
|
64
|
+
private def inherited_attribute(node, attr)
|
61
65
|
return if node.nil? || node.document?
|
62
66
|
return node[attr] if node.has_attribute?(attr)
|
63
67
|
|
data/lib/svg_optimizer.rb
CHANGED
@@ -38,8 +38,12 @@ module SvgOptimizer
|
|
38
38
|
].map {|name| Plugins.const_get(name) }
|
39
39
|
|
40
40
|
def self.optimize(contents, plugins = DEFAULT_PLUGINS)
|
41
|
-
xml = Nokogiri::XML(contents)
|
41
|
+
xml = Nokogiri::XML(contents) do |config|
|
42
|
+
config.recover.noent
|
43
|
+
end
|
44
|
+
|
42
45
|
plugins.each {|plugin| plugin.new(xml).process }
|
46
|
+
|
43
47
|
xml.root.to_xml
|
44
48
|
end
|
45
49
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: svg_optimizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nando Vieira
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: minitest-utils
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
@@ -67,7 +67,35 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop-fnando
|
71
99
|
requirement: !ruby/object:Gem::Requirement
|
72
100
|
requirements:
|
73
101
|
- - ">="
|
@@ -101,7 +129,7 @@ executables: []
|
|
101
129
|
extensions: []
|
102
130
|
extra_rdoc_files: []
|
103
131
|
files:
|
104
|
-
- LICENSE.
|
132
|
+
- LICENSE.md
|
105
133
|
- README.md
|
106
134
|
- lib/svg_optimizer.rb
|
107
135
|
- lib/svg_optimizer/plugins/base.rb
|
@@ -123,8 +151,9 @@ files:
|
|
123
151
|
homepage: https://github.com/fnando/svg_optimizer
|
124
152
|
licenses:
|
125
153
|
- MIT
|
126
|
-
metadata:
|
127
|
-
|
154
|
+
metadata:
|
155
|
+
rubygems_mfa_required: 'true'
|
156
|
+
post_install_message:
|
128
157
|
rdoc_options: []
|
129
158
|
require_paths:
|
130
159
|
- lib
|
@@ -132,16 +161,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
132
161
|
requirements:
|
133
162
|
- - ">="
|
134
163
|
- !ruby/object:Gem::Version
|
135
|
-
version: '
|
164
|
+
version: '2.7'
|
136
165
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
166
|
requirements:
|
138
167
|
- - ">="
|
139
168
|
- !ruby/object:Gem::Version
|
140
169
|
version: '0'
|
141
170
|
requirements: []
|
142
|
-
|
143
|
-
|
144
|
-
signing_key:
|
171
|
+
rubygems_version: 3.3.3
|
172
|
+
signing_key:
|
145
173
|
specification_version: 4
|
146
174
|
summary: SVG optimization based on Node's SVGO
|
147
175
|
test_files: []
|