Sha256: 0fd2c92a9b88f7b645cca525280234f2fb35757f1f14c734c26ab9f3005c349b
Contents?: true
Size: 1.09 KB
Versions: 4
Compression:
Stored size: 1.09 KB
Contents
require 'image_optim' class ImageOptim # Adds image_optim as preprocessor for gif, jpeg, png and svg images class Railtie < Rails::Railtie initializer 'image_optim.initializer' do |app| register_preprocessor(app) if register_preprocessor?(app) end def register_preprocessor?(app) return if app.config.assets.compress == false return if app.config.assets.image_optim == false app.assets end def options(app) if app.config.assets.image_optim == true {} else app.config.assets.image_optim || {} end end def register_preprocessor(app) image_optim = ImageOptim.new(options(app)) processor = proc do |_context, data| image_optim.optimize_image_data(data) || data end app.assets.register_preprocessor 'image/gif', :image_optim, &processor app.assets.register_preprocessor 'image/jpeg', :image_optim, &processor app.assets.register_preprocessor 'image/png', :image_optim, &processor app.assets.register_preprocessor 'image/svg+xml', :image_optim, &processor end end end
Version data entries
4 entries across 4 versions & 2 rubygems