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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 252e3ad0e74992fe85def8ef8d749d2f55975b6a
4
- data.tar.gz: 0ab2451d8cf7ee5ec69a0cf6462adcba953575e2
2
+ SHA256:
3
+ metadata.gz: 385024a89793a95b04290dbea791b71007a8d27387a02939865f4ed6f2528c72
4
+ data.tar.gz: 8e1e9581f7516362b09bc2221a889043e3ae1b1ad442e73a7b178be26e3e1d8b
5
5
  SHA512:
6
- metadata.gz: bfd401c30de6a280c6daddc788678f8635f0e179b7119ddc9ead993dbfbd0d08d70c30cf61153a6a6e7ff224dbdfd8b336c0027c65cbb916b8d115e262d966e6
7
- data.tar.gz: 0db71a133efeaa39992777d7a34fd4c1c309afafb4367fa1b9741fa73af26f4755cdb834ee3f2e8f80948794bf03f3190397e0a24e9e34e6e8395fffca9292a2
6
+ metadata.gz: 699299880bf18dab73133899f59dcfa541a46ab45f3f0d2aeb48eb478caec60bdc2ce07c5093b5ab99e6c09118a966fa1009ba656ac7db0ef768a22a54774222
7
+ data.tar.gz: 1862ba8ad388c1523d7e69ff2e139efef59e4d3ede808d6ac9cabfd112c94b35a706563b1efaf10302386acce25812b02ba2b33ba3a2ab3bb45dc459963748d8
File without changes
data/README.md CHANGED
@@ -1,8 +1,7 @@
1
1
  # SvgOptimizer
2
2
 
3
- [![Travis-CI](https://travis-ci.org/fnando/svg_optimizer.svg)](https://travis-ci.org/fnando/svg_optimizer)
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
- Add this line to your application's Gemfile:
14
-
15
- gem 'svg_optimizer'
16
-
17
- And then execute:
18
-
19
- $ bundle
12
+ ```bash
13
+ gem install svg_optimizer
14
+ ```
20
15
 
21
- Or install it yourself as:
16
+ Or add the following line to your project's Gemfile:
22
17
 
23
- $ gem install svg_optimizer
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 your new plugin, just do something like this:
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
- 1. Fork it
65
- 2. Create your feature branch (`git checkout -b my-new-feature`)
66
- 3. Commit your changes (`git commit -am 'Add some feature'`)
67
- 4. Push to the branch (`git push origin my-new-feature`)
68
- 5. Create new Pull Request
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).
@@ -9,7 +9,7 @@ module SvgOptimizer
9
9
  ].freeze
10
10
 
11
11
  IDS = LETTERS.dup.concat(LETTERS.combination(2).to_a).freeze
12
- XLINK_NAMESPACE = "http://www.w3.org/1999/xlink".freeze
12
+ XLINK_NAMESPACE = "http://www.w3.org/1999/xlink"
13
13
 
14
14
  def ids
15
15
  @ids ||= IDS.dup
@@ -50,6 +50,7 @@ module SvgOptimizer
50
50
  def remove_matching_attribute(node, name)
51
51
  node.attributes.each do |_, attr|
52
52
  next unless attr.namespace
53
+
53
54
  attr.remove if attr.namespace.prefix == name
54
55
  end
55
56
  end
@@ -11,9 +11,7 @@ module SvgOptimizer
11
11
  end
12
12
  end
13
13
 
14
- private
15
-
16
- def remove_if_empty(node, attr)
14
+ private def remove_if_empty(node, attr)
17
15
  node.remove_attribute(attr) if node[attr].empty?
18
16
  end
19
17
  end
@@ -3,7 +3,17 @@
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].freeze
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
@@ -7,9 +7,7 @@ module SvgOptimizer
7
7
  xml.xpath("//text()").each(&method(:remove_if_empty))
8
8
  end
9
9
 
10
- private
11
-
12
- def remove_if_empty(node)
10
+ private def remove_if_empty(node)
13
11
  node.remove if node.text.gsub(/\s/, "").empty?
14
12
  end
15
13
  end
@@ -4,7 +4,7 @@ module SvgOptimizer
4
4
  module Plugins
5
5
  class RemoveTitle < Base
6
6
  def process
7
- xml.xpath("//title").remove
7
+ xml.css("title").remove
8
8
  end
9
9
  end
10
10
  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[stroke stroke-opacity stroke-width stroke-dashoffset].freeze
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SvgOptimizer
4
- VERSION = "0.2.5".freeze
4
+ VERSION = "0.2.6"
5
5
  end
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.5
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: 2017-10-04 00:00:00.000000000 Z
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: rake
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: minitest-utils
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.txt
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
- post_install_message:
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: '0'
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
- rubyforge_project:
143
- rubygems_version: 2.6.13
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: []