svg_optimizer 0.1.0 → 0.2.0

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.

Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/lib/svg_optimizer.rb +5 -0
  3. data/lib/svg_optimizer/plugins/base.rb +1 -0
  4. data/lib/svg_optimizer/plugins/cleanup_attribute.rb +1 -0
  5. data/lib/svg_optimizer/plugins/cleanup_id.rb +1 -0
  6. data/lib/svg_optimizer/plugins/collapse_groups.rb +1 -0
  7. data/lib/svg_optimizer/plugins/remove_comment.rb +1 -0
  8. data/lib/svg_optimizer/plugins/remove_description.rb +11 -0
  9. data/lib/svg_optimizer/plugins/remove_editor_namespace.rb +1 -0
  10. data/lib/svg_optimizer/plugins/remove_empty_attribute.rb +1 -0
  11. data/lib/svg_optimizer/plugins/remove_empty_container.rb +1 -0
  12. data/lib/svg_optimizer/plugins/remove_empty_text_node.rb +1 -0
  13. data/lib/svg_optimizer/plugins/remove_hidden_element.rb +1 -0
  14. data/lib/svg_optimizer/plugins/remove_metadata.rb +1 -0
  15. data/lib/svg_optimizer/plugins/remove_raster_image.rb +1 -0
  16. data/lib/svg_optimizer/plugins/remove_title.rb +11 -0
  17. data/lib/svg_optimizer/plugins/remove_unused_namespace.rb +1 -0
  18. data/lib/svg_optimizer/plugins/remove_useless_stroke_and_fill.rb +1 -0
  19. data/lib/svg_optimizer/version.rb +2 -1
  20. metadata +8 -74
  21. data/spec/fixtures/cleanup_id.svg +0 -18
  22. data/spec/fixtures/cleanup_id_expected.svg +0 -18
  23. data/spec/fixtures/collapse_groups/collapseGroups.01.svg +0 -13
  24. data/spec/fixtures/collapse_groups/collapseGroups.02.svg +0 -13
  25. data/spec/fixtures/collapse_groups/collapseGroups.03.svg +0 -13
  26. data/spec/fixtures/collapse_groups/collapseGroups.04.svg +0 -17
  27. data/spec/fixtures/collapse_groups/collapseGroups.05.svg +0 -17
  28. data/spec/fixtures/collapse_groups/collapseGroups.06.svg +0 -17
  29. data/spec/fixtures/collapse_groups/collapseGroups.07.svg +0 -17
  30. data/spec/fixtures/collapse_groups/collapseGroups.08.svg +0 -25
  31. data/spec/fixtures/collapse_groups/collapseGroups.09.svg +0 -35
  32. data/spec/fixtures/collapse_groups/collapseGroups.10.svg +0 -19
  33. data/spec/fixtures/collapse_groups/collapseGroups.11.svg +0 -29
  34. data/spec/fixtures/green.svg +0 -37
  35. data/spec/fixtures/namespaced_attribute.svg +0 -10
  36. data/spec/fixtures/remove_useless_stroke_and_fill/removeUselessStrokeAndFill.01.svg +0 -41
  37. data/spec/fixtures/remove_useless_stroke_and_fill/removeUselessStrokeAndFill.02.svg +0 -31
  38. data/spec/fixtures/remove_useless_stroke_and_fill/removeUselessStrokeAndFill.03.svg +0 -21
  39. data/spec/fixtures/unused_namespace.svg +0 -13
  40. data/spec/spec_helper.rb +0 -61
  41. data/spec/svg_optimizer/plugins/cleanup_attribute_spec.rb +0 -7
  42. data/spec/svg_optimizer/plugins/cleanup_id_spec.rb +0 -13
  43. data/spec/svg_optimizer/plugins/collapse_groups_spec.rb +0 -6
  44. data/spec/svg_optimizer/plugins/remove_comment_spec.rb +0 -12
  45. data/spec/svg_optimizer/plugins/remove_editor_namespace_spec.rb +0 -19
  46. data/spec/svg_optimizer/plugins/remove_empty_attribute_spec.rb +0 -12
  47. data/spec/svg_optimizer/plugins/remove_empty_container_spec.rb +0 -9
  48. data/spec/svg_optimizer/plugins/remove_empty_text_node_spec.rb +0 -14
  49. data/spec/svg_optimizer/plugins/remove_hidden_element_spec.rb +0 -82
  50. data/spec/svg_optimizer/plugins/remove_metadata_spec.rb +0 -12
  51. data/spec/svg_optimizer/plugins/remove_raster_image_spec.rb +0 -15
  52. data/spec/svg_optimizer/plugins/remove_unused_namespace_spec.rb +0 -19
  53. data/spec/svg_optimizer/plugins/remove_useless_stroke_and_fill_spec.rb +0 -6
  54. data/spec/svg_optimizer/svg_optimizer_spec.rb +0 -54
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e80d8684aae3105745cd84db8c935a332bc58b02
4
- data.tar.gz: 698bc37343bf931cea862afb939cd0a45547208b
3
+ metadata.gz: '060478d22f373adde47ecd8f93ab8f025875c08b'
4
+ data.tar.gz: a13531444b8c1822ac928c1d71d948e9cc4d6e73
5
5
  SHA512:
