From da74bb8b616ceb8c9e2b9572ccce1b156f2b8c9c Mon Sep 17 00:00:00 2001 From: Thomas Stratmann Date: Wed, 23 Jul 2014 14:51:07 +0200 Subject: [PATCH] separate conditions from preproc registration and avoid LocalJumpError when breaking in railtie initializer block --- lib/image_optim/railtie.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/image_optim/railtie.rb b/lib/image_optim/railtie.rb index 9ce4f774..780435c5 100644 --- a/lib/image_optim/railtie.rb +++ b/lib/image_optim/railtie.rb @@ -4,11 +4,17 @@ 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 - break if app.config.assets.compress == false - break if app.config.assets.image_optim == false - break unless app.assets + app.assets + end + def register_preprocessor(app) options = if app.config.assets.image_optim == true {} else @@ -25,7 +31,6 @@ class Railtie < Rails::Railtie 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