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

Add global configuration from Ruby #36

Open
bobbus opened this issue Feb 8, 2014 · 8 comments
Open

Add global configuration from Ruby #36

bobbus opened this issue Feb 8, 2014 · 8 comments

Comments

@bobbus
Copy link

bobbus commented Feb 8, 2014

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.

@toy
Copy link
Owner

toy commented Feb 9, 2014

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.

@bobbus
Copy link
Author

bobbus commented Feb 9, 2014

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

@bencrouse
Copy link

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)

@bobbus
Copy link
Author

bobbus commented Feb 10, 2014

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

@bencrouse
Copy link

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.

@bobbus
Copy link
Author

bobbus commented Feb 10, 2014

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

@toy
Copy link
Owner

toy commented Feb 12, 2014

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

@jacek213
Copy link

jacek213 commented Feb 6, 2015

+1 for rails initializer idea

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants