guard-livereload 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Thibaud Guillaume-Gentil
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,58 @@
1
+ = Guard::LiveReload
2
+
3
+ LiveReload guard allows to automatically reload your browser when 'view' files are modified.
4
+
5
+ == Install
6
+
7
+ Please be sure to have {guard}[http://github.com/guard/guard] installed before continue.
8
+
9
+ Install the gem:
10
+
11
+ gem install guard-livereload
12
+
13
+ Add it to your Gemfile (inside test group):
14
+
15
+ gem 'guard-livereload'
16
+
17
+ Add guard definition to your Guardfile with:
18
+
19
+ guard init livereload
20
+
21
+ Install {livereload Safari/Chrome extension}[http://github.com/mockko/livereload]
22
+
23
+ == Usage
24
+
25
+ Please read {guard usage doc}[http://github.com/guard/guard#readme]
26
+ and {livereload extension usage doc}[http://github.com/mockko/livereload]
27
+
28
+ == Guardfile
29
+
30
+ You can adapt your 'view' files like you want.
31
+ Please read {guard doc}[http://github.com/guard/guard#readme] for more info about Guardfile DSL.
32
+
33
+ guard 'livereload' do
34
+ watch('^app/.+\.(erb|haml)$')
35
+ watch('^app/helpers/.+\.rb$')
36
+ watch('^/public/.+\.(css|js|html)$')
37
+ watch('^config/locales/.+\.ym$')
38
+ end
39
+
40
+ == Options
41
+
42
+ LiveReload guard have three options (host, port, api_version):
43
+
44
+ guard 'livereload', :port => '35728' do
45
+ ...
46
+ end
47
+
48
+ == Development
49
+
50
+ - Source hosted at {GitHub}[http://github.com/guard/guard-livereload]
51
+ - Report issues/Questions/Feature requests on {GitHub Issues}[http://github.com/guard/guard-livereload/issues]
52
+
53
+ Pull requests are very welcome! Make sure your patches are well tested. Please create a topic branch for every separate change
54
+ you make.
55
+
56
+ == Authors
57
+
58
+ {Thibaud Guillaume-Gentil}[http://github.com/thibaudgg]
@@ -0,0 +1,27 @@
1
+ require 'guard'
2
+ require 'guard/guard'
3
+
4
+ module Guard
5
+ class LiveReload < Guard
6
+
7
+ autoload :Reactor, 'guard/livereload/reactor'
8
+ attr_accessor :reactor
9
+
10
+ def start
11
+ options[:api_version] ||= '1.4'
12
+ options[:host] ||= '0.0.0.0'
13
+ options[:port] ||= '35729'
14
+
15
+ @reactor = Reactor.new(options)
16
+ end
17
+
18
+ def stop
19
+ reactor.stop
20
+ end
21
+
22
+ def run_on_change(paths)
23
+ reactor.reload_browser(paths)
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,61 @@
1
+ require 'em-websocket'
2
+ require 'json'
3
+
4
+ module Guard
5
+ class LiveReload
6
+ class Reactor
7
+
8
+ attr_reader :thread, :web_sockets
9
+
10
+ def initialize(options)
11
+ @web_sockets = []
12
+ @thread = start_threaded_reactor(options)
13
+ end
14
+
15
+ def stop
16
+ thread.kill
17
+ end
18
+
19
+ def reload_browser(paths = [])
20
+ UI.info "Reloading browser: #{paths.join(' ')}"
21
+ paths.each do |path|
22
+ data = ['refresh', { :path => path, :apply_js_live => false, :apply_css_live => true }].to_json
23
+ UI.debug data
24
+ @web_sockets.each { |ws| ws.send(data) }
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ def start_threaded_reactor(options)
31
+ Thread.new do
32
+ EventMachine.run do
33
+ UI.info "LiveReload #{options[:api_version]} is waiting for a browser to connect."
34
+ EventMachine::WebSocket.start(:host => options[:host], :port => options[:port]) do |ws|
35
+ ws.onopen do
36
+ begin
37
+ UI.info "Browser connected."
38
+ ws.send "!!ver:#{options[:api_version]}"
39
+ @web_sockets << ws
40
+ rescue
41
+ UI.errror $!
42
+ UI.errror $!.backtrace
43
+ end
44
+ end
45
+
46
+ ws.onmessage do |msg|
47
+ UI.info "Browser URL: #{msg}"
48
+ end
49
+
50
+ ws.onclose do
51
+ @web_sockets.delete ws
52
+ UI.info "Browser disconnected."
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,6 @@
1
+ guard 'livereload' do
2
+ watch('^app/.+\.(erb|haml)$')
3
+ watch('^app/helpers/.+\.rb$')
4
+ watch('^/public/.+\.(css|js|html)$')
5
+ watch('^config/locales/.+\.ym$')
6
+ end
@@ -0,0 +1,5 @@
1
+ module Guard
2
+ class LiveReload
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,169 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: guard-livereload
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Thibaud Guillaume-Gentil
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-10-10 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ version_requirements: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ hash: 25
28
+ segments:
29
+ - 0
30
+ - 1
31
+ - 1
32
+ version: 0.1.1
33
+ name: guard
34
+ prerelease: false
35
+ requirement: *id001
36
+ type: :runtime
37
+ - !ruby/object:Gem::Dependency
38
+ version_requirements: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ hash: 29
44
+ segments:
45
+ - 0
46
+ - 1
47
+ - 3
48
+ version: 0.1.3
49
+ name: em-websocket
50
+ prerelease: false
51
+ requirement: *id002
52
+ type: :runtime
53
+ - !ruby/object:Gem::Dependency
54
+ version_requirements: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ hash: 11
60
+ segments:
61
+ - 1
62
+ - 4
63
+ - 6
64
+ version: 1.4.6
65
+ name: json
66
+ prerelease: false
67
+ requirement: *id003
68
+ type: :runtime
69
+ - !ruby/object:Gem::Dependency
70
+ version_requirements: &id004 !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ hash: 19
76
+ segments:
77
+ - 1
78
+ - 0
79
+ - 2
80
+ version: 1.0.2
81
+ name: bundler
82
+ prerelease: false
83
+ requirement: *id004
84
+ type: :development
85
+ - !ruby/object:Gem::Dependency
86
+ version_requirements: &id005 !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ~>
90
+ - !ruby/object:Gem::Version
91
+ hash: 25
92
+ segments:
93
+ - 0
94
+ - 1
95
+ - 1
96
+ version: 0.1.1
97
+ name: guard-rspec
98
+ prerelease: false
99
+ requirement: *id005
100
+ type: :development
101
+ - !ruby/object:Gem::Dependency
102
+ version_requirements: &id006 !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ~>
106
+ - !ruby/object:Gem::Version
107
+ hash: 7712058
108
+ segments:
109
+ - 2
110
+ - 0
111
+ - 0
112
+ - rc
113
+ version: 2.0.0.rc
114
+ name: rspec
115
+ prerelease: false
116
+ requirement: *id006
117
+ type: :development
118
+ description: Guard::LiveReload automatically reload your browser when 'view' files are modified.
119
+ email:
120
+ - thibaud@thibaud.me
121
+ executables: []
122
+
123
+ extensions: []
124
+
125
+ extra_rdoc_files: []
126
+
127
+ files:
128
+ - lib/guard/livereload/reactor.rb
129
+ - lib/guard/livereload/templates/Guardfile
130
+ - lib/guard/livereload/version.rb
131
+ - lib/guard/livereload.rb
132
+ - LICENSE
133
+ - README.rdoc
134
+ has_rdoc: true
135
+ homepage: http://rubygems.org/gems/guard-livereload
136
+ licenses: []
137
+
138
+ post_install_message:
139
+ rdoc_options: []
140
+
141
+ require_paths:
142
+ - lib
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ none: false
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ hash: 3
149
+ segments:
150
+ - 0
151
+ version: "0"
152
+ required_rubygems_version: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ">="
156
+ - !ruby/object:Gem::Version
157
+ hash: 3
158
+ segments:
159
+ - 0
160
+ version: "0"
161
+ requirements: []
162
+
163
+ rubyforge_project: guard-livereload
164
+ rubygems_version: 1.3.7
165
+ signing_key:
166
+ specification_version: 3
167
+ summary: Guard gem for livereload
168
+ test_files: []
169
+