aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorGuillermo Iguaran <guilleiguaran@gmail.com>2011-08-29 16:28:11 -0500
committerGuillermo Iguaran <guilleiguaran@gmail.com>2011-08-31 12:41:28 -0500
commitdffdd829930e664cef522f34730d5987be348596 (patch)
tree6ccbfc5d488ac58269484e9bc932a269d07bc9ab /actionpack
parent508f33f35c9ce7a8973c1cf3466223313dfcfb24 (diff)
downloadrails-dffdd829930e664cef522f34730d5987be348596.tar.gz
rails-dffdd829930e664cef522f34730d5987be348596.tar.bz2
rails-dffdd829930e664cef522f34730d5987be348596.zip
Read digests of assets from manifest.yml if config.assets.manifest is on
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/sprockets/assets.rake10
-rw-r--r--actionpack/lib/sprockets/helpers/rails_helper.rb17
-rw-r--r--actionpack/lib/sprockets/railtie.rb6
3 files changed, 31 insertions, 2 deletions
diff --git a/actionpack/lib/sprockets/assets.rake b/actionpack/lib/sprockets/assets.rake
index 5698f22080..7ee82ee530 100644
--- a/actionpack/lib/sprockets/assets.rake
+++ b/actionpack/lib/sprockets/assets.rake
@@ -19,7 +19,8 @@ namespace :assets do
config = Rails.application.config
env = Rails.application.assets
- target = Rails.root.join("public#{config.assets.prefix}")
+ target = Pathname.new(File.join(Rails.public_path, config.assets.prefix))
+ manifest = {}
if env.respond_to?(:each_logical_path)
config.assets.precompile.each do |path|
@@ -31,6 +32,7 @@ namespace :assets do
end
if asset = env.find_asset(logical_path)
+ manifest[logical_path] = asset.digest_path
filename = target.join(asset.digest_path)
mkdir_p filename.dirname
asset.write_to(filename)
@@ -44,6 +46,12 @@ namespace :assets do
assets << {:to => target}
env.precompile(*assets)
end
+
+ if config.assets.manifest
+ File.open("#{target}/manifest.yml", 'w') do |f|
+ YAML.dump(manifest, f)
+ end
+ end
end
end
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
diff --git a/actionpack/lib/sprockets/railtie.rb b/actionpack/lib/sprockets/railtie.rb
index c21bf57935..680cb980ff 100644
--- a/actionpack/lib/sprockets/railtie.rb
+++ b/actionpack/lib/sprockets/railtie.rb
@@ -26,6 +26,12 @@ module Sprockets
end
end
+ if config.assets.manifest
+ if File.exist?(path = File.join(Rails.public_path, config.assets.prefix, "manifest.yml"))
+ config.assets.digests = YAML.load_file(path)
+ end
+ end
+
ActiveSupport.on_load(:action_view) do
include ::Sprockets::Helpers::RailsHelper