image_optim icon indicating copy to clipboard operation
image_optim copied to clipboard

Add global configuration from Ruby

Open bobbus opened this issue 11 years ago • 8 comments

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.

bobbus avatar Feb 08 '14 11:02 bobbus

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 avatar Feb 09 '14 09:02 toy

@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.

bobbus avatar Feb 09 '14 21:02 bobbus

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 avatar Feb 09 '14 22:02 bencrouse

@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.

bobbus avatar Feb 10 '14 15:02 bobbus

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 avatar Feb 10 '14 15:02 bencrouse

@bencrouse , seems like a perfect answer to my needs.

bobbus avatar Feb 10 '14 15:02 bobbus

@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?

toy avatar Feb 12 '14 23:02 toy

+1 for rails initializer idea

jacek213 avatar Feb 06 '15 13:02 jacek213