guard-mozrepl 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,27 @@
1
+ guard-mozrepl
2
+ =============
3
+
4
+ Make guard reload the current tab when things change.
5
+
6
+ ### Install
7
+
8
+ Install the awesome mozrepl extension, see...
9
+
10
+ https://github.com/bard/mozrepl/wiki
11
+
12
+ Don't forget to activate the Repl.
13
+
14
+ Tools → MozLab → Start MozRepl
15
+
16
+ Put this in your Gemfile
17
+
18
+ gem 'guard-mozrepl'
19
+
20
+ Run this
21
+
22
+ guard init mozrepl
23
+
24
+ ...and you're all set.
25
+
26
+
27
+
@@ -7,7 +7,12 @@ module Guard
7
7
 
8
8
  def initialize(watchers=[], options={})
9
9
  super
10
- @options = options
10
+ @options = {
11
+ :host => options[:host] || 'localhost',
12
+ :port => options[:port] || 4242,
13
+ :verbose => options[:verbose] || false
14
+ }
15
+ mozrepl
11
16
  end
12
17
 
13
18
  # Called once when Guard starts
@@ -36,6 +41,8 @@ module Guard
36
41
 
37
42
  # Called on file(s) modifications
38
43
  def run_on_change(paths)
44
+ return true if @serious_issue
45
+ puts "Reload tab via MozRepl for #{paths * ' '}" if @options[:verbose]
39
46
  reload_current_tab!
40
47
  end
41
48
 
@@ -43,11 +50,21 @@ module Guard
43
50
 
44
51
  def reload_current_tab!
45
52
  mozrepl.cmd('content.location.reload();')
53
+ rescue
54
+ warn "Error sending command to MozRepl. Attempting to reconnect..." if @options[:verbose]
55
+ @mozrepl = nil
56
+ # retry
57
+ mozrepl.cmd('content.location.reload();')
46
58
  end
47
59
 
48
60
  def mozrepl
49
- @mozrepl ||= Net::Telnet::new("Host" => @options[:host],
50
- "Port" => @options[:port])
61
+ return @mozrepl if @mozrepl
62
+ puts "Guard connecting to MozRepl at #{@options[:host]}:#{@options[:port]}"
63
+ @mozrepl = Net::Telnet::new("Host" => @options[:host],
64
+ "Port" => @options[:port])
65
+ rescue
66
+ warn "Not able to connect to MozRepl. Install/start MozRepl, or simply ignore this message."
67
+ @serious_issue = true
51
68
  end
52
69
 
53
70
  def close!
@@ -1,6 +1,10 @@
1
- guard 'mozrepl', :host => 'localhost', :port => 4242 do
1
+ guard 'mozrepl' do
2
2
  watch(%r{app/.+\.(erb|haml)})
3
3
  watch(%r{app/helpers/.+\.rb})
4
4
  watch(%r{public/.+\.(css|js|html)})
5
5
  watch(%r{config/locales/.+\.yml})
6
6
  end
7
+
8
+ ### or with options...
9
+ # guard 'mozrepl', :host => 'localhost', :port => 4242, :verbose => true do
10
+ # ...
@@ -1,5 +1,5 @@
1
1
  module Guard
2
2
  module Mozrepl
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guard-mozrepl
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Phil Hofmann
@@ -31,9 +31,9 @@ extra_rdoc_files: []
31
31
  files:
32
32
  - .gitignore
33
33
  - Gemfile
34
+ - README.md
34
35
  - Rakefile
35
36
  - guard-mozrepl.gemspec
36
- - lib/guard-mozrepl.rb
37
37
  - lib/guard/mozrepl.rb
38
38
  - lib/guard/mozrepl/templates/Guardfile
39
39
  - lib/guard/mozrepl/version.rb
@@ -1,5 +0,0 @@
1
- module Guard
2
- module Mozrepl
3
- # Your code goes here...
4
- end
5
- end