aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/sprockets/assets.rake
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/lib/sprockets/assets.rake')
-rw-r--r--actionpack/lib/sprockets/assets.rake61
1 files changed, 37 insertions, 24 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