diff options
author | Sam Pohlenz <sam@sampohlenz.com> | 2011-07-01 17:08:58 +0930 |
---|---|---|
committer | Sam Pohlenz <sam@sampohlenz.com> | 2011-07-01 17:08:58 +0930 |
commit | d5f7253206122296a050d8fe2376990710859947 (patch) | |
tree | 847daa5f553ac2a1c441a7e4347bde561b8aac3e /actionpack | |
parent | cb99c8593a8d5a92378a8167486d5148c1e2dff5 (diff) | |
download | rails-d5f7253206122296a050d8fe2376990710859947.tar.gz rails-d5f7253206122296a050d8fe2376990710859947.tar.bz2 rails-d5f7253206122296a050d8fe2376990710859947.zip |
Refactor sprockets asset paths to allow for alternate asset environments
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/sprockets/helpers/rails_helper.rb | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/actionpack/lib/sprockets/helpers/rails_helper.rb b/actionpack/lib/sprockets/helpers/rails_helper.rb index 63820cc76c..748541746c 100644 --- a/actionpack/lib/sprockets/helpers/rails_helper.rb +++ b/actionpack/lib/sprockets/helpers/rails_helper.rb @@ -16,7 +16,10 @@ module Sprockets else config.default_asset_host_protocol ||= :relative end - RailsHelper::AssetPaths.new(config, controller) + paths = RailsHelper::AssetPaths.new(config, controller) + paths.asset_environment = asset_environment + paths.asset_prefix = asset_prefix + paths end end @@ -76,9 +79,19 @@ module Sprockets params[:debug_assets] == 'true' end + def asset_prefix + Rails.application.config.assets.prefix + end + + def asset_environment + Rails.application.assets + end + class AssetPaths < ::ActionView::AssetPaths #:nodoc: - def compute_public_path(source, dir, ext=nil, include_host=true, protocol = nil) - super(source, Rails.application.config.assets.prefix, ext, include_host, protocol) + attr_accessor :asset_environment, :asset_prefix + + def compute_public_path(source, dir, ext=nil, include_host=true, protocol=nil) + super(source, asset_prefix, ext, include_host, protocol) end # Return the filesystem path for the source @@ -90,14 +103,14 @@ module Sprockets source = source.to_s return nil if is_uri?(source) source = rewrite_extension(source, nil, ext) - assets[source] + asset_environment[source] end def rewrite_asset_path(source, dir) if source[0] == ?/ source else - assets.path(source, performing_caching?, dir) + asset_environment.path(source, performing_caching?, dir) end end @@ -109,10 +122,6 @@ module Sprockets end end - def assets - Rails.application.assets - end - # When included in Sprockets::Context, we need to ask the top-level config as the controller is not available def performing_caching? config.action_controller.present? ? config.action_controller.perform_caching : config.perform_caching |