Skip to content
Browse files

Refactor sprockets asset paths to allow for alternate asset environments

  • Loading branch information...
1 parent 986e193 commit b8fa5f65a6e53f49c64df5102f336af7b13b25dc @spohlenz spohlenz committed
Showing with 18 additions and 9 deletions.
  1. +18 −9 actionpack/lib/sprockets/helpers/rails_helper.rb
View
27 actionpack/lib/sprockets/helpers/rails_helper.rb
@@ -16,7 +16,10 @@ def asset_paths
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 @@ def debug_assets?
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, 'assets', 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 @@ def asset_for(source, ext)
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 @@ def rewrite_extension(source, dir, ext)
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

0 comments on commit b8fa5f6

Please sign in to comment.
Something went wrong with that request. Please try again.