Browse files

obey config.assets.prefix. Closes #1. Closes #2.

Instead of doing an `rm -rf`, rely on `rake assets:clean`, which already
obeys the setting. Unfortunately, the call to figure out the count of assets
compiled would still need to have a directory specified. Thus, it's been
removed. Less information, but the compilation still works fine.
  • Loading branch information...
1 parent 13d954d commit 8424beee1e624e0835e28a946ac4664612839337 James A. Rosen committed Jun 19, 2011
Showing with 4 additions and 12 deletions.
  1. +2 −5 lib/guard/rails-assets.rb
  2. +2 −7 spec/guard/rails-assets_spec.rb
@@ -26,12 +26,9 @@ def run_on_change(paths=[])
def compile_assets
puts 'Compiling rails assets'
- result = system "rm -rf public/assets && bundle exec rake assets:precompile"
+ result = system "bundle exec rake assets:clean assets:precompile"
if result
- tree = `tree public/assets`
- puts tree
- summary = tree.split("\n").last
- Notifier::notify summary, :title => 'Assets compiled'
+ Notifier::notify 'Assets compiled'
Notifier::notify 'see the details in the terminal', :title => "Can't compile assets", :image => :failed
@@ -28,13 +28,12 @@
describe 'asset compilation using CLI' do
def stub_system_with result
- subject.should_receive(:system).with("rm -rf public/assets && bundle exec rake assets:precompile").and_return result
+ subject.should_receive(:system).with("bundle exec rake assets:clean assets:precompile").and_return result
it 'should notify on success' do
stub_system_with true
- subject.should_receive(:`).with('tree public/assets').and_return "a\nb\n1 directory, 2 files"
- Guard::Notifier.should_receive(:notify).with('1 directory, 2 files', :title => 'Assets compiled')
+ Guard::Notifier.should_receive(:notify).with('Assets compiled')
it 'should notify on failure' do
@@ -44,8 +43,4 @@ def stub_system_with result
- describe 'custom assets prefix' do
- it 'should use given prefix'
- end

12 comments on commit 8424bee

It looks like rake assets:clean only removes the js and css files only. I prefer to have a clean sheet before compilation. So I guess keeping the assets_prefix option would be useful for cases when rails cleanup doesn't clean properly. But I agree that making the rails clean task default makes more sense.


jamesarosen replied Jun 20, 2011

If we went this direction, my plan was to do the following:

# in lib/tasks/assets.rake
task :clean_image_assets => :environment do
  `rm -rf #{Rails.root + 'public/' + MyApp::Application.config.assets.prefix}`

namespace :assets do
  task :clean => :clean_image_assets

My hope is that Rails will eventually make this default behavior.

In 2 words, there are 2 main problems now:

  1. We have to manually configure assets_prefix to clean up or otherwise
  2. The assets directory is not fully cleaned up.

Addressing both at the same time doesn't look possible as they are mutually exclusive for now (until rails will do something similar to rm -rf public/assets).
But what we can do - is to provide an option: assets_prefix. When it is set, then the rm -rf public/#{assets_prefix} is used. Otherwise, default rails' rake task.
Additionally, when assets_prefix is specified, we can print more information using tree or similar.

Adding rake task just to run one single guard looks a bit dirty to me. I would rather prefer to run the rake tasks via Spork. But would need some clues on how to integrate it.


jamesarosen replied Jun 20, 2011

Sounds good. cf also rails/rails#1355 (comment)

Will work on it later some time .
The decision of clearing ALL js/css ONLY is a bit strange to me on the rails side.
Any ideas on Spork?


jamesarosen replied Jun 20, 2011

They've pulled in my changes, so the assets:clean issue should be resolved in Rails HEAD. I have never used Spork and haven't any thoughts on the matter. What are you thinking it will help with?

I saw. Great. Then the problem is solved and we can safely use rails' tasks. I will update and release the gem later this week.

Spork might help with generating assets faster. Instead of loading the whole Rails environment it could just run the rake tasks directly.


jamesarosen replied Jun 20, 2011

I'll work on some optional Spork support at some point in the next few days.

Any progress with the Spork support? Regenerating assets takes a very long time when it has to load Rails to re-compile assets each time I change a stylesheet. With Spork support this gem is going to be a hugely valuable component of my development environment. Excellent work.

Although spork support would be ideal, I have a fork that pre-loads the rails app into the current ruby/guard process, which gets past the biggest issue (speed) since rails is already loaded.


Also, since rails 3.1 rc5 the whole asset directory gets removed rather than just .js/.css files -

Please sign in to comment.