From 7f1a666db57983814e175cb5b54bb6621ec95c4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 4 Oct 2011 11:24:12 +0200 Subject: Fix failing tests and refactor assets.rake --- actionpack/lib/sprockets/assets.rake | 61 ++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 24 deletions(-) (limited to 'actionpack/lib/sprockets') diff --git a/actionpack/lib/sprockets/assets.rake b/actionpack/lib/sprockets/assets.rake index cc1e70d114..000e7175c0 100644 --- a/actionpack/lib/sprockets/assets.rake +++ b/actionpack/lib/sprockets/assets.rake @@ -1,51 +1,64 @@ require "fileutils" namespace :assets do - def invoke_precompile - args = [$0, "assets:internal_precompile"] + def ruby_rake_task(task) + args = [$0, task] args << "--trace" if Rake.application.options.trace ruby *args end desc "Compile all the assets named in config.assets.precompile" - task :precompile => "assets:clean" do + task :precompile do ENV["RAILS_GROUPS"] ||= "assets" ENV["RAILS_ENV"] ||= "production" - invoke_precompile + ruby_rake_task "assets:precompile:all" end - task :internal_precompile => "assets:environment" do - unless Rails.application.config.assets.enabled - raise "Cannot precompile assets if sprockets is disabled. Please set config.assets.enabled to true" - end + namespace :precompile do + def internal_precompile(digest=nil) + unless Rails.application.config.assets.enabled + warn "Cannot precompile assets if sprockets is disabled. Please set config.assets.enabled to true" + exit + end - # Ensure that action view is loaded and the appropriate sprockets hooks get executed - _ = ActionView::Base + # Ensure that action view is loaded and the appropriate + # sprockets hooks get executed + _ = ActionView::Base - config = Rails.application.config - config.assets.compile = true - config.assets.digest = false if ENV["RAILS_ASSETS_NONDIGEST"] - config.assets.digests = {} + config = Rails.application.config + config.assets.compile = true + config.assets.digest = digest unless digest.nil? + config.assets.digests = {} + + env = Rails.application.assets + target = File.join(Rails.public_path, config.assets.prefix) + static_compiler = Sprockets::StaticCompiler.new(env, target, :digest => config.assets.digest) + static_compiler.precompile(config.assets.precompile) + end - env = Rails.application.assets - target = File.join(Rails.public_path, config.assets.prefix) - static_compiler = Sprockets::StaticCompiler.new(env, target, :digest => config.assets.digest) + task :all do + Rake::Task["assets:precompile:digest"].invoke + ruby_rake_task "assets:precompile:nondigest" + end - manifest = static_compiler.precompile(config.assets.precompile) - manifest_path = config.assets.manifest || target - FileUtils.mkdir_p(manifest_path) + task :digest => ["assets:environment", "tmp:cache:clear"] do + manifest = internal_precompile + config = Rails.application.config + manifest_path = config.assets.manifest || File.join(Rails.public_path, config.assets.prefix) + FileUtils.mkdir_p(manifest_path) - unless ENV["RAILS_ASSETS_NONDIGEST"] File.open("#{manifest_path}/manifest.yml", 'wb') do |f| YAML.dump(manifest, f) end - ENV["RAILS_ASSETS_NONDIGEST"] = "true" - invoke_precompile + end + + task :nondigest => ["assets:environment", "tmp:cache:clear"] do + internal_precompile(false) end end desc "Remove compiled assets" - task :clean => "tmp:cache:clear" do + task :clean => ["assets:environment", "tmp:cache:clear"] do config = Rails.application.config public_asset_path = File.join(Rails.public_path, config.assets.prefix) rm_rf public_asset_path, :secure => true -- cgit v1.2.3