1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actionpack/lib/sprockets/assets.rake
José Valim eb367afeed rake assets:precompile loads the application but does not initialize it.
To the app developer, this means configuration add in
config/initializers/* will not be executed.

Plugins developers need to special case their initializers that are
meant to be run in the assets group by adding :group => :assets.

Conflicts:

	railties/CHANGELOG
	railties/test/application/assets_test.rb
2011-09-24 03:17:23 +02:00

44 lines
1.6 KiB
Ruby

namespace :assets do
desc "Compile all the assets named in config.assets.precompile"
task :precompile do
# let rails know we're precompiling assets
ENV["RAILS_ASSETS_PRECOMPILE"] = 'true'
# We need to do this dance because RAILS_GROUPS is used
# too early in the boot process and changing here is already too late.
if ENV["RAILS_GROUPS"].to_s.empty? || ENV["RAILS_ENV"].to_s.empty?
ENV["RAILS_GROUPS"] ||= "assets"
ENV["RAILS_ENV"] ||= "production"
Kernel.exec $0, *ARGV
else
Rake::Task["tmp:cache:clear"].invoke
Rails.application.initialize!(:assets)
Sprockets::Bootstrap.new(Rails.application).run
# Ensure that action view is loaded and the appropriate sprockets hooks get executed
ActionView::Base
# Always compile files
Rails.application.config.assets.compile = true
config = Rails.application.config
env = Rails.application.assets
target = Pathname.new(File.join(Rails.public_path, config.assets.prefix))
manifest_path = config.assets.manifest || target
static_compiler = Sprockets::StaticCompiler.new(env, target, :digest => config.assets.digest)
manifest = static_compiler.precompile(config.assets.precompile)
File.open("#{manifest_path}/manifest.yml", 'wb') do |f|
YAML.dump(manifest, f)
end
end
end
desc "Remove compiled assets"
task :clean => [: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
end
end