6
- metadata.gz: 1d4bf32d76d719e774137c9a00231de35caaed49d4a7f970606f9f6e58b2729bbae67708df72719ac31a008c29bdbd3b0c3548fe6d54e6dd8a9f7bb888eacddf
7
- data.tar.gz: 28a362b536013a61c426e0ccc3e3fc6d1f9674e9e011cfe50772e22d5aab954904925fb9209714e950556aef3700ab91cee876c0b634fae207b36ed3cd201a80
6
+ metadata.gz: 3d73b238b60d0e323e8c6d1ca3b99e97939eb7d5b1b342900832b4cc12eb6041bd65cc650fa40f25c39a928a36d8ee47bf8bc705353e763db16fc95944e31186
7
+ data.tar.gz: 5ba751b5b5818f7f027fd75e469c88d26ddf6c6609b933d79d763d3143c64041bc0c4099d6d69bb94f33440b9240a1c7583717f83734524f003e28e7a5dfe473
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "nokogiri"
3
4
 
4
5
  require "svg_optimizer/version"
@@ -16,6 +17,8 @@ require "svg_optimizer/plugins/remove_raster_image"
16
17
  require "svg_optimizer/plugins/remove_empty_attribute"
17
18
  require "svg_optimizer/plugins/remove_unused_namespace"
18
19
  require "svg_optimizer/plugins/remove_useless_stroke_and_fill"
20
+ require "svg_optimizer/plugins/remove_title"
21
+ require "svg_optimizer/plugins/remove_description"
19
22
 
20
23
  module SvgOptimizer
21
24
  DEFAULT_PLUGINS = %w[
@@ -32,6 +35,8 @@ module SvgOptimizer
32
35
  RemoveUselessStrokeAndFill
33
36
  RemoveEmptyTextNode
34
37
  RemoveEmptyContainer
38
+ RemoveTitle
39
+ RemoveDescription
35
40
  ].map {|name| Plugins.const_get(name) }
36
41
 
37
42
  def self.optimize(contents, plugins = DEFAULT_PLUGINS)
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module SvgOptimizer
3
4
  module Plugins
4
5
  class Base
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module SvgOptimizer
3
4
  module Plugins
4
5
  class CleanupAttribute < Base
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module SvgOptimizer
3
4
  module Plugins
4
5
  class CleanupId < Base
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module SvgOptimizer
3
4
  module Plugins
4
5
  class CollapseGroups < Base
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module SvgOptimizer
3
4
  module Plugins
4
5
  class RemoveComment < Base
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SvgOptimizer
4
+ module Plugins
5
+ class RemoveDescription < Base
6
+ def process
7
+ xml.css("desc").remove
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module SvgOptimizer
3
4
  module Plugins
4
5
  class RemoveEditorNamespace < Base
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module SvgOptimizer
3
4
  module Plugins
4
5
  class RemoveEmptyAttribute < Base
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module SvgOptimizer
3
4
  module Plugins
4
5
  class RemoveEmptyContainer < Base
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module SvgOptimizer
3
4
  module Plugins
4
5
  class RemoveEmptyTextNode < Base
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module SvgOptimizer
3
4
  module Plugins
4
5
  class RemoveHiddenElement < Base
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module SvgOptimizer
3
4
  module Plugins
4
5
  class RemoveMetadata < Base
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module SvgOptimizer
3
4
  module Plugins
4
5
  class RemoveRasterImage < Base
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SvgOptimizer
4
+ module Plugins
5
+ class RemoveTitle < Base
6
+ def process
7
+ xml.css("title").remove
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module SvgOptimizer
3
4
  module Plugins
4
5
  class RemoveUnusedNamespace < Base
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module SvgOptimizer
3
4
  module Plugins
4
5
  class RemoveUselessStrokeAndFill < Base
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module SvgOptimizer
3
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
4
5
  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.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-23 00:00:00.000000000 Z
11
+ date: 2017-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -67,7 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: rspec
70
+ name: minitest-utils
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
@@ -81,7 +81,7 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: codeclimate-test-reporter
84
+ name: simplecov
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
@@ -109,6 +109,7 @@ files:
109
109
  - lib/svg_optimizer/plugins/cleanup_id.rb
110
110
  - lib/svg_optimizer/plugins/collapse_groups.rb
111
111
  - lib/svg_optimizer/plugins/remove_comment.rb
112
+ - lib/svg_optimizer/plugins/remove_description.rb
112
113
  - lib/svg_optimizer/plugins/remove_editor_namespace.rb
113
114
  - lib/svg_optimizer/plugins/remove_empty_attribute.rb
114
115
  - lib/svg_optimizer/plugins/remove_empty_container.rb
@@ -116,43 +117,10 @@ files:
116
117
  - lib/svg_optimizer/plugins/remove_hidden_element.rb
117
118
  - lib/svg_optimizer/plugins/remove_metadata.rb
118
119
  - lib/svg_optimizer/plugins/remove_raster_image.rb
120
+ - lib/svg_optimizer/plugins/remove_title.rb
119
121
  - lib/svg_optimizer/plugins/remove_unused_namespace.rb
120
122
  - lib/svg_optimizer/plugins/remove_useless_stroke_and_fill.rb
121
123
  - lib/svg_optimizer/version.rb
