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

56 lines
2 KiB
Ruby
Raw Normal View History

2011-03-21 19:05:56 -04:00
namespace :assets do
desc "Compile all the assets named in config.assets.precompile"
task :precompile do
# 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["environment"].invoke
2011-08-16 11:37:56 -04:00
# Ensure that action view is loaded and the appropriate sprockets hooks get executed
ActionView::Base
# Always perform caching so that asset_path appends the timestamps to file references.
Rails.application.config.action_controller.perform_caching = true
2011-08-21 17:42:06 -04:00
config = Rails.application.config
2011-08-24 11:54:01 -04:00
env = Rails.application.assets
target = Rails.root.join("public#{config.assets.prefix}")
if env.respond_to?(:each_logical_path)
config.assets.precompile.each do |path|
env.each_logical_path do |logical_path|
if path.is_a?(Regexp)
next unless path.match(logical_path)
else
next unless File.fnmatch(path.to_s, logical_path)
end
if asset = env.find_asset(logical_path)
filename = target.join(asset.digest_path)
mkdir_p filename.dirname
asset.write_to(filename)
asset.write_to("#{filename}.gz") if filename.to_s =~ /\.(css|js)$/
end
end
end
else
# TODO: Remove this once we're depending on sprockets beta 15
assets = config.assets.precompile.dup
assets << {:to => target}
env.precompile(*assets)
end
end
2011-03-21 19:05:56 -04:00
end
desc "Remove compiled assets"
task :clean => [:environment, 'tmp:cache:clear'] do
2011-08-21 17:42:06 -04:00
config = Rails.application.config
public_asset_path = File.join(Rails.public_path, config.assets.prefix)
rm_rf public_asset_path, :secure => true
end
end