Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a :hide_success option (defaulted to false) for those who only want a growl notification when compilation fails #2

Merged
merged 1 commit into from
May 9, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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