diff options
author | José Valim <jose.valim@gmail.com> | 2011-10-04 11:24:12 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2011-10-04 11:25:36 +0200 |
commit | 7f1a666db57983814e175cb5b54bb6621ec95c4f (patch) | |
tree | 205458145643a25fa5154aeb58fe8dc8aa06e8d4 | |
parent | 88f60fd1a744d93528dc36fa1461a59df3efc6a3 (diff) | |
download | rails-7f1a666db57983814e175cb5b54bb6621ec95c4f.tar.gz rails-7f1a666db57983814e175cb5b54bb6621ec95c4f.tar.bz2 rails-7f1a666db57983814e175cb5b54bb6621ec95c4f.zip |
Fix failing tests and refactor assets.rake
-rw-r--r-- | actionpack/lib/sprockets/assets.rake | 61 | ||||
-rw-r--r-- | railties/test/application/assets_test.rb | 2 |
2 files changed, 38 insertions, 25 deletions
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 diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index e0e36063c8..efbed35bdf 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -247,7 +247,7 @@ module ApplicationTests test "precompile properly refers files referenced with asset_path and and run in the provided RAILS_ENV" do app_file "app/assets/stylesheets/application.css.erb", "<%= asset_path('rails.png') %>" # digest is default in false, we must enable it for test environment - add_to_config "config.assets.digest = true" + add_to_env_config "test", "config.assets.digest = true" quietly do Dir.chdir(app_path){ `bundle exec rake assets:precompile RAILS_ENV=test` } |