diff options
author | José Valim <jose.valim@gmail.com> | 2011-08-31 11:25:47 -0700 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2011-08-31 11:25:47 -0700 |
commit | e3efe78a5f127970cf47ba15889ae131604813ac (patch) | |
tree | 50c5041a32766e460e380d7f34c2a649f654d231 /actionpack/lib | |
parent | 508f33f35c9ce7a8973c1cf3466223313dfcfb24 (diff) | |
parent | 87074600d3f7909bce7884c4588aab83f1b3a2d1 (diff) | |
download | rails-e3efe78a5f127970cf47ba15889ae131604813ac.tar.gz rails-e3efe78a5f127970cf47ba15889ae131604813ac.tar.bz2 rails-e3efe78a5f127970cf47ba15889ae131604813ac.zip |
Merge pull request #2772 from guilleiguaran/backports-assets-pipeline
Backports of the assets pipeline changes done in 3-1-stable
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/sprockets/assets.rake | 9 | ||||
-rw-r--r-- | actionpack/lib/sprockets/helpers/rails_helper.rb | 36 | ||||
-rw-r--r-- | actionpack/lib/sprockets/railtie.rb | 10 |
3 files changed, 38 insertions, 17 deletions
diff --git a/actionpack/lib/sprockets/assets.rake b/actionpack/lib/sprockets/assets.rake index 5698f22080..6f38ece0c3 100644 --- a/actionpack/lib/sprockets/assets.rake +++ b/actionpack/lib/sprockets/assets.rake @@ -19,7 +19,9 @@ 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 = {} + manifest_path = config.assets.manifest || target if env.respond_to?(:each_logical_path) config.assets.precompile.each do |path| @@ -31,6 +33,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 +47,10 @@ namespace :assets do assets << {:to => target} env.precompile(*assets) end + + File.open("#{manifest_path}/manifest.yml", 'w') do |f| + YAML.dump(manifest, f) + end end end diff --git a/actionpack/lib/sprockets/helpers/rails_helper.rb b/actionpack/lib/sprockets/helpers/rails_helper.rb index 062aa4dae5..975dc9e80c 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 @@ -60,7 +61,7 @@ module Sprockets def debug_assets? begin config = Rails.application.config.assets - config.allow_debugging && (config.debug || params[:debug_assets]) + config.compile && (config.debug || params[:debug_assets]) rescue NoMethodError false 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,18 +110,25 @@ module Sprockets end def digest_for(logical_path) - if asset = asset_environment[logical_path] - return asset.digest_path + if asset_digests && (digest = asset_digests[logical_path]) + return digest end - logical_path + if Rails.application.config.assets.compile + if asset = asset_environment[logical_path] + return asset.digest_path + end + return logical_path + else + raise AssetNotPrecompiledError.new("#{logical_path} isn't precompiled") + end end def rewrite_asset_path(source, dir) if source[0] == ?/ source else - source = digest_for(source) if performing_caching? + source = digest_for(source) if Rails.application.config.assets.digest source = File.join(dir, source) source = "/#{source}" unless source =~ /^\// source @@ -128,16 +142,6 @@ module Sprockets source end end - - def performing_caching? - # When included in Sprockets::Context, we need to ask the - # top-level config as the controller is not available. - if config.action_controller.present? - config.action_controller.perform_caching - else - config.perform_caching - end - end end end end diff --git a/actionpack/lib/sprockets/railtie.rb b/actionpack/lib/sprockets/railtie.rb index c21bf57935..7927b7bc2c 100644 --- a/actionpack/lib/sprockets/railtie.rb +++ b/actionpack/lib/sprockets/railtie.rb @@ -26,6 +26,16 @@ module Sprockets end end + if config.assets.manifest + path = File.join(config.assets.manifest, "manifest.yml") + else + path = File.join(Rails.public_path, config.assets.prefix, "manifest.yml") + end + + if File.exist?(path) + config.assets.digests = YAML.load_file(path) + end + ActiveSupport.on_load(:action_view) do include ::Sprockets::Helpers::RailsHelper |