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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 385024a89793a95b04290dbea791b71007a8d27387a02939865f4ed6f2528c72
4
- data.tar.gz: 8e1e9581f7516362b09bc2221a889043e3ae1b1ad442e73a7b178be26e3e1d8b
3
+ metadata.gz: ec1327e57cc38ef5060b4e20afa3bce438abb6e967b8eb2b1691c571871fe293
4
+ data.tar.gz: 3945086145b7e192f93adb176b19d970c8707e6981ed8e7f14dcdc5ffbb0c723
5
5
  SHA512:
6
- metadata.gz: 699299880bf18dab73133899f59dcfa541a46ab45f3f0d2aeb48eb478caec60bdc2ce07c5093b5ab99e6c09118a966fa1009ba656ac7db0ef768a22a54774222
7
- data.tar.gz: 1862ba8ad388c1523d7e69ff2e139efef59e4d3ede808d6ac9cabfd112c94b35a706563b1efaf10302386acce25812b02ba2b33ba3a2ab3bb45dc459963748d8
6
+ metadata.gz: '099effe7f458ba87feef6323f0df44caefbc9fec401cf626b6d4452fccbb60ec9f9c2eb8ea407eab470278ffb2f9084413dafde9dbea736acf6541bafddcd0d9'
7
+ data.tar.gz: 6e8831f708e90f74176342ba2a681894099e4dbaaa0122fb12959b395addf79638326dd629efe61d082a7b262a7671b1cb31013bfaff760529ed59a9f8d707a9
data/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  # SvgOptimizer
2
2
 
3
3
  [![Tests](https://github.com/fnando/svg_optimizer/workflows/ruby-tests/badge.svg)](https://github.com/fnando/svg_optimizer)
4
- [![Code Climate](https://codeclimate.com/github/fnando/svg_optimizer/badges/gpa.svg)](https://codeclimate.com/github/fnando/svg_optimizer)
5
4
  [![Gem](https://img.shields.io/gem/v/svg_optimizer.svg)](https://rubygems.org/gems/svg_optimizer)
6
5
  [![Gem](https://img.shields.io/gem/dt/svg_optimizer.svg)](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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SvgOptimizer
4
- VERSION = "0.2.6"
4
+ VERSION = "0.3.0"
5
5
  end
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(path, target = path, plugins = DEFAULT_PLUGINS)
51
- contents = optimize(File.read(path), plugins)
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.2.6
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: 2022-01-05 00:00:00.000000000 Z
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.3.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