From 3d62b56635f493467b50d4c47cdea18977b6ee28 Mon Sep 17 00:00:00 2001 From: Dmitry Vorotilin Date: Sat, 2 Apr 2016 14:17:25 +0300 Subject: [PATCH] Bring quiet_assets to sprockets-rails --- lib/sprockets/rails/quiet_assets.rb | 18 ++++++++++++++++++ lib/sprockets/railtie.rb | 6 ++++++ 2 files changed, 24 insertions(+) create mode 100644 lib/sprockets/rails/quiet_assets.rb diff --git a/lib/sprockets/rails/quiet_assets.rb b/lib/sprockets/rails/quiet_assets.rb new file mode 100644 index 00000000..a54ab829 --- /dev/null +++ b/lib/sprockets/rails/quiet_assets.rb @@ -0,0 +1,18 @@ +module Sprockets + module Rails + class QuietAssets + def initialize(app) + @app = app + @assets_regex = %r(\A/{0,2}#{::Rails.application.config.assets.prefix}) + end + + def call(env) + if env['PATH_INFO'] =~ @assets_regex + ::Rails.logger.silence { @app.call(env) } + else + @app.call(env) + end + end + end + end +end diff --git a/lib/sprockets/railtie.rb b/lib/sprockets/railtie.rb index e616254d..26d24364 100644 --- a/lib/sprockets/railtie.rb +++ b/lib/sprockets/railtie.rb @@ -6,6 +6,7 @@ require 'sprockets' require 'sprockets/rails/context' require 'sprockets/rails/helper' +require 'sprockets/rails/quiet_assets' require 'sprockets/rails/route_wrapper' require 'sprockets/rails/version' require 'set' @@ -97,6 +98,7 @@ def configure(&block) config.assets.precompile = [] config.assets.prefix = "/assets" config.assets.manifest = nil + config.assets.quiet = true initializer :set_default_precompile do |app| if using_sprockets4? @@ -105,6 +107,10 @@ def configure(&block) else app.config.assets.precompile += [LOOSE_APP_ASSETS, /(?:\/|\\|\A)application\.(css|js)$/] end + + if app.config.assets.quiet + app.middleware.insert_before ::Rails::Rack::Logger, Sprockets::Rails::QuietAssets + end end config.assets.version = ""