Skip to content

Commit

Permalink
Merge branch 'tomhughes-svgo'
Browse files Browse the repository at this point in the history
  • Loading branch information
toy committed Nov 10, 2015
2 parents ab1c37b + cf7c048 commit 8d534db
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Unify getting description of option default value using `default_description` [@toy](https://github.com/toy)
* Don't use `-strip` option for optipng when the bin version is less than 0.7 [#106](https://github.com/toy/image_optim/issues/106) [@toy](https://github.com/toy)
* Use quality `0..100` by default in lossy mode of pngquant worker [#77](https://github.com/toy/image_optim/issues/77) [@toy](https://github.com/toy)
* Add `:disable_plugins` and `:enable_plugins` options to `svgo` worker [#110](https://github.com/toy/image_optim/pull/110) [@tomhughes](https://github.com/tomhughes)

## v0.21.0 (2015-05-30)

Expand Down
3 changes: 2 additions & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,8 @@ Worker has no options
* `:speed` — speed/quality trade-off: `1` - slow, `3` - default, `11` - fast & rough *(defaults to `3`)*

### svgo:
Worker has no options
* `:disable_plugins` — List of plugins to disable *(defaults to `[]`)*
* `:enable_plugins` — List of plugins to enable *(defaults to `[]`)*

<!---</worker-options>-->

Expand Down
16 changes: 16 additions & 0 deletions lib/image_optim/worker/svgo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,27 @@ class ImageOptim
class Worker
# https://github.com/svg/svgo
class Svgo < Worker
DISABLE_PLUGINS_OPTION =
option(:disable_plugins, [], 'List of plugins to disable') do |v|
Array(v).map(&:to_s)
end

ENABLE_PLUGINS_OPTION =
option(:enable_plugins, [], 'List of plugins to enable') do |v|
Array(v).map(&:to_s)
end

def optimize(src, dst)
args = %W[
--input #{src}
--output #{dst}
]
disable_plugins.each do |plugin_name|
args.unshift "--disable=#{plugin_name}"
end
enable_plugins.each do |plugin_name|
args.unshift "--enable=#{plugin_name}"
end
execute(:svgo, *args) && optimized?(src, dst)
end
end
Expand Down

0 comments on commit 8d534db

Please sign in to comment.