Skip to content

Commit

Permalink
Merge pull request #113 from WojtekKruszewski/notify_option
Browse files Browse the repository at this point in the history
Optionally push system notifications when reloading
  • Loading branch information
thibaudgg committed Jun 25, 2014
2 parents c95da08 + 9dc465f commit e18f4dd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,16 @@ end
Available options:

``` ruby
notify: true # default false
host: '127.3.3.1' # default '0.0.0.0'
port: '12345' # default '35729'
apply_css_live: false # default true
override_url: false # default false
grace_period: 0.5 # default 0 (seconds)
```

See [LiveReload configuration doc](https://github.com/mockko/livereload/blob/master/README-old.md) from version 1.x for more info about those options.
`notify` uses Guard's [system notifications](https://github.com/guard/guard/wiki/System-notifications).
See [LiveReload configuration doc](https://github.com/mockko/livereload/blob/master/README-old.md) from version 1.x for more info about other options.

## Development

Expand Down
7 changes: 6 additions & 1 deletion lib/guard/livereload/reactor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ def stop
end

def reload_browser(paths = [])
UI.info "Reloading browser: #{paths.join(' ')}"
msg = "Reloading browser: #{paths.join(' ')}"
UI.info msg
if options[:notify]
Notifier.notify(msg, title: 'Reloading browser', image: :success)
end

paths.each do |path|
data = _data(path)
UI.debug(data)
Expand Down
14 changes: 13 additions & 1 deletion spec/lib/guard/livereload/reactor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,22 @@

describe "#reload_browser(paths = [])" do
it "displays a message" do
expect(Guard::UI).to receive(:info).with("Reloading browser: stylesheets/layout.css stylesheets/style.css")
expect(Guard::UI).to receive(:info).
with('Reloading browser: stylesheets/layout.css stylesheets/style.css')
new_live_reactor.reload_browser(paths)
end

it 'by default does not send notification' do
expect(::Guard::Notifier).to_not receive(:notify)
new_live_reactor.reload_browser(paths)
end

it 'optionally pushes notification' do
expect(::Guard::Notifier).to receive(:notify).
with(kind_of(String), have_key(:title))
new_live_reactor(notify: true).reload_browser(paths)
end

it "each web socket receives send with data containing default options for each path modified" do
reactor = new_live_reactor
paths.each do |path|
Expand Down

0 comments on commit e18f4dd

Please sign in to comment.