2011-06-17 10:32:50 +00:00
|
|
|
require 'guard'
|
|
|
|
require 'guard/guard'
|
2011-07-31 20:37:09 +00:00
|
|
|
require 'rake/dsl_definition'
|
2011-06-17 10:32:50 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2011-07-31 20:37:09 +00:00
|
|
|
def create_rails_runner
|
|
|
|
@rails_runner = RailsRunner.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def rails_runner
|
|
|
|
@rails_runner ||= create_rails_runner
|
|
|
|
end
|
|
|
|
|
2011-06-17 10:32:50 +00:00
|
|
|
def start
|
2011-07-31 20:37:09 +00:00
|
|
|
create_rails_runner
|
|
|
|
|
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-07-31 20:37:09 +00:00
|
|
|
rails_runner.restart_rails
|
|
|
|
|
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 13:23:04 +00:00
|
|
|
puts 'Compiling rails assets'
|
2011-07-31 20:37:09 +00:00
|
|
|
result = rails_runner.compile_assets
|
|
|
|
|
2011-06-17 12:14:17 +00:00
|
|
|
if result
|
2011-06-19 17:32:14 +00:00
|
|
|
Notifier::notify 'Assets compiled'
|
2011-06-17 12:14:17 +00:00
|
|
|
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
|
|
|
def run_for? command
|
|
|
|
run_on = @options[:run_on]
|
2011-07-15 01:57:14 +00:00
|
|
|
run_on = [:start, :change] if not run_on or run_on.to_s.empty?
|
2011-06-17 13:23:04 +00:00
|
|
|
run_on = [run_on] unless run_on.respond_to?(:include?)
|
2011-06-17 12:14:17 +00:00
|
|
|
run_on.include?(command)
|
|
|
|
end
|
2011-06-17 10:32:50 +00:00
|
|
|
end
|
|
|
|
end
|
2011-07-31 20:37:09 +00:00
|
|
|
|
|
|
|
require 'guard/rails-assets/rails_runner'
|