Skip to content

Commit

Permalink
Encapsulate common rake invocation logic in a method.
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Oct 4, 2011
1 parent 0ad5040 commit 188d21c
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions actionpack/lib/sprockets/assets.rake
Expand Up @@ -2,25 +2,29 @@ require "fileutils"


namespace :assets do namespace :assets do
def ruby_rake_task(task) def ruby_rake_task(task)
env = ENV['RAILS_ENV'] || 'production' env = ENV['RAILS_ENV'] || 'production'
groups = ENV['RAILS_GROUPS'] || 'assets' groups = ENV['RAILS_GROUPS'] || 'assets'
args = [$0, task,"RAILS_ENV=#{env}","RAILS_GROUPS=#{groups}"] args = [$0, task,"RAILS_ENV=#{env}","RAILS_GROUPS=#{groups}"]
args << "--trace" if Rake.application.options.trace args << "--trace" if Rake.application.options.trace
ruby *args ruby *args
end end


desc "Compile all the assets named in config.assets.precompile" # We are currently running with no explicit bundler group
task :precompile do # and/or no explicit environment - we have to reinvoke rake to
# execute this task.
def invoke_or_reboot_rake_task(task)
if ENV['RAILS_GROUPS'].to_s.empty? || ENV['RAILS_ENV'].to_s.empty? if ENV['RAILS_GROUPS'].to_s.empty? || ENV['RAILS_ENV'].to_s.empty?
# We are currently running with no explicit bundler group ruby_rake_task task
# and/or no explicit environment - we have to reinvoke rake to
# execute this task.
ruby_rake_task "assets:precompile:all"
else else
Rake::Task["assets:precompile:all"].invoke Rake::Task[task].invoke
end end
end end


desc "Compile all the assets named in config.assets.precompile"
task :precompile do
invoke_or_reboot_rake_task "assets:precompile:all"
end

namespace :precompile do namespace :precompile do
def internal_precompile(digest=nil) def internal_precompile(digest=nil)
unless Rails.application.config.assets.enabled unless Rails.application.config.assets.enabled
Expand Down Expand Up @@ -70,14 +74,7 @@ namespace :assets do


desc "Remove compiled assets" desc "Remove compiled assets"
task :clean do task :clean do
if ENV['RAILS_GROUPS'].to_s.empty? || ENV['RAILS_ENV'].to_s.empty? invoke_or_reboot_rake_task "assets:clean:all"
# We are currently running with no explicit bundler group
# and/or no explicit environment - we have to reinvoke rake to
# execute this task.
ruby_rake_task "assets:clean:all"
else
Rake::Task["assets:clean:all"].invoke
end
end end


namespace :clean do namespace :clean do
Expand Down

0 comments on commit 188d21c

Please sign in to comment.