From 2cc1bc37732a5f89c8364e6724e8c39e14216a0a Mon Sep 17 00:00:00 2001 From: Chris Eppstein Date: Sat, 18 Jun 2011 12:10:09 -0700 Subject: Move the config bootstrapping to initialization to minimize access to the Rails.application global. --- actionpack/lib/action_view/asset_paths.rb | 17 +++++++---------- actionpack/lib/sprockets/helpers/rails_helper.rb | 8 +++++++- 2 files changed, 14 insertions(+), 11 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/asset_paths.rb b/actionpack/lib/action_view/asset_paths.rb index a74d45db6f..a768a0b882 100644 --- a/actionpack/lib/action_view/asset_paths.rb +++ b/actionpack/lib/action_view/asset_paths.rb @@ -107,20 +107,17 @@ module ActionView end def relative_url_root - if controller.respond_to?(:config) && controller.config - controller.config.relative_url_root - elsif config.respond_to?(:action_controller) && config.action_controller - config.action_controller.relative_url_root - elsif Rails.respond_to?(:application) && Rails.application.config - Rails.application.config.action_controller.relative_url_root - end + config = controller.config if controller.respond_to?(:config) + config ||= config.action_controller if config.action_controller.present? + config ||= config + config.relative_url_root end def asset_host_config - if config.respond_to?(:asset_host) + if config.action_controller.present? + config.action_controller.asset_host + else config.asset_host - elsif Rails.respond_to?(:application) - Rails.application.config.action_controller.asset_host end end diff --git a/actionpack/lib/sprockets/helpers/rails_helper.rb b/actionpack/lib/sprockets/helpers/rails_helper.rb index 3a77db5fd8..cf185749ea 100644 --- a/actionpack/lib/sprockets/helpers/rails_helper.rb +++ b/actionpack/lib/sprockets/helpers/rails_helper.rb @@ -10,6 +10,12 @@ module Sprockets @asset_paths ||= begin config = self.config if respond_to?(:config) controller = self.controller if respond_to?(:controller) + config ||= Rails.application.config + if config.action_controller.present? + config.action_controller.default_asset_host_protocol ||= :relative + else + config.default_asset_host_protocol ||= :relative + end RailsHelper::AssetPaths.new(config, controller) end end @@ -109,7 +115,7 @@ module Sprockets # When included in Sprockets::Context, we need to ask the top-level config as the controller is not available def performing_caching? - @config ? @config.perform_caching : Rails.application.config.action_controller.perform_caching + config.action_controller.present? ? config.action_controller.perform_caching : config.perform_caching end end end -- cgit v1.2.3