From dffdd829930e664cef522f34730d5987be348596 Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Mon, 29 Aug 2011 16:28:11 -0500 Subject: Read digests of assets from manifest.yml if config.assets.manifest is on --- actionpack/lib/sprockets/helpers/rails_helper.rb | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'actionpack/lib/sprockets/helpers') diff --git a/actionpack/lib/sprockets/helpers/rails_helper.rb b/actionpack/lib/sprockets/helpers/rails_helper.rb index 062aa4dae5..8e7eb182fd 100644 --- a/actionpack/lib/sprockets/helpers/rails_helper.rb +++ b/actionpack/lib/sprockets/helpers/rails_helper.rb @@ -14,6 +14,7 @@ module Sprockets paths = RailsHelper::AssetPaths.new(config, controller) paths.asset_environment = asset_environment paths.asset_prefix = asset_prefix + paths.asset_digests = asset_digests paths end end @@ -76,6 +77,10 @@ module Sprockets Rails.application.config.assets.prefix end + def asset_digests + Rails.application.config.assets.digests + 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+. @@ -84,7 +89,9 @@ module Sprockets end class AssetPaths < ::ActionView::AssetPaths #:nodoc: - attr_accessor :asset_environment, :asset_prefix + attr_accessor :asset_environment, :asset_prefix, :asset_digests + + class AssetNotPrecompiledError < StandardError; end def compute_public_path(source, dir, ext=nil, include_host=true, protocol=nil) super(source, asset_prefix, ext, include_host, protocol) @@ -103,6 +110,14 @@ module Sprockets end def digest_for(logical_path) + if asset_digests && (digest = asset_digests[logical_path]) + return digest + end + + if digest.nil? && Rails.application.config.assets.precompile_only + raise AssetNotPrecompiledError + end + if asset = asset_environment[logical_path] return asset.digest_path end -- cgit v1.2.3