Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow svgo plugins to be disabled #110

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 `svgo` worker

## 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 none)*
* `enable_plugins` - List of plugins to enable *(defaults to none)*

<!---</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