2010-11-08 18:35:23 +00:00
|
|
|
require 'guard'
|
|
|
|
require 'guard/guard'
|
2010-11-08 19:53:07 +00:00
|
|
|
require 'jammit'
|
2011-06-16 14:27:16 +00:00
|
|
|
|
2010-11-08 18:35:23 +00:00
|
|
|
module Guard
|
2010-11-08 19:53:07 +00:00
|
|
|
class Jammit < Guard
|
2010-11-08 18:35:23 +00:00
|
|
|
|
|
|
|
def initialize(watchers = [], options = {})
|
|
|
|
super
|
2010-11-08 19:53:07 +00:00
|
|
|
|
2010-11-08 18:35:23 +00:00
|
|
|
# init stuff here, thx!
|
2011-06-16 19:57:13 +00:00
|
|
|
::Jammit.load_configuration ::Jammit::DEFAULT_CONFIG_PATH
|
2010-11-08 18:35:23 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# ================
|
|
|
|
# = Guard method =
|
|
|
|
# ================
|
|
|
|
|
|
|
|
# If one of those methods raise an exception, the Guard instance
|
|
|
|
# will be removed from the active guard.
|
|
|
|
|
|
|
|
# Call once when guard starts
|
|
|
|
# Please override initialize method to init stuff
|
|
|
|
def start
|
|
|
|
jammit
|
|
|
|
end
|
|
|
|
|
|
|
|
# Call with Ctrl-C signal (when Guard quit)
|
|
|
|
def stop
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
# Call with Ctrl-Z signal
|
|
|
|
# This method should be mainly used for "reload" (really!) actions like reloading passenger/spork/bundler/...
|
|
|
|
def reload
|
|
|
|
jammit
|
|
|
|
end
|
|
|
|
|
|
|
|
# Call with Ctrl-/ signal
|
|
|
|
# This method should be principally used for long action like running all specs/tests/...
|
|
|
|
def run_all
|
|
|
|
jammit
|
|
|
|
end
|
|
|
|
|
|
|
|
# Call on file(s) modifications
|
|
|
|
def run_on_change(paths)
|
|
|
|
jammit
|
|
|
|
end
|
|
|
|
|
|
|
|
def jammit
|
2011-06-16 14:27:16 +00:00
|
|
|
ensure_rails_env!
|
2011-06-16 19:57:13 +00:00
|
|
|
::Jammit.reload!
|
|
|
|
puts "Jamming assets..."
|
2010-11-08 19:53:07 +00:00
|
|
|
::Jammit.packager.force = true
|
|
|
|
::Jammit.packager.precache_all
|
2010-11-08 18:35:23 +00:00
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2011-06-16 14:27:16 +00:00
|
|
|
private
|
|
|
|
def ensure_rails_env!
|
|
|
|
if !defined?(::Rails) || !::Rails.respond_to?(:env)
|
|
|
|
require 'rails'
|
|
|
|
end
|
|
|
|
end
|
2010-11-08 18:35:23 +00:00
|
|
|
end
|
2011-06-16 14:27:16 +00:00
|
|
|
end
|