trigger-happy 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'em-websocket'
4
+ gem 'directory_watcher'
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "shoulda", ">= 0"
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.5.2"
12
+ gem "rcov", ">= 0"
13
+ end
@@ -0,0 +1,28 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ addressable (2.2.4)
5
+ directory_watcher (1.3.2)
6
+ em-websocket (0.2.0)
7
+ addressable (>= 2.1.1)
8
+ eventmachine (>= 0.12.9)
9
+ eventmachine (0.12.10)
10
+ git (1.2.5)
11
+ jeweler (1.5.2)
12
+ bundler (~> 1.0.0)
13
+ git (>= 1.2.5)
14
+ rake
15
+ rake (0.8.7)
16
+ rcov (0.9.9)
17
+ shoulda (2.11.3)
18
+
19
+ PLATFORMS
20
+ ruby
21
+
22
+ DEPENDENCIES
23
+ bundler (~> 1.0.0)
24
+ directory_watcher
25
+ em-websocket
26
+ jeweler (~> 1.5.2)
27
+ rcov
28
+ shoulda
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Alex Gibbons
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.
@@ -0,0 +1,37 @@
1
+ = TriggerHappy
2
+
3
+ TriggerHappy watches a directory of files and tells browser pages, activated with a bookmarklet, to refresh when changes are detected.
4
+
5
+ == Installation
6
+
7
+ Install the library.
8
+
9
+ gem install trigger-happy
10
+
11
+ Install the bookmarklet in your browser.
12
+
13
+ trigger-happy-setup
14
+
15
+
16
+ == Usage
17
+
18
+ cd /me/my/project
19
+ trigger-happy
20
+
21
+ Now use your browser bookmarklet to activate page refreshing when watched files change.
22
+
23
+ == Contributing to trigger-happy
24
+
25
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
26
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
27
+ * Fork the project
28
+ * Start a feature/bugfix branch
29
+ * Commit and push until you are happy with your contribution
30
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
31
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
32
+
33
+ == Copyright
34
+
35
+ Copyright (c) 2011 Alex Gibbons. See LICENSE.txt for
36
+ further details.
37
+
@@ -0,0 +1,26 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "trigger-happy"
16
+ gem.homepage = "http://github.com/alexgb/trigger-happy"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{Browser page refreshing for your web projects}
19
+ gem.description = %Q{TriggerHappy watches a directory of files and tells browser pages, activated with a bookmarklet, to refresh when changes are detected}
20
+ gem.email = "alex.gibbons [a] gmail [dot] com"
21
+ gem.authors = ["Alex Gibbons"]
22
+ gem.bindir = "bin"
23
+ gem.add_dependency 'em-websocket'
24
+ gem.add_dependency 'directory_watcher'
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.0
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'em-websocket'
5
+ require 'directory_watcher'
6
+ require 'optparse'
7
+
8
+ options = {}
9
+
10
+ optparse = OptionParser.new do |opts|
11
+ opts.banner = %{Usage: trigger-happy [options] [dir1 dir2 ...]
12
+
13
+ Examples:
14
+ trigger-happy #=> watches all files
15
+ trigger-happy lib public #=> watches all files in lib and public
16
+ trigger-happy --glob="**/*.rb" lib #=> watches all ruby files in lib
17
+
18
+ }
19
+
20
+ options[:glob] = '**/*'
21
+ opts.on( '-g', '--glob PATTERN', 'Glob pattern to define which files to watch' ) do |pattern|
22
+ options[:glob] = pattern
23
+ end
24
+
25
+ opts.on( '-h', '--help', 'Display this screen' ) do
26
+ puts opts
27
+ exit
28
+ end
29
+ end
30
+ optparse.parse!
31
+
32
+ directories = []
33
+ directories.push('.') if ARGV.empty?
34
+ ARGV.each do |dir|
35
+ directories.push(dir)
36
+ end
37
+
38
+
39
+ EventMachine.kqueue = true if EventMachine.kqueue?
40
+ EventMachine::run do
41
+ @sockets = []
42
+
43
+ dw = DirectoryWatcher.new '.', :glob => directories.collect {|d| File.join(d, options[:glob])}, :pre_load => true, :scanner => :em
44
+ dw.add_observer do |*events|
45
+ events.each do |e|
46
+ @sockets.each {|s| s.send e.path if e.type == :modified}
47
+ end
48
+ end
49
+ dw.start
50
+
51
+ EventMachine::WebSocket.start(:host => "0.0.0.0", :port => 10101) do |socket|
52
+ socket.onopen do
53
+ @sockets.push(socket)
54
+ end
55
+ socket.onclose do
56
+ @sockets.delete(socket)
57
+ end
58
+ end
59
+
60
+ puts "Server running use the included bookmarklet to enable page refreshing"
61
+ end
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'webrick'
4
+ require 'uri'
5
+ require 'trigger-happy/install_page_server'
6
+
7
+
8
+ PORT = 10100
9
+ PATH = "http://localhost:#{PORT}"
10
+
11
+ puts "\nInstall the bookmarklet by going to #{PATH}\nThen quit WEBrick with ctrl-c"
12
+
13
+ $stderr = File.new('/dev/null', 'w')
14
+
15
+ module OnStart
16
+ def self.call
17
+ `open #{PATH}`
18
+ end
19
+ end
20
+
21
+ server = WEBrick::HTTPServer.new(:Port => PORT, :StartCallback => OnStart)
22
+ server.mount("/", TriggerHappy::InstallPageServer)
23
+
24
+
25
+ ['INT', 'TERM'].each {|signal|
26
+ trap(signal) {server.shutdown}
27
+ }
28
+
29
+ server.start
File without changes
@@ -0,0 +1,92 @@
1
+ require 'webrick'
2
+ require 'erb'
3
+
4
+
5
+ module TriggerHappy
6
+ class InstallPageServer < WEBrick::HTTPServlet::AbstractServlet
7
+
8
+ def do_GET(req, response)
9
+ response.body = TEMPLATE.result(binding)
10
+ response['Content-Type'] = "text/html"
11
+ end
12
+
13
+ BOOKMARKLET = <<-EOS
14
+ (function() {
15
+ var PageLoader = {};
16
+
17
+ PageLoader.init = function() {
18
+ while ( document.body.childNodes.length >= 1 ) {
19
+ document.body.removeChild( document.body.firstChild );
20
+ }
21
+ document.documentElement.style.height = '100%';
22
+ document.body.style = {margin:0, height:'100%', overflow:'hidden'};
23
+
24
+ this.iframe = document.createElement('iframe');
25
+ this.iframe.setAttribute('src', document.location.href);
26
+ this.iframe.setAttribute('style', 'width:100%;height:100%;');
27
+ this.iframe.setAttribute('allowtransparency', 'true');
28
+ this.iframe.setAttribute('frameborder', '0');
29
+ this.iframe.setAttribute('sandbox', 'allow-same-origin allow-forms allow-scripts');
30
+ this.iframe.setAttribute('scrolling', 'auto');
31
+ document.body.appendChild(this.iframe);
32
+
33
+ this.msg = document.createElement('div');
34
+ this.msg.setAttribute('style', 'background-color:red;padding:10px;color:white;position:absolute;top:0;right:0;' );
35
+ document.body.appendChild(this.msg);
36
+
37
+ this.openSocket();
38
+ };
39
+
40
+ PageLoader.openSocket = function(text, permanent) {
41
+ var self = this,
42
+ ws = new WebSocket("ws://localhost:10101");
43
+
44
+ ws.onmessage = function(evt) {
45
+ self.message("File Changed: " +evt.data);
46
+ self.refresh();
47
+ };
48
+ ws.onclose = function() {
49
+ self.message("Server Not Running<br/>Launch with `trigger-happy`", true);
50
+ window.setTimeout(function() {self.openSocket();},500);
51
+ };
52
+ ws.onopen = function() {
53
+ self.message("Connection to Server Opened");
54
+ };
55
+ ws.onerror = function() {
56
+ self.message("An Error Has Occured");
57
+ };
58
+ };
59
+
60
+ PageLoader.message = function(text, permanent) {
61
+ var msgEl = this.msg;
62
+
63
+ msgEl.style.display = 'inherit';
64
+ msgEl.innerHTML = text;
65
+ if (!permanent) {window.setTimeout(function() {msgEl.style.display = 'none';},1500);}
66
+ };
67
+
68
+ PageLoader.refresh = function() {
69
+ this.iframe.contentWindow.location.reload(true);
70
+ };
71
+
72
+ PageLoader.init();
73
+ })();
74
+ EOS
75
+
76
+ TEMPLATE = ERB.new <<-EOS
77
+ <!DOCTYPE HTML>
78
+ <html lang="en">
79
+ <head>
80
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
81
+ <title>Install Bookmarklet</title>
82
+ <meta name="author" content="Alex Gibbons">
83
+ </head>
84
+ <body>
85
+ <p>Drag this link: <a href="javascript:<%= URI.escape(BOOKMARKLET) %>">Make TriggerHappy</a> up to your Bookmarks Toolbar</p>
86
+
87
+ </body>
88
+ </html>
89
+ EOS
90
+
91
+ end
92
+ end
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'trigger-happy'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestTriggerHappy < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
@@ -0,0 +1,80 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{trigger-happy}
8
+ s.version = "0.2.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Alex Gibbons"]
12
+ s.date = %q{2011-02-02}
13
+ s.description = %q{TriggerHappy watches a directory of files and tells browser pages, activated with a bookmarklet, to refresh when changes are detected}
14
+ s.email = %q{alex.gibbons [a] gmail [dot] com}
15
+ s.executables = ["trigger-happy", "trigger-happy-setup"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE.txt",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "bin/trigger-happy",
29
+ "bin/trigger-happy-setup",
30
+ "lib/trigger-happy.rb",
31
+ "lib/trigger-happy/install_page_server.rb",
32
+ "test/helper.rb",
33
+ "test/test_trigger-happy.rb",
34
+ "trigger-happy.gemspec"
35
+ ]
36
+ s.homepage = %q{http://github.com/alexgb/trigger-happy}
37
+ s.licenses = ["MIT"]
38
+ s.require_paths = ["lib"]
39
+ s.rubygems_version = %q{1.3.7}
40
+ s.summary = %q{Browser page refreshing for your web projects}
41
+ s.test_files = [
42
+ "test/helper.rb",
43
+ "test/test_trigger-happy.rb"
44
+ ]
45
+
46
+ if s.respond_to? :specification_version then
47
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
48
+ s.specification_version = 3
49
+
50
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
51
+ s.add_runtime_dependency(%q<em-websocket>, [">= 0"])
52
+ s.add_runtime_dependency(%q<directory_watcher>, [">= 0"])
53
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
54
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
55
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
56
+ s.add_development_dependency(%q<rcov>, [">= 0"])
57
+ s.add_runtime_dependency(%q<em-websocket>, [">= 0"])
58
+ s.add_runtime_dependency(%q<directory_watcher>, [">= 0"])
59
+ else
60
+ s.add_dependency(%q<em-websocket>, [">= 0"])
61
+ s.add_dependency(%q<directory_watcher>, [">= 0"])
62
+ s.add_dependency(%q<shoulda>, [">= 0"])
63
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
64
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
65
+ s.add_dependency(%q<rcov>, [">= 0"])
66
+ s.add_dependency(%q<em-websocket>, [">= 0"])
67
+ s.add_dependency(%q<directory_watcher>, [">= 0"])
68
+ end
69
+ else
70
+ s.add_dependency(%q<em-websocket>, [">= 0"])
71
+ s.add_dependency(%q<directory_watcher>, [">= 0"])
72
+ s.add_dependency(%q<shoulda>, [">= 0"])
73
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
74
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
75
+ s.add_dependency(%q<rcov>, [">= 0"])
76
+ s.add_dependency(%q<em-websocket>, [">= 0"])
77
+ s.add_dependency(%q<directory_watcher>, [">= 0"])
78
+ end
79
+ end
80
+
metadata ADDED
@@ -0,0 +1,198 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: trigger-happy
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
+ platform: ruby
12
+ authors:
13
+ - Alex Gibbons
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-02-02 00:00:00 -08:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ type: :runtime
23
+ prerelease: false
24
+ name: em-websocket
25
+ version_requirements: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 3
31
+ segments:
32
+ - 0
33
+ version: "0"
34
+ requirement: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ type: :runtime
37
+ prerelease: false
38
+ name: directory_watcher
39
+ version_requirements: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ requirement: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ type: :development
51
+ prerelease: false
52
+ name: shoulda
53
+ version_requirements: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ requirement: *id003
63
+ - !ruby/object:Gem::Dependency
64
+ type: :development
65
+ prerelease: false
66
+ name: bundler
67
+ version_requirements: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ~>
71
+ - !ruby/object:Gem::Version
72
+ hash: 23
73
+ segments:
74
+ - 1
75
+ - 0
76
+ - 0
77
+ version: 1.0.0
78
+ requirement: *id004
79
+ - !ruby/object:Gem::Dependency
80
+ type: :development
81
+ prerelease: false
82
+ name: jeweler
83
+ version_requirements: &id005 !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ~>
87
+ - !ruby/object:Gem::Version
88
+ hash: 7
89
+ segments:
90
+ - 1
91
+ - 5
92
+ - 2
93
+ version: 1.5.2
94
+ requirement: *id005
95
+ - !ruby/object:Gem::Dependency
96
+ type: :development
97
+ prerelease: false
98
+ name: rcov
99
+ version_requirements: &id006 !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ hash: 3
105
+ segments:
106
+ - 0
107
+ version: "0"
108
+ requirement: *id006
109
+ - !ruby/object:Gem::Dependency
110
+ type: :runtime
111
+ prerelease: false
112
+ name: em-websocket
113
+ version_requirements: &id007 !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ hash: 3
119
+ segments:
120
+ - 0
121
+ version: "0"
122
+ requirement: *id007
123
+ - !ruby/object:Gem::Dependency
124
+ type: :runtime
125
+ prerelease: false
126
+ name: directory_watcher
127
+ version_requirements: &id008 !ruby/object:Gem::Requirement
128
+ none: false
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ hash: 3
133
+ segments:
134
+ - 0
135
+ version: "0"
136
+ requirement: *id008
137
+ description: TriggerHappy watches a directory of files and tells browser pages, activated with a bookmarklet, to refresh when changes are detected
138
+ email: alex.gibbons [a] gmail [dot] com
139
+ executables:
140
+ - trigger-happy
141
+ - trigger-happy-setup
142
+ extensions: []
143
+
144
+ extra_rdoc_files:
145
+ - LICENSE.txt
146
+ - README.rdoc
147
+ files:
148
+ - .document
149
+ - Gemfile
150
+ - Gemfile.lock
151
+ - LICENSE.txt
152
+ - README.rdoc
153
+ - Rakefile
154
+ - VERSION
155
+ - bin/trigger-happy
156
+ - bin/trigger-happy-setup
157
+ - lib/trigger-happy.rb
158
+ - lib/trigger-happy/install_page_server.rb
159
+ - test/helper.rb
160
+ - test/test_trigger-happy.rb
161
+ - trigger-happy.gemspec
162
+ has_rdoc: true
163
+ homepage: http://github.com/alexgb/trigger-happy
164
+ licenses:
165
+ - MIT
166
+ post_install_message:
167
+ rdoc_options: []
168
+
169
+ require_paths:
170
+ - lib
171
+ required_ruby_version: !ruby/object:Gem::Requirement
172
+ none: false
173
+ requirements:
174
+ - - ">="
175
+ - !ruby/object:Gem::Version
176
+ hash: 3
177
+ segments:
178
+ - 0
179
+ version: "0"
180
+ required_rubygems_version: !ruby/object:Gem::Requirement
181
+ none: false
182
+ requirements:
183
+ - - ">="
184
+ - !ruby/object:Gem::Version
185
+ hash: 3
186
+ segments:
187
+ - 0
188
+ version: "0"
189
+ requirements: []
190
+
191
+ rubyforge_project:
192
+ rubygems_version: 1.3.7
193
+ signing_key:
194
+ specification_version: 3
195
+ summary: Browser page refreshing for your web projects
196
+ test_files:
197
+ - test/helper.rb
198
+ - test/test_trigger-happy.rb