122
- - spec/fixtures/cleanup_id.svg
123
- - spec/fixtures/cleanup_id_expected.svg
124
- - spec/fixtures/collapse_groups/collapseGroups.01.svg
125
- - spec/fixtures/collapse_groups/collapseGroups.02.svg
126
- - spec/fixtures/collapse_groups/collapseGroups.03.svg
127
- - spec/fixtures/collapse_groups/collapseGroups.04.svg
128
- - spec/fixtures/collapse_groups/collapseGroups.05.svg
129
- - spec/fixtures/collapse_groups/collapseGroups.06.svg
130
- - spec/fixtures/collapse_groups/collapseGroups.07.svg
131
- - spec/fixtures/collapse_groups/collapseGroups.08.svg
132
- - spec/fixtures/collapse_groups/collapseGroups.09.svg
133
- - spec/fixtures/collapse_groups/collapseGroups.10.svg
134
- - spec/fixtures/collapse_groups/collapseGroups.11.svg
135
- - spec/fixtures/green.svg
136
- - spec/fixtures/namespaced_attribute.svg
137
- - spec/fixtures/remove_useless_stroke_and_fill/removeUselessStrokeAndFill.01.svg
138
- - spec/fixtures/remove_useless_stroke_and_fill/removeUselessStrokeAndFill.02.svg
139
- - spec/fixtures/remove_useless_stroke_and_fill/removeUselessStrokeAndFill.03.svg
140
- - spec/fixtures/unused_namespace.svg
141
- - spec/spec_helper.rb
142
- - spec/svg_optimizer/plugins/cleanup_attribute_spec.rb
143
- - spec/svg_optimizer/plugins/cleanup_id_spec.rb
144
- - spec/svg_optimizer/plugins/collapse_groups_spec.rb
145
- - spec/svg_optimizer/plugins/remove_comment_spec.rb
146
- - spec/svg_optimizer/plugins/remove_editor_namespace_spec.rb
147
- - spec/svg_optimizer/plugins/remove_empty_attribute_spec.rb
148
- - spec/svg_optimizer/plugins/remove_empty_container_spec.rb
149
- - spec/svg_optimizer/plugins/remove_empty_text_node_spec.rb
150
- - spec/svg_optimizer/plugins/remove_hidden_element_spec.rb
151
- - spec/svg_optimizer/plugins/remove_metadata_spec.rb
152
- - spec/svg_optimizer/plugins/remove_raster_image_spec.rb
153
- - spec/svg_optimizer/plugins/remove_unused_namespace_spec.rb
154
- - spec/svg_optimizer/plugins/remove_useless_stroke_and_fill_spec.rb
155
- - spec/svg_optimizer/svg_optimizer_spec.rb
156
124
  homepage: https://github.com/fnando/svg_optimizer
157
125
  licenses:
158
126
  - MIT
@@ -173,42 +141,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
173
141
  version: '0'
174
142
  requirements: []
175
143
  rubyforge_project:
176
- rubygems_version: 2.5.1
144
+ rubygems_version: 2.6.13
177
145
  signing_key:
178
146
  specification_version: 4
179
147
  summary: SVG optimization based on Node's SVGO
