Permalink
Browse files

Merge pull request #2786 from spohlenz/extract-asset-paths-config-master

Remove explicit references to Rails.application.config from AssetPaths in Sprockets helper
  • Loading branch information...
2 parents 3ce3b5b + d5165e5 commit 9af2b5eeaa33861ad9613fb2c23083e89234eea5 @josevalim josevalim committed Sep 1, 2011
Showing with 14 additions and 5 deletions.
  1. +14 −5 actionpack/lib/sprockets/helpers/rails_helper.rb
@@ -15,6 +15,8 @@ def asset_paths
paths.asset_environment = asset_environment
paths.asset_prefix = asset_prefix
paths.asset_digests = asset_digests
+ paths.compile_assets = compile_assets?
+ paths.digest_assets = digest_assets?
paths
end
end
@@ -60,8 +62,7 @@ def asset_path(source, default_ext = nil, body = false, protocol = nil)
private
def debug_assets?
begin
- config = Rails.application.config.assets
- config.compile && (config.debug || params[:debug_assets])
+ compile_assets? && (Rails.application.config.assets.debug || params[:debug_assets])
rescue NoMethodError
false
end
@@ -81,6 +82,14 @@ def asset_digests
Rails.application.config.assets.digests
end
+ def compile_assets?
+ Rails.application.config.assets.compile
+ end
+
+ def digest_assets?
+ Rails.application.config.assets.digest
+ end
+
# Override to specify an alternative asset environment for asset
# path generation. The environment should already have been mounted
# at the prefix returned by +asset_prefix+.
@@ -89,7 +98,7 @@ def asset_environment
end
class AssetPaths < ::ActionView::AssetPaths #:nodoc:
- attr_accessor :asset_environment, :asset_prefix, :asset_digests
+ attr_accessor :asset_environment, :asset_prefix, :asset_digests, :compile_assets, :digest_assets
class AssetNotPrecompiledError < StandardError; end
@@ -114,7 +123,7 @@ def digest_for(logical_path)
return digest
end
- if Rails.application.config.assets.compile
+ if compile_assets
if asset = asset_environment[logical_path]
return asset.digest_path
end
@@ -128,7 +137,7 @@ def rewrite_asset_path(source, dir)
if source[0] == ?/
source
else
- source = digest_for(source) if Rails.application.config.assets.digest
+ source = digest_for(source) if digest_assets
source = File.join(dir, source)
source = "/#{source}" unless source =~ /^\//
source

0 comments on commit 9af2b5e

Please sign in to comment.