guard-rails-assets/lib/guard/rails-assets.rb

47 lines
1.0 KiB
Ruby
Raw Normal View History

2011-06-17 10:32:50 +00:00
require 'guard'
require 'guard/guard'
module Guard
class RailsAssets < Guard
def initialize(watchers=[], options={})
super
2011-06-17 12:14:17 +00:00
@options = options || {}
2011-06-17 10:32:50 +00:00
end
def start
2011-06-17 12:14:17 +00:00
compile_assets if run_for? :start
2011-06-17 10:32:50 +00:00
end
def reload
2011-06-17 12:14:17 +00:00
compile_assets if run_for? :reload
2011-06-17 10:32:50 +00:00
end
def run_all
2011-06-17 12:14:17 +00:00
compile_assets if run_for? :all
2011-06-17 10:32:50 +00:00
end
2011-06-17 12:14:17 +00:00
def run_on_change(paths=[])
compile_assets if run_for? :change
2011-06-17 10:32:50 +00:00
end
def compile_assets
2011-06-17 12:14:17 +00:00
result = system "rm -rf public/assets && bundle exec rake assets:precompile"
if result
tree = `tree public/assets`
summary = tree.split("\n").last
Notifier::notify summary, :title => 'Assets compiled'
else
Notifier::notify 'see the details in the terminal', :title => "Can't compile assets", :image => :failed
end
2011-06-17 10:32:50 +00:00
end
2011-06-17 12:14:17 +00:00
private
def run_for? command
run_on = @options[:run_on]
run_on = [:start, :all, :change] if not run_on or run_on.empty?
run_on.include?(command)
end
2011-06-17 10:32:50 +00:00
end
end