Refactor sprockets asset paths to allow for alternate asset environments
This commit is contained in:
parent
cb99c8593a
commit
d5f7253206
@ -16,7 +16,10 @@ def asset_paths
|
|||||||
else
|
else
|
||||||
config.default_asset_host_protocol ||= :relative
|
config.default_asset_host_protocol ||= :relative
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -76,9 +79,19 @@ def debug_assets?
|
|||||||
params[:debug_assets] == 'true'
|
params[:debug_assets] == 'true'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def asset_prefix
|
||||||
|
Rails.application.config.assets.prefix
|
||||||
|
end
|
||||||
|
|
||||||
|
def asset_environment
|
||||||
|
Rails.application.assets
|
||||||
|
end
|
||||||
|
|
||||||
class AssetPaths < ::ActionView::AssetPaths #:nodoc:
|
class AssetPaths < ::ActionView::AssetPaths #:nodoc:
|
||||||
def compute_public_path(source, dir, ext=nil, include_host=true, protocol = nil)
|
attr_accessor :asset_environment, :asset_prefix
|
||||||
super(source, Rails.application.config.assets.prefix, ext, include_host, protocol)
|
|
||||||
|
def compute_public_path(source, dir, ext=nil, include_host=true, protocol=nil)
|
||||||
|
super(source, asset_prefix, ext, include_host, protocol)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Return the filesystem path for the source
|
# Return the filesystem path for the source
|
||||||
@ -90,14 +103,14 @@ def asset_for(source, ext)
|
|||||||
source = source.to_s
|
source = source.to_s
|
||||||
return nil if is_uri?(source)
|
return nil if is_uri?(source)
|
||||||
source = rewrite_extension(source, nil, ext)
|
source = rewrite_extension(source, nil, ext)
|
||||||
assets[source]
|
asset_environment[source]
|
||||||
end
|
end
|
||||||
|
|
||||||
def rewrite_asset_path(source, dir)
|
def rewrite_asset_path(source, dir)
|
||||||
if source[0] == ?/
|
if source[0] == ?/
|
||||||
source
|
source
|
||||||
else
|
else
|
||||||
assets.path(source, performing_caching?, dir)
|
asset_environment.path(source, performing_caching?, dir)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -109,10 +122,6 @@ def rewrite_extension(source, dir, ext)
|
|||||||
end
|
end
|
||||||
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
|
# When included in Sprockets::Context, we need to ask the top-level config as the controller is not available
|
||||||
def performing_caching?
|
def performing_caching?
|
||||||
config.action_controller.present? ? config.action_controller.perform_caching : config.perform_caching
|
config.action_controller.present? ? config.action_controller.perform_caching : config.perform_caching
|
||||||
|
Loading…
Reference in New Issue
Block a user