svg_optimizer 0.2.0 → 0.2.1

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
2
  SHA1:
3
- metadata.gz: '060478d22f373adde47ecd8f93ab8f025875c08b'
4
- data.tar.gz: a13531444b8c1822ac928c1d71d948e9cc4d6e73
3
+ metadata.gz: 59eadfc68915559182e085a2f122874d2248fb2a
4
+ data.tar.gz: 35e56a3a5085279f4736bac7b8742d2ae677945e
5
5
  SHA512:
6
- metadata.gz: 3d73b238b60d0e323e8c6d1ca3b99e97939eb7d5b1b342900832b4cc12eb6041bd65cc650fa40f25c39a928a36d8ee47bf8bc705353e763db16fc95944e31186
7
- data.tar.gz: 5ba751b5b5818f7f027fd75e469c88d26ddf6c6609b933d79d763d3143c64041bc0c4099d6d69bb94f33440b9240a1c7583717f83734524f003e28e7a5dfe473
6
+ metadata.gz: 632f0a5d429a6f9c5f3696af63adb973034f4d4c8d9c9f78764d21916186948094d5102ed21c867161c19cfc7fa6678e8b06570727eca69cd3a576643d6d26b8
7
+ data.tar.gz: c66b98f89cf0dab885246af11ed53ab20eef217f7ce12c900964820811dc399de942531de48f73517e51c5b5c2180cd09b0f24df483f15c48394162f5a7b5697
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # SvgOptimizer
2
2
 
3
- [![Travis-CI](https://travis-ci.org/fnando/svg_optimizer.png)](https://travis-ci.org/fnando/svg_optimizer)
3
+ [![Travis-CI](https://travis-ci.org/fnando/svg_optimizer.svg)](https://travis-ci.org/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
5
  [![Test Coverage](https://codeclimate.com/github/fnando/svg_optimizer/badges/coverage.svg)](https://codeclimate.com/github/fnando/svg_optimizer/coverage)
6
6
  [![Gem](https://img.shields.io/gem/v/svg_optimizer.svg)](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 CollapseGroups < Base
6
- COLLAPSABLE_ATTRS = %w[transform class]
6
+ COLLAPSABLE_ATTRS = %w[transform class].freeze
7
7
 
8
8
  def process
9
9
  xml.css("g:not(:empty)").each do |group|
@@ -4,7 +4,7 @@ module SvgOptimizer
4
4
  module Plugins
5
5
  class RemoveDescription < Base
6
6
  def process
7
- xml.css("desc").remove
7
+ xml.xpath("//desc").remove
8
8
  end
9
9
  end
10
10
  end
@@ -17,7 +17,7 @@ module SvgOptimizer
17
17
  http://ns.adobe.com/GenericCustomNamespace/1.0/
18
18
  http://ns.adobe.com/XPath/1.0
19
19
  http://www.bohemiancoding.com/sketch/ns
20
- ]
20
+ ].freeze
21
21
 
22
22
  def process
23
23
  namespaces = xml.namespaces
@@ -5,7 +5,7 @@ module SvgOptimizer
5
5
  class RemoveEmptyAttribute < Base
6
6
  def process
7
7
  xml.xpath("//*[@*='']").each do |node|
8
- node.attributes.each do |name, value|
8
+ node.attributes.each do |name, _|
9
9
  remove_if_empty node, name
10
10
  end
11
11
  end
@@ -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,7 +4,7 @@ module SvgOptimizer
4
4
  module Plugins
5
5
  class RemoveTitle < Base
6
6
  def process
7
- xml.css("title").remove
7
+ xml.xpath("//title").remove
8
8
  end
9
9
  end
10
10
  end
@@ -4,13 +4,16 @@ module SvgOptimizer
4
4
  module Plugins
5
5
  class RemoveUnusedNamespace < Base
6
6
  def process
7
- xml.root.namespace_definitions
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 { |attr| node.delete(attr) }
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 { |attr| node.delete(attr) }
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
- return inherited_attribute(node, "stroke-width") == "0"
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
- return !fill
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SvgOptimizer
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1".freeze
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: svg_optimizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira