2011-03-21 19:05:56 -04:00
|
|
|
namespace :assets do
|
2011-04-18 05:18:37 -04:00
|
|
|
desc "Compile all the assets named in config.assets.precompile"
|
2011-08-14 13:52:46 -04:00
|
|
|
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.
|
2011-08-15 14:31:47 -04:00
|
|
|
if ENV["RAILS_GROUPS"].to_s.empty? || ENV["RAILS_ENV"].to_s.empty?
|
|
|
|
ENV["RAILS_GROUPS"] ||= "assets"
|
|
|
|
ENV["RAILS_ENV"] ||= "production"
|
2011-08-14 13:52:46 -04:00
|
|
|
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
|
2011-04-19 14:06:09 -04:00
|
|
|
|
2011-08-31 19:53:51 -04:00
|
|
|
# Always compile files
|
2011-08-31 10:42:43 -04:00
|
|
|
Rails.application.config.assets.compile = 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
|
2011-08-29 17:28:11 -04:00
|
|
|
target = Pathname.new(File.join(Rails.public_path, config.assets.prefix))
|
|
|
|
manifest = {}
|
2011-08-30 17:30:53 -04:00
|
|
|
manifest_path = config.assets.manifest || target
|
2011-08-24 11:54:01 -04:00
|
|
|
|
2011-08-31 21:50:38 -04:00
|
|
|
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
|
2011-08-24 11:54:01 -04:00
|
|
|
|
2011-08-31 21:50:38 -04:00
|
|
|
if asset = env.find_asset(logical_path)
|
2011-08-31 19:53:51 -04:00
|
|
|
asset_path = config.assets.digest ? asset.digest_path : logical_path
|
|
|
|
manifest[logical_path] = asset_path
|
|
|
|
filename = target.join(asset_path)
|
|
|
|
|
2011-08-31 21:50:38 -04:00
|
|
|
mkdir_p filename.dirname
|
|
|
|
asset.write_to(filename)
|
|
|
|
asset.write_to("#{filename}.gz") if filename.to_s =~ /\.(css|js)$/
|
2011-08-24 11:54:01 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2011-08-29 17:28:11 -04:00
|
|
|
|
2011-08-30 17:30:53 -04:00
|
|
|
File.open("#{manifest_path}/manifest.yml", 'w') do |f|
|
2011-08-31 13:47:33 -04:00
|
|
|
YAML.dump(manifest, f)
|
2011-08-29 17:28:11 -04:00
|
|
|
end
|
2011-08-14 13:52:46 -04:00
|
|
|
end
|
2011-03-21 19:05:56 -04:00
|
|
|
end
|
2011-05-27 03:29:54 -04:00
|
|
|
|
|
|
|
desc "Remove compiled assets"
|
2011-08-04 19:17:03 -04:00
|
|
|
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)
|
2011-07-16 18:44:00 -04:00
|
|
|
rm_rf public_asset_path, :secure => true
|
2011-05-27 03:29:54 -04:00
|
|
|
end
|
2011-08-15 14:31:47 -04:00
|
|
|
end
|