Skip to content

Commit

Permalink
Add a :hide_success option (defaulted to false) for those who only ne…
Browse files Browse the repository at this point in the history
…ed a growl notification when compilation fails
  • Loading branch information
hoverbird committed May 8, 2011
1 parent 74ecc2b commit fd63672
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
3 changes: 2 additions & 1 deletion lib/guard/coffeescript.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ def initialize(watchers = [], options = {})

super(watchers, {
:bare => false,
:shallow => false
:shallow => false,
:hide_success => false,
}.merge(options))
end

Expand Down
10 changes: 5 additions & 5 deletions lib/guard/coffeescript/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class << self
def run(files, watchers, options = {})
notify_start(files, options)
changed_files, errors = compile_files(files, options, watchers)
notify_result(changed_files, errors)
notify_result(changed_files, errors, options)

changed_files
rescue ::CoffeeScript::EngineError => e
Expand Down Expand Up @@ -74,12 +74,12 @@ def detect_nested_directories(watchers, files, options)
directories
end

def notify_result(changed_files, errors)
if errors.empty?
def notify_result(changed_files, errors, options = {})
if !errors.empty?
::Guard::Notifier.notify(errors.join("\n"), :title => 'CoffeeScript results', :image => :failed)
elsif !options[:hide_success]
message = "Successfully generated #{ changed_files.join(', ') }"
::Guard::Notifier.notify(message, :title => 'CoffeeScript results')
else
::Guard::Notifier.notify(errors.join("\n"), :title => 'CoffeeScript results', :image => :failed)
end
end

Expand Down
11 changes: 11 additions & 0 deletions spec/guard/coffeescript/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,17 @@
Guard::Notifier.should_receive(:notify).with('Successfully generated javascripts/a.js', :title => 'CoffeeScript results')
runner.run(['a.coffee'], [watcher], { :output => 'javascripts' })
end

context 'with the :hide_success option set to true' do
let(:watcher) { Guard::Watcher.new('^app/coffeescripts/(.*)\.coffee') }

it 'compiles the CoffeeScripts to the output and creates nested directories' do
FileUtils.should_receive(:mkdir_p).with("#{ @project_path }/javascripts/x/y")
Guard::Notifier.should_not_receive(:notify).with('Successfully generated javascripts/a.js', :title => 'CoffeeScript results')
runner.run(['app/coffeescripts/x/y/a.coffee'], [watcher], { :output => 'javascripts', :hide_success => true })
end
end
end

end
end
13 changes: 11 additions & 2 deletions spec/guard/coffeescript_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@
it 'sets a default :shallow option' do
guard.options[:shallow].should be_false
end

it 'sets a default :hide_success option' do
guard.options[:hide_success].should be_false
end
end

context 'with other options than the default ones' do
let(:guard) { Guard::CoffeeScript.new(nil, { :output => 'output_folder', :bare => true, :shallow => true }) }
let(:guard) { Guard::CoffeeScript.new(nil, { :output => 'output_folder', :bare => true, :shallow => true, :hide_success => true }) }

it 'sets the provided :bare option' do
guard.options[:bare].should be_true
Expand All @@ -30,6 +34,10 @@
it 'sets the provided :shallow option' do
guard.options[:shallow].should be_true
end

it 'sets the provided :hide_success option' do
guard.options[:hide_success].should be_true
end
end

context 'with a input option' do
Expand Down Expand Up @@ -74,7 +82,8 @@
Guard::CoffeeScript::Inspector.should_receive(:clean).with(['a.coffee', 'b.coffee']).and_return ['a.coffee']
Guard::CoffeeScript::Runner.should_receive(:run).with(['a.coffee'], [], {
:bare => false,
:shallow => false }).and_return ['a.js']
:shallow => false,
:hide_success => false }).and_return ['a.js']
guard.run_on_change(['a.coffee', 'b.coffee'])
end

Expand Down

0 comments on commit fd63672

Please sign in to comment.