svg_optimizer 0.0.3 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 04c18d44c25510e630cd61ffbeef9bc5f08805ff
4
- data.tar.gz: 6487bf3266e7c8f234beaa82c1655ce4602e12c9
3
+ metadata.gz: 57b703a501df1067d13975a65831cfa8eb07e602
4
+ data.tar.gz: 48295ee163a4dcbce704d3044e84e442c7fb3957
5
5
  SHA512:
6
- metadata.gz: 127d9e70d9d298803ef8aed89c2edebeedfa9b820b2436b6894f7611267733b41a5e63667ae7ab069c402fde370c8d3f12976f955a405fc160c3d35892bf67e9
7
- data.tar.gz: 902429ee40b207e5adc5a32ba6a3c2754f04743dba41b4957e4a3ab68ed54241bcebc2d063212d9cf5cf41fbb2261ae677d0032f319cbbff2361d45e93a01f8b
6
+ metadata.gz: fc04c56579a8c2ef51015c23ebc77865ef63712f16382caf9dbde46efc148c4cb75d8d64c575a6c457baecb7a380829887718be9d44598d42b790abc9dab3d21
7
+ data.tar.gz: 26553ccf7bba878f75209ec42c64949867e8eff07bba8184af4ea3c219e358f6c4057a22a17ab0775f836c6ead457f049fa04804ef16b4707e72e4d989c6b90e
@@ -17,8 +17,27 @@ module SvgOptimizer
17
17
  http://www.bohemiancoding.com/sketch/ns
18
18
  ]
19
19
 
20
+ def namespaces_to_be_removed
21
+ xml.namespaces.map do |name, value|
22
+ _, name = name.split(":")
23
+ name if NAMESPACES.include?(value)
24
+ end.compact
25
+ end
26
+
27
+ def remove_namespaced_attributes
28
+ namespaces_to_be_removed.each do |ns|
29
+ xml.xpath("//*[@#{ns}:*]").each do |node|
30
+ node.attributes.each do |_, attr|
31
+ next unless attr.namespace
32
+ attr.remove if attr.namespace.prefix == ns
33
+ end
34
+ end
35
+ end
36
+ end
37
+
20
38
  def process
21
39
  namespaces = xml.namespaces
40
+ remove_namespaced_attributes
22
41
  xml.remove_namespaces!
23
42
 
24
43
  namespaces.each do |name, value|
@@ -1,3 +1,3 @@
1
1
  module SvgOptimizer
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -0,0 +1,10 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+ <svg width="25px" height="25px" viewBox="0 0 25 25" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sketch="http://www.bohemiancoding.com/sketch/ns">
3
+ <!-- Generator: Sketch 3.4.4 (17248) - http://www.bohemiancoding.com/sketch -->
4
+ <title>Rectangle 1</title>
5
+ <desc>Created with Sketch.</desc>
6
+ <defs></defs>
7
+ <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" sketch:type="MSPage">
8
+ <rect id="Rectangle-1" fill="#4990E2" sketch:type="MSShapeGroup" x="0" y="0" width="25" height="25"></rect>
9
+ </g>
10
+ </svg>
@@ -1,8 +1,18 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe SvgOptimizer::Plugins::RemoveEditorNamespace do
4
- with_svg_plugin ""
5
- it { expect(xml.namespaces.values).not_to include("http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd") }
6
- it { expect(xml.namespaces.values).to include("http://www.w3.org/2000/svg") }
7
- it { expect(xml.namespaces.values).to include("http://www.w3.org/1999/xlink") }
4
+ describe "root namespaces" do
5
+ with_svg_plugin ""
6
+ it { expect(xml.namespaces.values).not_to include("http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd") }
7
+ it { expect(xml.namespaces.values).to include("http://www.w3.org/2000/svg") }
8
+ it { expect(xml.namespaces.values).to include("http://www.w3.org/1999/xlink") }
9
+ end
10
+
11
+ describe "attribute namespaces" do
12
+ with_svg_plugin "namespaced_attribute.svg"
13
+ it { expect(xml.css("#Page-1").first.has_attribute?("sketch:type")).to be_falsy }
14
+ it { expect(xml.css("#Page-1").first.has_attribute?("type")).to be_falsy }
15
+ it { expect(xml.css("#Rectangle-1").first.has_attribute?("sketch:type")).to be_falsy }
16
+ it { expect(xml.css("#Rectangle-1").first.has_attribute?("type")).to be_falsy }
17
+ end
8
18
  end
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.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-10 00:00:00.000000000 Z
11
+ date: 2015-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -106,6 +106,7 @@ files:
106
106
  - spec/fixtures/cleanup_id.svg
107
107
  - spec/fixtures/cleanup_id_expected.svg
108
108
  - spec/fixtures/green.svg
109
+ - spec/fixtures/namespaced_attribute.svg
109
110
  - spec/fixtures/unused_namespace.svg
110
111
  - spec/spec_helper.rb
111
112
  - spec/svg_optimizer/plugins/cleanup_attribute_spec.rb
@@ -139,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
140
  version: '0'
140
141
  requirements: []
141
142
  rubyforge_project:
142
- rubygems_version: 2.4.5.1
143
+ rubygems_version: 2.5.1
143
144
  signing_key:
144
145
  specification_version: 4
145
146
  summary: SVG optimization based on Node's SVGO
@@ -147,6 +148,7 @@ test_files:
147
148
  - spec/fixtures/cleanup_id.svg
148
149
  - spec/fixtures/cleanup_id_expected.svg
149
150
  - spec/fixtures/green.svg
151
+ - spec/fixtures/namespaced_attribute.svg
150
152
  - spec/fixtures/unused_namespace.svg
151
153
  - spec/spec_helper.rb
152
154
  - spec/svg_optimizer/plugins/cleanup_attribute_spec.rb
@@ -160,4 +162,3 @@ test_files:
160
162
  - spec/svg_optimizer/plugins/remove_metadata_spec.rb
161
163
  - spec/svg_optimizer/plugins/remove_raster_image_spec.rb
162
164
  - spec/svg_optimizer/plugins/remove_unused_namespace_spec.rb
163
- has_rdoc: