svg_optimizer 0.2.6 → 0.3.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.
- checksums.yaml +4 -4
- data/README.md +14 -1
- data/lib/svg_optimizer/version.rb +1 -1
- data/lib/svg_optimizer.rb +9 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec1327e57cc38ef5060b4e20afa3bce438abb6e967b8eb2b1691c571871fe293
|
4
|
+
data.tar.gz: 3945086145b7e192f93adb176b19d970c8707e6981ed8e7f14dcdc5ffbb0c723
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '099effe7f458ba87feef6323f0df44caefbc9fec401cf626b6d4452fccbb60ec9f9c2eb8ea407eab470278ffb2f9084413dafde9dbea736acf6541bafddcd0d9'
|
7
|
+
data.tar.gz: 6e8831f708e90f74176342ba2a681894099e4dbaaa0122fb12959b395addf79638326dd629efe61d082a7b262a7671b1cb31013bfaff760529ed59a9f8d707a9
|
data/README.md
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# SvgOptimizer
|
2
2
|
|
3
3
|
[](https://github.com/fnando/svg_optimizer)
|
4
|
-
[](https://codeclimate.com/github/fnando/svg_optimizer)
|
5
4
|
[](https://rubygems.org/gems/svg_optimizer)
|
6
5
|
[](https://rubygems.org/gems/svg_optimizer)
|
7
6
|
|
@@ -33,6 +32,20 @@ SvgOptimizer.optimize_file("file.svg")
|
|
33
32
|
SvgOptimizer.optimize_file("file.svg", "optimized/file.svg")
|
34
33
|
```
|
35
34
|
|
35
|
+
You may have a need to optimize a *trusted* SVG document with entities that need to be
|
36
|
+
expanded. **Only if you are sure the file is trusted**, you may enable this additional entity
|
37
|
+
processing by passing the `trusted:` keyword argument:
|
38
|
+
|
39
|
+
``` ruby
|
40
|
+
# Optimize an existing trusted String which requires entity expansion.
|
41
|
+
xml = File.read("file.svg")
|
42
|
+
optimized = SvgOptimizer.optimize(xml, trusted: true)
|
43
|
+
|
44
|
+
# Optimize a trusted file which requires entity expansion - it will override the original file.
|
45
|
+
SvgOptimizer.optimize_file("file.svg", trusted: true)
|
46
|
+
```
|
47
|
+
|
48
|
+
|
36
49
|
You can specify the plugins you want to enable. The method signature is:
|
37
50
|
|
38
51
|
```ruby
|
data/lib/svg_optimizer.rb
CHANGED
@@ -37,9 +37,9 @@ module SvgOptimizer
|
|
37
37
|
RemoveEmptyContainer
|
38
38
|
].map {|name| Plugins.const_get(name) }
|
39
39
|
|
40
|
-
def self.optimize(contents, plugins = DEFAULT_PLUGINS)
|
40
|
+
def self.optimize(contents, plugins = DEFAULT_PLUGINS, trusted: false)
|
41
41
|
xml = Nokogiri::XML(contents) do |config|
|
42
|
-
config.recover.noent
|
42
|
+
config.recover.noent if trusted
|
43
43
|
end
|
44
44
|
|
45
45
|
plugins.each {|plugin| plugin.new(xml).process }
|
@@ -47,8 +47,13 @@ module SvgOptimizer
|
|
47
47
|
xml.root.to_xml
|
48
48
|
end
|
49
49
|
|
50
|
-
def self.optimize_file(
|
51
|
-
|
50
|
+
def self.optimize_file(
|
51
|
+
path,
|
52
|
+
target = path,
|
53
|
+
plugins = DEFAULT_PLUGINS,
|
54
|
+
trusted: false
|
55
|
+
)
|
56
|
+
contents = optimize(File.read(path), plugins, trusted: trusted)
|
52
57
|
File.open(target, "w") {|file| file << contents }
|
53
58
|
true
|
54
59
|
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.
|
4
|
+
version: 0.3.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:
|
11
|
+
date: 2023-09-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -168,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
168
168
|
- !ruby/object:Gem::Version
|
169
169
|
version: '0'
|
170
170
|
requirements: []
|
171
|
-
rubygems_version: 3.
|
171
|
+
rubygems_version: 3.4.6
|
172
172
|
signing_key:
|
173
173
|
specification_version: 4
|
174
174
|
summary: SVG optimization based on Node's SVGO
|