lib/image_optim/railtie.rb in image_optim-0.13.3 vs lib/image_optim/railtie.rb in image_optim-0.14.0
- old
+ new
@@ -1,28 +1,31 @@
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|
- if app.config.assets.compress != false && app.config.assets.image_optim != false && app.assets
- options = if app.config.assets.image_optim == true
- {}
- else
- app.config.assets.image_optim || {}
- end
+ break if app.config.assets.compress == false
+ break if app.config.assets.image_optim == false
+ break unless app.assets
- image_optim = ImageOptim.new(options)
+ options = if app.config.assets.image_optim == true
+ {}
+ else
+ app.config.assets.image_optim || {}
+ end
- processor = proc do |context, data|
- image_optim.optimize_image_data(data) || data
- end
+ image_optim = ImageOptim.new(options)
- 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
-
+ 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