Skip to content
Browse files

Fix failing tests and refactor assets.rake

  • Loading branch information...
1 parent 9d34991 commit 360b8c4c52da408517f0fe08e5d33a6e8d768c33 @josevalim josevalim committed Oct 4, 2011
Showing with 38 additions and 25 deletions.
  1. +37 −24 actionpack/lib/sprockets/assets.rake
  2. +1 −1 railties/test/application/assets_test.rb
View
61 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
View
2 railties/test/application/assets_test.rb
@@ -247,7 +247,7 @@ class ::PostsController < ActionController::Base ; end
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` }

0 comments on commit 360b8c4

Please sign in to comment.
Something went wrong with that request. Please try again.