180
- test_files:
181
- - spec/fixtures/cleanup_id.svg
182
- - spec/fixtures/cleanup_id_expected.svg
183
- - spec/fixtures/collapse_groups/collapseGroups.01.svg
184
- - spec/fixtures/collapse_groups/collapseGroups.02.svg
185
- - spec/fixtures/collapse_groups/collapseGroups.03.svg
186
- - spec/fixtures/collapse_groups/collapseGroups.04.svg
187
- - spec/fixtures/collapse_groups/collapseGroups.05.svg
188
- - spec/fixtures/collapse_groups/collapseGroups.06.svg
189
- - spec/fixtures/collapse_groups/collapseGroups.07.svg
190
- - spec/fixtures/collapse_groups/collapseGroups.08.svg
191
- - spec/fixtures/collapse_groups/collapseGroups.09.svg
192
- - spec/fixtures/collapse_groups/collapseGroups.10.svg
193
- - spec/fixtures/collapse_groups/collapseGroups.11.svg
194
- - spec/fixtures/green.svg
195
- - spec/fixtures/namespaced_attribute.svg
196
- - spec/fixtures/remove_useless_stroke_and_fill/removeUselessStrokeAndFill.01.svg
197
- - spec/fixtures/remove_useless_stroke_and_fill/removeUselessStrokeAndFill.02.svg
198
- - spec/fixtures/remove_useless_stroke_and_fill/removeUselessStrokeAndFill.03.svg
199
- - spec/fixtures/unused_namespace.svg
200
- - spec/spec_helper.rb
201
- - spec/svg_optimizer/plugins/cleanup_attribute_spec.rb
202
- - spec/svg_optimizer/plugins/cleanup_id_spec.rb
203
- - spec/svg_optimizer/plugins/collapse_groups_spec.rb
204
- - spec/svg_optimizer/plugins/remove_comment_spec.rb
205
- - spec/svg_optimizer/plugins/remove_editor_namespace_spec.rb
206
- - spec/svg_optimizer/plugins/remove_empty_attribute_spec.rb
207
- - spec/svg_optimizer/plugins/remove_empty_container_spec.rb
208
- - spec/svg_optimizer/plugins/remove_empty_text_node_spec.rb
209
- - spec/svg_optimizer/plugins/remove_hidden_element_spec.rb
210
- - spec/svg_optimizer/plugins/remove_metadata_spec.rb
211
- - spec/svg_optimizer/plugins/remove_raster_image_spec.rb
212
- - spec/svg_optimizer/plugins/remove_unused_namespace_spec.rb
213
- - spec/svg_optimizer/plugins/remove_useless_stroke_and_fill_spec.rb
214
- - spec/svg_optimizer/svg_optimizer_spec.rb
148
+ test_files: []
@@ -1,18 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
2
- <defs>
3
- <linearGradient id="gradient001">
4
- <stop offset="5%" stop-color="#F60"/>
5
- <stop offset="95%" stop-color="#FF6"/>
6
- </linearGradient>
7
- <text id="referencedText">
8
- referenced text
9
- </text>
10
- </defs>
11
- <g id="g001">
12
- <circle id="circle001" fill="url(#gradient001)" cx="60" cy="60" r="50"/>
13
- <tref xlink:href="#referencedText"/>
14
- </g>
15
- <g>
16
- <tref xlink:href="#referencedText"/>
17
- </g>
18
- </svg>
@@ -1,18 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
2
- <defs>
3
- <linearGradient id="a">
4
- <stop offset="5%" stop-color="#F60"/>
5
- <stop offset="95%" stop-color="#FF6"/>
6
- </linearGradient>
7
- <text id="b">
8
- referenced text
9
- </text>
10
- </defs>
11
- <g>
12
- <circle fill="url(#a)" cx="60" cy="60" r="50"/>
13
- <tref xlink:href="#b"/>
14
- </g>
15
- <g>
16
- <tref xlink:href="#b"/>
17
- </g>
18
- </svg>
@@ -1,13 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg">
2
- <g>
3
- <g>
4
- <path d="..."/>
5
- </g>
6
- </g>
7
- </svg>
8
-
9
- @@@
10
-
11
- <svg xmlns="http://www.w3.org/2000/svg">
12
- <path d="..."/>
13
- </svg>
@@ -1,13 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg">
2
- <g>
3
- <g attr1="val1">
4
- <path d="..."/>
5
- </g>
6
- </g>
7
- </svg>
8
-
9
- @@@
10
-
11
- <svg xmlns="http://www.w3.org/2000/svg">
12
- <path d="..." attr1="val1"/>
13
- </svg>
@@ -1,13 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg">
2
- <g attr1="val1">
3
- <g attr2="val2">
4
- <path d="..."/>
5
- </g>
6
- </g>
7
- </svg>
8
-
9
- @@@
10
-
11
- <svg xmlns="http://www.w3.org/2000/svg">
12
- <path d="..." attr2="val2" attr1="val1"/>
13
- </svg>
@@ -1,17 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg">
2
- <g attr1="val1">
3
- <g>
4
- <path d="..."/>
5
- </g>
6
- <path d="..."/>
7
- </g>
8
- </svg>
9
-
10
- @@@
11
-
12
- <svg xmlns="http://www.w3.org/2000/svg">
13
- <g attr1="val1">
14
- <path d="..."/>
15
- <path d="..."/>
16
- </g>
17
- </svg>
@@ -1,17 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg">
2
- <g attr1="val1">
3
- <g attr2="val2">
4
- <path d="..."/>
5
- </g>
6
- <path d="..."/>
7
- </g>
8
- </svg>
9
-
10
- @@@
11
-
12
- <svg xmlns="http://www.w3.org/2000/svg">
13
- <g attr1="val1">
14
- <path d="..." attr2="val2"/>
15
- <path d="..."/>
16
- </g>
17
- </svg>
@@ -1,17 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg">
2
- <g attr1="val1">
3
- <g attr2="val2">
4
- <path attr2="val3" d="..."/>
5
- </g>
6
- <path d="..."/>
7
- </g>
8
- </svg>
9
-
10
- @@@
11
-
12
- <svg xmlns="http://www.w3.org/2000/svg">
13
- <g attr1="val1">
14
- <path attr2="val3" d="..."/>
15
- <path d="..."/>
16
- </g>
17
- </svg>
@@ -1,17 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg">
2
- <g attr1="val1">
3
- <g transform="rotate(45)">
4
- <path transform="scale(2)" d="..."/>
5
- </g>
6
- <path d="..."/>
7
- </g>
8
- </svg>
9
-
10
- @@@
11
-
12
- <svg xmlns="http://www.w3.org/2000/svg">
13
- <g attr1="val1">
14
- <path transform="rotate(45) scale(2)" d="..."/>
15
- <path d="..."/>
16
- </g>
17
- </svg>
@@ -1,25 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg">
2
- <clipPath id="a">
3
- <path d="..."/>
4
- </clipPath>
5
- <g transform="matrix(0 -1.25 -1.25 0 100 100)" clip-path="url(#a)">
6
- <g transform="scale(.2)">
7
- <path d="..."/>
8
- <path d="..."/>
9
- </g>
10
- </g>
11
- </svg>
12
-
13
- @@@
14
-
15
- <svg xmlns="http://www.w3.org/2000/svg">
16
- <clipPath id="a">
17
- <path d="..."/>
18
- </clipPath>
19
- <g transform="matrix(0 -1.25 -1.25 0 100 100)" clip-path="url(#a)">
20
- <g transform="scale(.2)">
21
- <path d="..."/>
22
- <path d="..."/>
23
- </g>
24
- </g>
25
- </svg>
@@ -1,35 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg">
2
- <clipPath id="a">
3
- <path d="..."/>
4
- </clipPath>
5
- <clipPath id="b">
6
- <path d="..."/>
7
- </clipPath>
8
- <g transform="matrix(0 -1.25 -1.25 0 100 100)" clip-path="url(#a)">
9
- <g transform="scale(.2)">
10
- <g>
11
- <g clip-path="url(#b)">
12
- <path d="..."/>
13
- <path d="..."/>
14
- </g>
15
- </g>
16
- </g>
17
- </g>
18
- </svg>
19
-
20
- @@@
21
-
22
- <svg xmlns="http://www.w3.org/2000/svg">
23
- <clipPath id="a">
24
- <path d="..."/>
25
- </clipPath>
26
- <clipPath id="b">
27
- <path d="..."/>
28
- </clipPath>
29
- <g transform="matrix(0 -1.25 -1.25 0 100 100)" clip-path="url(#a)">
30
- <g clip-path="url(#b)" transform="scale(.2)">
31
- <path d="..."/>
32
- <path d="..."/>
33
- </g>
34
- </g>
35
- </svg>
@@ -1,19 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg">
2
- <clipPath id="a">
3
- <path d="..."/>
4
- </clipPath>
5
- <g clip-path="url(#a)">
6
- <path d="..." transform="scale(.2)"/>
7
- </g>
8
- </svg>
9
-
10
- @@@
11
-
12
- <svg xmlns="http://www.w3.org/2000/svg">
13
- <clipPath id="a">
14
- <path d="..."/>
15
- </clipPath>
16
- <g clip-path="url(#a)">
17
- <path d="..." transform="scale(.2)"/>
18
- </g>
19
- </svg>
@@ -1,29 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg">
2
- <g stroke="#000">
3
- <g id="star">
4
- <path id="bar" d="..."/>
5
- </g>
6
- </g>
7
- <g>
8
- <animate id="frame0" attributeName="visibility" values="visible" dur="33ms" begin="0s;frame27.end"/>
9
- <path d="..." fill="#272727"/>
10
- <path d="..." fill="#404040"/>
11
- <path d="..." fill="#2d2d2d"/>
12
- </g>
13
- </svg>
14
-
15
- @@@
16
-
17
- <svg xmlns="http://www.w3.org/2000/svg">
18
- <g stroke="#000">
19
- <g id="star">
20
- <path id="bar" d="..."/>
21
- </g>
22
- </g>
23
- <g>
24
- <animate id="frame0" attributeName="visibility" values="visible" dur="33ms" begin="0s;frame27.end"/>
25
- <path d="..." fill="#272727"/>
26
- <path d="..." fill="#404040"/>
27
- <path d="..." fill="#2d2d2d"/>
28
- </g>
29
- </svg>
@@ -1,37 +0,0 @@
1
- <?xml version="1.0" encoding="utf-8"?>
2
- <!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
3
- <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
4
- <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
5
- width="10px" height="10px" viewBox="0 0 10 10" enable-background="new 0 0 10 10" xml:space="preserve">
6
- <rect fill="#39B54A" width="10" height="10"/>
7
- <g>
8
- </g>
9
- <g>
10
- </g>
11
- <g>
12
- </g>
13
- <g>
14
- </g>
15
- <g>
16
- </g>
17
- <g>
18
- </g>
19
- <g>
20
- </g>
21
- <g>
22
- </g>
23
- <g>
24
- </g>
25
- <g>
26
- </g>
27
- <g>
28
- </g>
29
- <g>
30
- </g>
31
- <g>
32
- </g>
33
- <g>
34
- </g>
35
- <g>
36
- </g>
37
- </svg>
@@ -1,10 +0,0 @@
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,41 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg">
2
- <defs>
3
- <g id="test">
4
- <rect stroke-dashoffset="5" width="100" height="100"/>
5
- </g>
6
- </defs>
7
- <circle fill="red" stroke-width="6" stroke-dashoffset="5" cx="60" cy="60" r="50"/>
8
- <circle fill="red" stroke="#000" stroke-width="6" stroke-dashoffset="5" stroke-opacity="0" cx="60" cy="60" r="50"/>
9
- <circle fill="red" stroke="#000" stroke-width="0" stroke-dashoffset="5" cx="60" cy="60" r="50"/>
10
- <circle fill="red" stroke="#000" stroke-width="6" stroke-dashoffset="5" cx="60" cy="60" r="50"/>
11
- <g stroke="#000" stroke-width="6">
12
- <circle fill="red" stroke="red" stroke-width="0" stroke-dashoffset="5" cx="60" cy="60" r="50"/>
13
- <circle fill="red" stroke-dashoffset="5" cx="60" cy="60" r="50"/>
14
- </g>
15
- <g stroke="#000">
16
- <circle fill="red" stroke-width="0" stroke-dashoffset="5" cx="60" cy="60" r="50"/>
17
- <circle fill="red" stroke="none" stroke-dashoffset="5" cx="60" cy="60" r="50"/>
18
- </g>
19
- </svg>
20
-
21
- @@@
22
-
23
- <svg xmlns="http://www.w3.org/2000/svg">
24
- <defs>
25
- <g id="test">
26
- <rect stroke-dashoffset="5" width="100" height="100"/>
27
- </g>
28
- </defs>
29
- <circle fill="red" cx="60" cy="60" r="50"/>
30
- <circle fill="red" cx="60" cy="60" r="50"/>
31
- <circle fill="red" cx="60" cy="60" r="50"/>
32
- <circle fill="red" stroke="#000" stroke-width="6" stroke-dashoffset="5" cx="60" cy="60" r="50"/>
33
- <g stroke="#000" stroke-width="6">
34
- <circle fill="red" cx="60" cy="60" r="50" stroke="none"/>
35
- <circle fill="red" stroke-dashoffset="5" cx="60" cy="60" r="50"/>
36
- </g>
37
- <g stroke="#000">
38
- <circle fill="red" cx="60" cy="60" r="50" stroke="none"/>
39
- <circle fill="red" cx="60" cy="60" r="50" stroke="none"/>
40
- </g>
41
- </svg>
@@ -1,31 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg">
2
- <defs>
3
- <g id="test">
4
- <rect fill-opacity=".5" width="100" height="100"/>
5
- </g>
6
- </defs>
7
- <circle fill="none" fill-rule="evenodd" cx="60" cy="60" r="50"/>
8
- <circle fill="red" fill-opacity="0" cx="90" cy="90" r="50"/>
9
- <circle fill-opacity="0" fill-rule="evenodd" cx="90" cy="60" r="50"/>
10
- <circle fill="red" fill-opacity=".5" cx="60" cy="60" r="50"/>
11
- <g fill="none">
12
- <circle fill-opacity=".5" cx="60" cy="60" r="50"/>
13
- </g>
14
- </svg>
15
-
16
- @@@
17
-
18
- <svg xmlns="http://www.w3.org/2000/svg">
19
- <defs>
20
- <g id="test">
21
- <rect fill-opacity=".5" width="100" height="100"/>
22
- </g>
23
- </defs>
24
- <circle fill="none" cx="60" cy="60" r="50"/>
25
- <circle fill="none" cx="90" cy="90" r="50"/>
26
- <circle cx="90" cy="60" r="50" fill="none"/>
27
- <circle fill="red" fill-opacity=".5" cx="60" cy="60" r="50"/>
28
- <g fill="none">
29
- <circle cx="60" cy="60" r="50"/>
30
- </g>
31
- </svg>
@@ -1,21 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg">
2
- <style>
3
-
4
- </style>
5
- <circle fill="none" fill-rule="evenodd" cx="60" cy="60" r="50"/>
6
- <circle fill-opacity="0" fill-rule="evenodd" cx="90" cy="60" r="50"/>
7
- <circle fill="red" stroke-width="6" stroke-dashoffset="5" cx="60" cy="60" r="50"/>
8
- <circle fill="red" stroke="#000" stroke-width="6" stroke-dashoffset="5" stroke-opacity="0" cx="60" cy="60" r="50"/>
9
- </svg>
10
-
11
- @@@
12
-
13
- <svg xmlns="http://www.w3.org/2000/svg">
14
- <style>
15
-
16
- </style>
17
- <circle fill="none" fill-rule="evenodd" cx="60" cy="60" r="50"/>
18
- <circle fill-opacity="0" fill-rule="evenodd" cx="90" cy="60" r="50"/>
19
- <circle fill="red" stroke-width="6" stroke-dashoffset="5" cx="60" cy="60" r="50"/>
20
- <circle fill="red" stroke="#000" stroke-width="6" stroke-dashoffset="5" stroke-opacity="0" cx="60" cy="60" r="50"/>
21
- </svg>
@@ -1,13 +0,0 @@
1
- <svg
2
- xmlns="http://www.w3.org/2000/svg"
3
- xmlns:test="http://example.com/"
4
- xmlns:test2="http://example2.com/"
5
- xmlns:test3="http://example3.com/"
6
- xmlns:test4="http://example4.com/"
7
- >
8
- <test:elem>
9
- <test2:elem>
10
- test
11
- </test2:elem>
12
- </test:elem>
13
- </svg>
@@ -1,61 +0,0 @@
1
- # frozen_string_literal: true
2
- require "codeclimate-test-reporter"
3
- CodeClimate::TestReporter.start
4
-
5
- require "bundler/setup"
6
- require "svg_optimizer"
7
- require "securerandom"
8
-
9
- module RSpecHelpers
10
- SVG = <<-XML
11
- <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
12
- "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
13
- <?xml version="1.0" encoding="utf-8"?>
14
- <svg xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
15
- %s
16
- </svg>
17
- XML
18
-
19
- def build_svg(content)
20
- SVG % content
21
- end
22
-
23
- def fixtures_path
24
- File.expand_path("../fixtures", __FILE__)
25
- end
26
-
27
- def setup_plugin_test
28
- let(:input_xml) { Nokogiri::XML(input_content, &:noblanks) }
29
- let(:plugin) { described_class.new(input_xml) }
30
- let(:xml) { plugin.xml }
31
- before { plugin.process }
32
- end
33
-
34
- def with_svg_plugin(content)
35
- let(:file_path) { File.join(fixtures_path, content) }
36
- let(:input_content) { File.file?(file_path) ? File.read(file_path) : build_svg(content) }
37
- setup_plugin_test
38
- end
39
-
40
- def test_with_fixture_set(name)
41
- Dir.glob(File.join(fixtures_path, name, "*.svg")).each do |fixture|
42
- context "output from fixture: #{fixture}" do
43
- let(:fixture_content) { File.read(fixture) }
44
- let(:input_content) { fixture_content.split("@@@")[0].strip }
45
- let(:expected_content) { fixture_content.split("@@@")[1].strip }
46
- let(:expected) { Nokogiri::XML(expected_content, &:noblanks).root.to_xml }
47
- subject { xml.root.to_xml }
48
- setup_plugin_test
49
-
50
- it { is_expected.to eq(expected) }
51
- end
52
- end
53
- end
54
-
55
- end
56
-
57
- RSpec.configure do |config|
58
- config.order = "random"
59
- config.extend RSpecHelpers
60
- config.include RSpecHelpers
61
- end
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
- require "spec_helper"
3
-
4
- describe SvgOptimizer::Plugins::CleanupAttribute do
5
- with_svg_plugin %[<g a="b \n\t\tc"/>]
6
- it { expect(xml.css("g").first["a"]).to eql("b c") }
7
- end
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
- require "spec_helper"
3
-
4
- describe SvgOptimizer::Plugins::CleanupId do
5
- with_svg_plugin "cleanup_id.svg"
6
-
7
- it { expect(xml.css("linearGradient").first["id"]).to eql("a") }
8
- it { expect(xml.css("circle").first["fill"]).to eql("url(#a)") }
9
- it { expect(xml.css("circle[id]")).to be_empty }
10
- it { expect(xml.css("g[id]")).to be_empty }
11
- it { expect(xml.css("tref[xlink|href='#b']").size).to eql(2) }
12
- it { expect(xml.css("text").first["id"]).to eql("b") }
13
- end
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
- require "spec_helper"
3
-
4
- describe SvgOptimizer::Plugins::CollapseGroups do
5
- test_with_fixture_set("collapse_groups")
6
- end
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
- require "spec_helper"
3
-
4
- describe SvgOptimizer::Plugins::RemoveComment do
5
- with_svg_plugin <<-SVG
6
- <!-- foo -->
7
- <g></g>
8
- <!-- bar -->
9
- SVG
10
-
11
- it { expect(xml.xpath("//comment()")).to be_empty }
12
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
- require "spec_helper"
3
-
4
- describe SvgOptimizer::Plugins::RemoveEditorNamespace do
5
- describe "root namespaces" do
6
- with_svg_plugin ""
7
- it { expect(xml.namespaces.values).not_to include("http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd") }
8
- it { expect(xml.namespaces.values).to include("http://www.w3.org/2000/svg") }
9
- it { expect(xml.namespaces.values).to include("http://www.w3.org/1999/xlink") }
10
- end
11
-
12
- describe "attribute namespaces" do
13
- with_svg_plugin "namespaced_attribute.svg"
14
- it { expect(xml.css("#Page-1").first.has_attribute?("sketch:type")).to be_falsy }
15
- it { expect(xml.css("#Page-1").first.has_attribute?("type")).to be_falsy }
16
- it { expect(xml.css("#Rectangle-1").first.has_attribute?("sketch:type")).to be_falsy }
17
- it { expect(xml.css("#Rectangle-1").first.has_attribute?("type")).to be_falsy }
18
- end
19
- end
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
- require "spec_helper"
3
-
4
- describe SvgOptimizer::Plugins::RemoveEmptyAttribute do
5
- with_svg_plugin <<-SVG
6
- <g attr1="" attr2=""/>
7
- <g attr3="" attr4=""/>
8
- <g namespace:attr="" />
9
- SVG
10
-
11
- it { expect(xml.xpath("//*[@*='']")).to be_empty }
12
- end
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
- require "spec_helper"
3
-
4
- describe SvgOptimizer::Plugins::RemoveEmptyContainer do
5
- context "inner elements" do
6
- with_svg_plugin "<g><marker><a/></marker></g>"
7
- it { expect(xml.root.css("*")).to be_empty }
8
- end
9
- end
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
- require "spec_helper"
3
-
4
- describe SvgOptimizer::Plugins::RemoveEmptyTextNode do
5
- context "groups with empty text nodes only" do
6
- with_svg_plugin %[<g> \n\t\r\n </g>]
7
- it { expect(xml.css("g").children).to be_empty }
8
- end
9
-
10
- context "groups with non-empty nodes" do
11
- with_svg_plugin %[<g> Hello \n\t\r\n </g>]
12
- it { expect(xml.css("g").children).not_to be_empty }
13
- end
14
- end
@@ -1,82 +0,0 @@
1
- # frozen_string_literal: true
2
- require "spec_helper"
3
-
4
- describe SvgOptimizer::Plugins::RemoveHiddenElement do
5
- context "display: none" do
6
- with_svg_plugin <<-SVG
7
- <path display="none" d="..."/>
8
- SVG
9
-
10
- it { expect(xml.css("path")).to be_empty }
11
- end
12
-
13
- context "opacity: 0" do
14
- with_svg_plugin <<-SVG
15
- <path opacity="0" d="..."/>
16
- SVG
17
-
18
- it { expect(xml.css("path")).to be_empty }
19
- end
20
-
21
- context "circle" do
22
- with_svg_plugin <<-SVG
23
- <circle r="0"/>
24
- SVG
25
-
26
- it { expect(xml.css("circle")).to be_empty }
27
- end
28
-
29
- context "ellipse" do
30
- with_svg_plugin <<-SVG
31
- <ellipse rx="0"/>
32
- <ellipse ry="0"/>
33
- SVG
34
-
35
- it { expect(xml.css("ellipse")).to be_empty }
36
- end
37
-
38
- context "rect" do
39
- with_svg_plugin <<-SVG
40
- <rect width="0"/>
41
- <rect height="0"/>
42
- SVG
43
-
44
- it { expect(xml.css("rect")).to be_empty }
45
- end
46
-
47
- context "pattern" do
48
- with_svg_plugin <<-SVG
49
- <pattern width="0"/>
50
- <pattern height="0"/>
51
- SVG
52
-
53
- it { expect(xml.css("pattern")).to be_empty }
54
- end
55
-
56
- context "image" do
57
- with_svg_plugin <<-SVG
58
- <image width="0"/>
59
- <image height="0"/>
60
- SVG
61
-
62
- it { expect(xml.css("image")).to be_empty }
63
- end
64
-
65
- context "<path d=''/>" do
66
- with_svg_plugin <<-SVG
67
- <path d=''/>
68
- SVG
69
-
70
- it { expect(xml.css("path")).to be_empty }
71
- end
72
-
73
- context "other hidden elements" do
74
- with_svg_plugin <<-SVG
75
- <path/>
76
- <polyline/>
77
- <polygon/>
78
- SVG
79
-
80
- it { expect(xml.root.css("*")).to be_empty }
81
- end
82
- end
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
- require "spec_helper"
3
-
4
- describe SvgOptimizer::Plugins::RemoveMetadata do
5
- with_svg_plugin <<-SVG
6
- <metadata></metadata>
7
- <!-- foo -->
8
- <metadata></metadata>
9
- SVG
10
-
11
- it { expect(xml.css("metadata")).to be_empty }
12
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
- require "spec_helper"
3
-
4
- describe SvgOptimizer::Plugins::RemoveRasterImage do
5
- with_svg_plugin <<-SVG
6
- <g>
7
- <image xlink:href="raster.jpg" width="100" height="100"/>
8
- <image xlink:href="raster.png" width="100" height="100"/>
9
- <image xlink:href="raster.gif" width="100" height="100"/>
10
- <image xlink:href="raster.svg" width="100" height="100"/>
11
- </g>
12
- SVG
13
-
14
- it { expect(xml.css("image").size).to eql(1) }
15
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
- require "spec_helper"
3
-
4
- describe SvgOptimizer::Plugins::RemoveUnusedNamespace do
5
- with_svg_plugin "unused_namespace.svg"
6
-
7
- let(:namespaces) do
8
- xml.root.namespace_definitions.each_with_object({}) do |ns, buffer|
9
- next unless ns.prefix
10
- buffer[ns.prefix] = ns.href
11
- end
12
- end
13
-
14
- it { expect(namespaces).to include("test" => "http://example.com/") }
15
- it { expect(namespaces).to include("test2" => "http://example2.com/") }
16
-
17
- it { expect(namespaces).not_to include("test3" => "http://example3.com/") }
18
- it { expect(namespaces).not_to include("test4" => "http://example4.com/") }
19
- end
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
- require "spec_helper"
3
-
4
- describe SvgOptimizer::Plugins::RemoveUselessStrokeAndFill do
5
- test_with_fixture_set("remove_useless_stroke_and_fill")
6
- end
@@ -1,54 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe SvgOptimizer do
4
- context "file saving" do
5
- let(:input) { "/tmp/#{SecureRandom.uuid}.svg" }
6
- let(:output) { "/tmp/#{SecureRandom.uuid}.svg" }
7
- let(:raw_svg) { build_svg("<!-- foo --><text>SVG</text>") }
8
- let(:output_svg) { SvgOptimizer.optimize(raw_svg) }
9
-
10
- before do
11
- File.open(input, "w") {|file| file << raw_svg }
12
- end
13
-
14
- it "overrides existing file with optimized version" do
15
- SvgOptimizer.optimize_file(input)
16
- expect(File.read(input)).to eq(output_svg)
17
- end
18
-
19
- it "saves new file file with optimized version" do
20
- SvgOptimizer.optimize_file(input, output)
21
- expect(File.read(input)).to eq(raw_svg)
22
- expect(File.read(output)).to eq(output_svg)
23
- end
24
- end
25
-
26
- context "plugin selection" do
27
- it "applies all plugins" do
28
- svg = build_svg <<-SVG
29
- <!-- foo -->
30
- <g></g>
31
- <!-- bar -->
32
- SVG
33
-
34
- xml = Nokogiri::XML(SvgOptimizer.optimize(svg))
35
-
36
- expect(xml.xpath("//comment()")).to be_empty
37
- expect(xml.css("g")).to be_empty
38
- end
39
-
40
- it "applies just specified plugins" do
41
- plugins = [SvgOptimizer::Plugins::RemoveComment]
42
- svg = build_svg <<-SVG
43
- <!-- foo -->
44
- <g></g>
45
- <!-- bar -->
46
- SVG
47
-
48
- xml = Nokogiri::XML(SvgOptimizer.optimize(svg, plugins))
49
-
50
- expect(xml.xpath("//comment()")).to be_empty
51
- expect(xml.css("g").length).to eql(1)
52
- end
53
- end
54
- end