Permalink
Browse files

Move the config bootstrapping to initialization to minimize access to…

… the Rails.application global.
  • Loading branch information...
chriseppstein committed Jun 18, 2011
1 parent 6c64e1e commit 2cc1bc37732a5f89c8364e6724e8c39e14216a0a
Showing with 14 additions and 11 deletions.
  1. +7 −10 actionpack/lib/action_view/asset_paths.rb
  2. +7 −1 actionpack/lib/sprockets/helpers/rails_helper.rb
@@ -107,20 +107,17 @@ def compute_asset_host(source)
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
@@ -10,6 +10,12 @@ def asset_paths
@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 @@ def assets
# 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

0 comments on commit 2cc1bc3

Please sign in to comment.