Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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...
commit 8424beee1e624e0835e28a946ac4664612839337 1 parent 13d954d
James A. Rosen authored
Showing with 4 additions and 12 deletions.
  1. +2 −5 lib/guard/rails-assets.rb
  2. +2 −7 spec/guard/rails-assets_spec.rb
View
7 lib/guard/rails-assets.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'
else
Notifier::notify 'see the details in the terminal', :title => "Can't compile assets", :image => :failed
end
View
9 spec/guard/rails-assets_spec.rb
@@ -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
end
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')
subject.compile_assets
end
it 'should notify on failure' do
@@ -44,8 +43,4 @@ def stub_system_with result
subject.compile_assets
end
end
-
- describe 'custom assets prefix' do
- it 'should use given prefix'
- end
end

12 comments on commit 8424bee

@dnagir

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

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}`
end

namespace :assets do
  task :clean => :clean_image_assets
end

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

@dnagir

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

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

@dnagir

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

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?

@dnagir

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

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

@nmertaugh

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.

@dnagir
@stevehodgkiss

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.

stevehodgkiss@431daf1

@stevehodgkiss

Also, since rails 3.1 rc5 the whole asset directory gets removed rather than just .js/.css files - https://github.com/rails/rails/blob/v3.1.0.rc5/actionpack/lib/sprockets/assets.rake

Please sign in to comment.
Something went wrong with that request. Please try again.