guard-jasmine-headless-webkit/lib/guard/jasmine-headless-webkit.rb

49 lines
1.0 KiB
Ruby
Raw Normal View History

2011-05-23 22:37:19 +00:00
require 'guard'
require 'guard/guard'
2011-05-24 01:28:01 +00:00
require 'guard/jasmine-headless-webkit/runner'
2011-05-23 22:37:19 +00:00
module Guard
class JasmineHeadlessWebkit < Guard
2011-05-24 00:44:18 +00:00
def initialize(watchers = [], options = {})
super
@options = {
:all_on_start => true,
:run_before => false
2011-05-24 00:44:18 +00:00
}.merge(options)
end
2011-05-23 22:37:19 +00:00
def start
UI.info "Guard::JasmineHeadlessWebkit is running."
2011-05-24 00:44:18 +00:00
run_all if @options[:all_on_start]
2011-05-23 22:37:19 +00:00
end
def run_all
JasmineHeadlessWebkitRunner.run if run_before
2011-05-23 22:37:19 +00:00
end
def run_on_change(paths)
if run_before
run_all if JasmineHeadlessWebkitRunner.run(paths) == 0
end
end
private
def run_before
if @options[:run_before]
UI.info "Guard::JasmineHeadlessWebkit running #{@options[:run_before]} first..."
system @options[:run_before]
$?.exitstatus == 0
else
true
end
2011-05-23 22:37:19 +00:00
end
end
2011-05-24 00:59:20 +00:00
class Dsl
def newest_js_file(path)
2011-05-23 22:37:19 +00:00
Dir[path + '*.{js,coffee}'].sort { |left, right| File.mtime(right) <=> File.mtime(left) }.first
end
end
end