image_optim
image_optim copied to clipboard
Add global configuration from Ruby
Actually, the only way to set global config for image_optim is to write them in a .yml file.
For our Rails application, this is not really practical and we would like to make it possible to set them in an initializer or application config.
Does it seems like a useful feature ? If so, I can try to write a PR implementing this.
Please look at #31 by @bencrouse it allows to set options for image_optim in rails app config, it is already merged, but not yet released.
@toy , Thanks for your answer but actually #31 make it possible to config ImageOptim for Rails assets pipeline only, it is not used in other context.
The need of writing a yaml file for the config make it hardly feasible to share a config between several application or when developing a gem.
You could write your own config/image_optim.yml and do something like this to load it:
IMAGE_OPTIM_CONFIG = YAML.load_file(Rails.root.join('config', 'image_optim.yml')[Rails.env]
config.assets.image_optim = IMAGE_OPTIM_CONFIG
and then where ever else you wanted to use image_optim...
io = ImageOptim.new(IMAGE_OPTIM_CONFIG)
@bencrouse , thanks for your suggestion, I will use it from now.
I would still be in favor of adding this directly in this gem in order to avoid having to specify default option everywhere we use ImageOptim.new but not a big deal neither, please close if you feel like it's not wanted for now.
I think ideally, I'd like to see a ImageOptim.defaults config option where you could 1) find out the out of the box defaults 2) change them for all instances of ImageOptim.
ImageOptim#initialize would then be responsible for merging whatever options are sent into that instance with whatever is in ImageOptim.defaults.
I may take a stab at it if @toy likes the idea and I have some free dev time this week.
@bencrouse , seems like a perfect answer to my needs.
@bencrouse @bobbus Better to put it into ImageOptim::Config.
defaults sounds like it should be overridable by global and local configs. It is a good thing that it will be possible to read defaults, but it will not be possible to override global/local config. Ideas?
+1 for rails initializer idea