diff --git a/CHANGELOG.markdown b/CHANGELOG.markdown index 08898701..85dcc9cf 100644 --- a/CHANGELOG.markdown +++ b/CHANGELOG.markdown @@ -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) diff --git a/README.markdown b/README.markdown index 530ba887..c304f351 100644 --- a/README.markdown +++ b/README.markdown @@ -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 `[]`)* diff --git a/lib/image_optim/worker/svgo.rb b/lib/image_optim/worker/svgo.rb index 7fe2d7bb..62aa8b35 100644 --- a/lib/image_optim/worker/svgo.rb +++ b/lib/image_optim/worker/svgo.rb @@ -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