svg_optimizer 0.0.4 → 0.0.5
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 +4 -4
- data/lib/svg_optimizer/plugins/collapse_groups.rb +48 -0
- data/lib/svg_optimizer/plugins/remove_useless_stroke_and_fill.rb +62 -0
- data/lib/svg_optimizer/version.rb +1 -1
- data/lib/svg_optimizer.rb +4 -0
- data/spec/fixtures/collapse_groups/collapseGroups.01.svg +13 -0
- data/spec/fixtures/collapse_groups/collapseGroups.02.svg +13 -0
- data/spec/fixtures/collapse_groups/collapseGroups.03.svg +13 -0
- data/spec/fixtures/collapse_groups/collapseGroups.04.svg +17 -0
- data/spec/fixtures/collapse_groups/collapseGroups.05.svg +17 -0
- data/spec/fixtures/collapse_groups/collapseGroups.06.svg +17 -0
- data/spec/fixtures/collapse_groups/collapseGroups.07.svg +17 -0
- data/spec/fixtures/collapse_groups/collapseGroups.08.svg +25 -0
- data/spec/fixtures/collapse_groups/collapseGroups.09.svg +35 -0
- data/spec/fixtures/collapse_groups/collapseGroups.10.svg +19 -0
- data/spec/fixtures/collapse_groups/collapseGroups.11.svg +29 -0
- data/spec/fixtures/remove_useless_stroke_and_fill/removeUselessStrokeAndFill.01.svg +41 -0
- data/spec/fixtures/remove_useless_stroke_and_fill/removeUselessStrokeAndFill.02.svg +31 -0
- data/spec/fixtures/remove_useless_stroke_and_fill/removeUselessStrokeAndFill.03.svg +21 -0
- data/spec/spec_helper.rb +29 -3
- data/spec/svg_optimizer/plugins/collapse_groups_spec.rb +5 -0
- data/spec/svg_optimizer/plugins/remove_useless_stroke_and_fill_spec.rb +5 -0
- metadata +36 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 967fe8ee11fe2dfd0f45a43b8162f63407a9b66b
|
4
|
+
data.tar.gz: 92ae939384c1111548a7972cab68c438c24066d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00ed5692f1ca0e2cb01b99c3fb4fd05bf7a0f304841ed21f256d4dc819e0c56faf4b3b685d35316879d38632f253fe48ef15f967809ef97865078292d6d403f1
|
7
|
+
data.tar.gz: 6f30a9fba01672b745858889f972fc562025b49f353032dcccdeff418c12daea995cfd3dcac122b9a82700f94cc3fca5b8966da9946ee1afab0e183f6a7c66eb
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module SvgOptimizer
|
2
|
+
module Plugins
|
3
|
+
class CollapseGroups < Base
|
4
|
+
def process
|
5
|
+
xml.css('g:not(:empty)').each do |group|
|
6
|
+
collapse(group)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def collapse(group)
|
13
|
+
collapse_attributes(group)
|
14
|
+
group.swap(group.children) if collapse?(group)
|
15
|
+
end
|
16
|
+
|
17
|
+
def collapse_attributes(group)
|
18
|
+
child = group.first_element_child
|
19
|
+
return unless collapse_attributes?(group, child)
|
20
|
+
|
21
|
+
group.attributes.each do |attr, val|
|
22
|
+
if %w(transform class).include?(attr)
|
23
|
+
child[attr] = [val, child[attr]].compact.join(' ')
|
24
|
+
else
|
25
|
+
child[attr] ||= val
|
26
|
+
end
|
27
|
+
group.delete(attr)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def collapse?(group)
|
32
|
+
group.attributes.empty? &&
|
33
|
+
!group.element_children.map(&:name).include?('animate')
|
34
|
+
end
|
35
|
+
|
36
|
+
def collapse_attributes?(group, child)
|
37
|
+
return false unless group.attributes.any?
|
38
|
+
return false unless group.element_children.length == 1
|
39
|
+
return false if child.has_attribute?('id')
|
40
|
+
return false unless !group.has_attribute?('clip-path') ||
|
41
|
+
child.name == 'g' &&
|
42
|
+
!group.has_attribute?('transform') &&
|
43
|
+
!child.has_attribute?('transform')
|
44
|
+
true
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module SvgOptimizer
|
2
|
+
module Plugins
|
3
|
+
class RemoveUselessStrokeAndFill < Base
|
4
|
+
SELECTOR = %w(circle ellipse line path polygon polyline rect).join(',')
|
5
|
+
STROKE_ATTRS = %w(stroke stroke-opacity stroke-width stroke-dashoffset)
|
6
|
+
FILL_ATTRS = %w(fill-opacity fill-rule)
|
7
|
+
|
8
|
+
def process
|
9
|
+
return if xml.css('style, script').any?
|
10
|
+
xml.css(SELECTOR).each do |node|
|
11
|
+
remove_useless_attributes(node)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def remove_useless_attributes(node)
|
18
|
+
return if inherited_attribute(node, 'id')
|
19
|
+
remove_stroke(node) if remove_stroke?(node)
|
20
|
+
remove_fill(node) if remove_fill?(node)
|
21
|
+
end
|
22
|
+
|
23
|
+
def remove_stroke(node)
|
24
|
+
STROKE_ATTRS.each { |attr| node.delete(attr) }
|
25
|
+
node['stroke'] = 'none' if decline_inherited_stroke?(node)
|
26
|
+
end
|
27
|
+
|
28
|
+
def remove_fill(node)
|
29
|
+
FILL_ATTRS.each { |attr| node.delete(attr) }
|
30
|
+
node['fill'] = 'none' if decline_inherited_fill?(node)
|
31
|
+
end
|
32
|
+
|
33
|
+
def decline_inherited_stroke?(node)
|
34
|
+
(inherited_attribute(node.parent, 'stroke') || 'none') != 'none'
|
35
|
+
end
|
36
|
+
|
37
|
+
def decline_inherited_fill?(node)
|
38
|
+
!inherited_attribute(node, 'fill') || node.has_attribute?('fill')
|
39
|
+
end
|
40
|
+
|
41
|
+
def remove_stroke?(node)
|
42
|
+
return true if (inherited_attribute(node, 'stroke') || 'none') == 'none'
|
43
|
+
return true if inherited_attribute(node, 'stroke-opacity') == '0'
|
44
|
+
return inherited_attribute(node, 'stroke-width') == '0'
|
45
|
+
end
|
46
|
+
|
47
|
+
def remove_fill?(node)
|
48
|
+
fill = inherited_attribute(node, 'fill')
|
49
|
+
return true if fill == 'none'
|
50
|
+
return true if inherited_attribute(node, 'fill-opacity') == '0'
|
51
|
+
return !fill
|
52
|
+
end
|
53
|
+
|
54
|
+
def inherited_attribute(node, attr)
|
55
|
+
return nil if node.nil? || node.document?
|
56
|
+
return node[attr] if node.has_attribute?(attr)
|
57
|
+
inherited_attribute(node.parent, attr)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
data/lib/svg_optimizer.rb
CHANGED
@@ -4,6 +4,7 @@ require "svg_optimizer/version"
|
|
4
4
|
require "svg_optimizer/plugins/base"
|
5
5
|
require "svg_optimizer/plugins/cleanup_attribute"
|
6
6
|
require "svg_optimizer/plugins/cleanup_id"
|
7
|
+
require "svg_optimizer/plugins/collapse_groups"
|
7
8
|
require "svg_optimizer/plugins/remove_comment"
|
8
9
|
require "svg_optimizer/plugins/remove_metadata"
|
9
10
|
require "svg_optimizer/plugins/remove_empty_text_node"
|
@@ -13,6 +14,7 @@ require "svg_optimizer/plugins/remove_hidden_element"
|
|
13
14
|
require "svg_optimizer/plugins/remove_raster_image"
|
14
15
|
require "svg_optimizer/plugins/remove_empty_attribute"
|
15
16
|
require "svg_optimizer/plugins/remove_unused_namespace"
|
17
|
+
require "svg_optimizer/plugins/remove_useless_stroke_and_fill"
|
16
18
|
|
17
19
|
module SvgOptimizer
|
18
20
|
PLUGINS = %w[
|
@@ -25,6 +27,8 @@ module SvgOptimizer
|
|
25
27
|
RemoveUnusedNamespace
|
26
28
|
RemoveRasterImage
|
27
29
|
RemoveEmptyAttribute
|
30
|
+
CollapseGroups
|
31
|
+
RemoveUselessStrokeAndFill
|
28
32
|
RemoveEmptyTextNode
|
29
33
|
RemoveEmptyContainer
|
30
34
|
]
|
@@ -0,0 +1,17 @@
|
|
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>
|
@@ -0,0 +1,17 @@
|
|
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>
|
@@ -0,0 +1,17 @@
|
|
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>
|
@@ -0,0 +1,17 @@
|
|
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>
|
@@ -0,0 +1,25 @@
|
|
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>
|
@@ -0,0 +1,35 @@
|
|
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>
|
@@ -0,0 +1,19 @@
|
|
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>
|
@@ -0,0 +1,29 @@
|
|
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>
|
@@ -0,0 +1,41 @@
|
|
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>
|
@@ -0,0 +1,31 @@
|
|
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>
|
@@ -0,0 +1,21 @@
|
|
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>
|
data/spec/spec_helper.rb
CHANGED
@@ -11,13 +11,38 @@ module RSpecHelpers
|
|
11
11
|
</svg>
|
12
12
|
XML
|
13
13
|
|
14
|
-
def
|
15
|
-
|
16
|
-
|
14
|
+
def fixtures_path
|
15
|
+
File.expand_path("../fixtures", __FILE__)
|
16
|
+
end
|
17
|
+
|
18
|
+
def setup_plugin_test
|
19
|
+
let(:input_xml) { Nokogiri::XML(input_content, &:noblanks) }
|
17
20
|
let(:plugin) { described_class.new(input_xml) }
|
18
21
|
let(:xml) { plugin.xml }
|
19
22
|
before { plugin.process }
|
20
23
|
end
|
24
|
+
|
25
|
+
def with_svg_plugin(content)
|
26
|
+
let(:file_path) { File.join(fixtures_path, content) }
|
27
|
+
let(:input_content) { File.file?(file_path) ? File.read(file_path) : SVG % content }
|
28
|
+
setup_plugin_test
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_with_fixture_set(name)
|
32
|
+
Dir.glob(File.join(fixtures_path, name, '*.svg')).each do |fixture|
|
33
|
+
context "output from fixture: #{fixture}" do
|
34
|
+
let(:fixture_content) { File.read(fixture) }
|
35
|
+
let(:input_content) { fixture_content.split('@@@')[0].strip }
|
36
|
+
let(:expected_content) { fixture_content.split('@@@')[1].strip }
|
37
|
+
let(:expected) { Nokogiri::XML(expected_content, &:noblanks).root.to_xml }
|
38
|
+
subject { xml.root.to_xml }
|
39
|
+
setup_plugin_test
|
40
|
+
|
41
|
+
it { is_expected.to eq(expected) }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
21
46
|
end
|
22
47
|
|
23
48
|
RSpec.configure do |config|
|
@@ -25,4 +50,5 @@ RSpec.configure do |config|
|
|
25
50
|
config.filter_run :focus
|
26
51
|
config.order = "random"
|
27
52
|
config.extend RSpecHelpers
|
53
|
+
config.include RSpecHelpers
|
28
54
|
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.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nando Vieira
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-04-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -93,6 +93,7 @@ files:
|
|
93
93
|
- lib/svg_optimizer/plugins/base.rb
|
94
94
|
- lib/svg_optimizer/plugins/cleanup_attribute.rb
|
95
95
|
- lib/svg_optimizer/plugins/cleanup_id.rb
|
96
|
+
- lib/svg_optimizer/plugins/collapse_groups.rb
|
96
97
|
- lib/svg_optimizer/plugins/remove_comment.rb
|
97
98
|
- lib/svg_optimizer/plugins/remove_editor_namespace.rb
|
98
99
|
- lib/svg_optimizer/plugins/remove_empty_attribute.rb
|
@@ -102,15 +103,31 @@ files:
|
|
102
103
|
- lib/svg_optimizer/plugins/remove_metadata.rb
|
103
104
|
- lib/svg_optimizer/plugins/remove_raster_image.rb
|
104
105
|
- lib/svg_optimizer/plugins/remove_unused_namespace.rb
|
106
|
+
- lib/svg_optimizer/plugins/remove_useless_stroke_and_fill.rb
|
105
107
|
- lib/svg_optimizer/version.rb
|
106
108
|
- spec/fixtures/cleanup_id.svg
|
107
109
|
- spec/fixtures/cleanup_id_expected.svg
|
110
|
+
- spec/fixtures/collapse_groups/collapseGroups.01.svg
|
111
|
+
- spec/fixtures/collapse_groups/collapseGroups.02.svg
|
112
|
+
- spec/fixtures/collapse_groups/collapseGroups.03.svg
|
113
|
+
- spec/fixtures/collapse_groups/collapseGroups.04.svg
|
114
|
+
- spec/fixtures/collapse_groups/collapseGroups.05.svg
|
115
|
+
- spec/fixtures/collapse_groups/collapseGroups.06.svg
|
116
|
+
- spec/fixtures/collapse_groups/collapseGroups.07.svg
|
117
|
+
- spec/fixtures/collapse_groups/collapseGroups.08.svg
|
118
|
+
- spec/fixtures/collapse_groups/collapseGroups.09.svg
|
119
|
+
- spec/fixtures/collapse_groups/collapseGroups.10.svg
|
120
|
+
- spec/fixtures/collapse_groups/collapseGroups.11.svg
|
108
121
|
- spec/fixtures/green.svg
|
109
122
|
- spec/fixtures/namespaced_attribute.svg
|
123
|
+
- spec/fixtures/remove_useless_stroke_and_fill/removeUselessStrokeAndFill.01.svg
|
124
|
+
- spec/fixtures/remove_useless_stroke_and_fill/removeUselessStrokeAndFill.02.svg
|
125
|
+
- spec/fixtures/remove_useless_stroke_and_fill/removeUselessStrokeAndFill.03.svg
|
110
126
|
- spec/fixtures/unused_namespace.svg
|
111
127
|
- spec/spec_helper.rb
|
112
128
|
- spec/svg_optimizer/plugins/cleanup_attribute_spec.rb
|
113
129
|
- spec/svg_optimizer/plugins/cleanup_id_spec.rb
|
130
|
+
- spec/svg_optimizer/plugins/collapse_groups_spec.rb
|
114
131
|
- spec/svg_optimizer/plugins/remove_comment_spec.rb
|
115
132
|
- spec/svg_optimizer/plugins/remove_editor_namespace_spec.rb
|
116
133
|
- spec/svg_optimizer/plugins/remove_empty_attribute_spec.rb
|
@@ -120,6 +137,7 @@ files:
|
|
120
137
|
- spec/svg_optimizer/plugins/remove_metadata_spec.rb
|
121
138
|
- spec/svg_optimizer/plugins/remove_raster_image_spec.rb
|
122
139
|
- spec/svg_optimizer/plugins/remove_unused_namespace_spec.rb
|
140
|
+
- spec/svg_optimizer/plugins/remove_useless_stroke_and_fill_spec.rb
|
123
141
|
homepage: https://github.com/fnando/svg_optimizer
|
124
142
|
licenses:
|
125
143
|
- MIT
|
@@ -147,12 +165,27 @@ summary: SVG optimization based on Node's SVGO
|
|
147
165
|
test_files:
|
148
166
|
- spec/fixtures/cleanup_id.svg
|
149
167
|
- spec/fixtures/cleanup_id_expected.svg
|
168
|
+
- spec/fixtures/collapse_groups/collapseGroups.01.svg
|
169
|
+
- spec/fixtures/collapse_groups/collapseGroups.02.svg
|
170
|
+
- spec/fixtures/collapse_groups/collapseGroups.03.svg
|
171
|
+
- spec/fixtures/collapse_groups/collapseGroups.04.svg
|
172
|
+
- spec/fixtures/collapse_groups/collapseGroups.05.svg
|
173
|
+
- spec/fixtures/collapse_groups/collapseGroups.06.svg
|
174
|
+
- spec/fixtures/collapse_groups/collapseGroups.07.svg
|
175
|
+
- spec/fixtures/collapse_groups/collapseGroups.08.svg
|
176
|
+
- spec/fixtures/collapse_groups/collapseGroups.09.svg
|
177
|
+
- spec/fixtures/collapse_groups/collapseGroups.10.svg
|
178
|
+
- spec/fixtures/collapse_groups/collapseGroups.11.svg
|
150
179
|
- spec/fixtures/green.svg
|
151
180
|
- spec/fixtures/namespaced_attribute.svg
|
181
|
+
- spec/fixtures/remove_useless_stroke_and_fill/removeUselessStrokeAndFill.01.svg
|
182
|
+
- spec/fixtures/remove_useless_stroke_and_fill/removeUselessStrokeAndFill.02.svg
|
183
|
+
- spec/fixtures/remove_useless_stroke_and_fill/removeUselessStrokeAndFill.03.svg
|
152
184
|
- spec/fixtures/unused_namespace.svg
|
153
185
|
- spec/spec_helper.rb
|
154
186
|
- spec/svg_optimizer/plugins/cleanup_attribute_spec.rb
|
155
187
|
- spec/svg_optimizer/plugins/cleanup_id_spec.rb
|
188
|
+
- spec/svg_optimizer/plugins/collapse_groups_spec.rb
|
156
189
|
- spec/svg_optimizer/plugins/remove_comment_spec.rb
|
157
190
|
- spec/svg_optimizer/plugins/remove_editor_namespace_spec.rb
|
158
191
|
- spec/svg_optimizer/plugins/remove_empty_attribute_spec.rb
|
@@ -162,3 +195,4 @@ test_files:
|
|
162
195
|
- spec/svg_optimizer/plugins/remove_metadata_spec.rb
|
163
196
|
- spec/svg_optimizer/plugins/remove_raster_image_spec.rb
|
164
197
|
- spec/svg_optimizer/plugins/remove_unused_namespace_spec.rb
|
198
|
+
- spec/svg_optimizer/plugins/remove_useless_stroke_and_fill_spec.rb
|