autorefresh 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +33 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +78 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/bin/autorefresh +17 -0
- data/lib/autorefresh.rb +28 -0
- data/spec/autorefresh_spec.rb +33 -0
- data/spec/spec.watchr +2 -0
- data/spec/spec_helper.rb +22 -0
- metadata +162 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
gem "pusher", ">= 0.7.0"
|
7
|
+
gem "watchr", ">= 0.7"
|
8
|
+
|
9
|
+
# Add dependencies to develop your gem here.
|
10
|
+
# Include everything needed to run rake, tests, features, etc.
|
11
|
+
group :development do
|
12
|
+
gem "bacon", ">= 0"
|
13
|
+
gem "bundler", "~> 1.0.0"
|
14
|
+
gem "jeweler", "~> 1.5.2"
|
15
|
+
gem "rcov", ">= 0"
|
16
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
bacon (1.1.0)
|
5
|
+
crack (0.1.8)
|
6
|
+
git (1.2.5)
|
7
|
+
jeweler (1.5.2)
|
8
|
+
bundler (~> 1.0.0)
|
9
|
+
git (>= 1.2.5)
|
10
|
+
rake
|
11
|
+
json (1.4.6)
|
12
|
+
pusher (0.7.0)
|
13
|
+
crack (~> 0.1.0)
|
14
|
+
json (~> 1.4.0)
|
15
|
+
ruby-hmac (~> 0.4.0)
|
16
|
+
signature (~> 0.1.2)
|
17
|
+
rake (0.8.7)
|
18
|
+
rcov (0.9.9)
|
19
|
+
ruby-hmac (0.4.0)
|
20
|
+
signature (0.1.2)
|
21
|
+
ruby-hmac
|
22
|
+
watchr (0.7)
|
23
|
+
|
24
|
+
PLATFORMS
|
25
|
+
ruby
|
26
|
+
|
27
|
+
DEPENDENCIES
|
28
|
+
bacon
|
29
|
+
bundler (~> 1.0.0)
|
30
|
+
jeweler (~> 1.5.2)
|
31
|
+
pusher (>= 0.7.0)
|
32
|
+
rcov
|
33
|
+
watchr (>= 0.7)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Logan Koester
|
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,78 @@
|
|
1
|
+
= AutoRefresh
|
2
|
+
|
3
|
+
AutoRefresh is inspired by XRefresh[http://xrefresh.binaryage.com/], a tool to
|
4
|
+
automatically refresh your browser when a file has changed, allowing web
|
5
|
+
designers working with multiple monitors to preview changes without leaving
|
6
|
+
your editor.
|
7
|
+
|
8
|
+
XRefresh requires that you install a Firefox extension and run a local server
|
9
|
+
to watch for changes in your files, and only works on Mac/Windows.
|
10
|
+
|
11
|
+
AutoRefresh approaches the problem in a different way, using watchr[https://github.com/mynyml/watchr].
|
12
|
+
|
13
|
+
== Installation
|
14
|
+
gem install autorefresh
|
15
|
+
|
16
|
+
== Usage
|
17
|
+
|
18
|
+
Add the AutoRefresh gem to your project
|
19
|
+
require 'autorefresh'
|
20
|
+
|
21
|
+
Insert a JavaScript snippet in your page template using the AutoRefresh helper.
|
22
|
+
Remember only to include this snippet in your development environment, so users
|
23
|
+
don't end up getting their page refreshed. You should give your channel a unique
|
24
|
+
name that won't conflict with other developers using AutoRefresh.
|
25
|
+
|
26
|
+
<html>
|
27
|
+
<head>
|
28
|
+
<%= AutoRefresh.channel('myproject') %>
|
29
|
+
</head>
|
30
|
+
</html>
|
31
|
+
|
32
|
+
Now create a refresh.watchr file (or use an existing file, if you are already
|
33
|
+
using Watchr to run your tests), and add some rules for the files you want
|
34
|
+
to watch using regular expressions.
|
35
|
+
|
36
|
+
refresh.watchr
|
37
|
+
watch( 'public/stylesheets/.*\.css' ) { |m| system('autorefresh myproject') }
|
38
|
+
|
39
|
+
Now run Watchr to begin observing changes in your files.
|
40
|
+
$ watchr refresh.watchr
|
41
|
+
|
42
|
+
And enjoy your new workflow!
|
43
|
+
|
44
|
+
=== Usage without ERB
|
45
|
+
|
46
|
+
Simply use this snippet instead of the automatic helper.
|
47
|
+
|
48
|
+
<script src="http://js.pusherapp.com/1.6/pusher.js" type="text/javascript"></script>
|
49
|
+
<script type="text/javascript">
|
50
|
+
var pusher = new Pusher('a2024b659f492cab86cc');
|
51
|
+
pusher.subscribe('yourproject');
|
52
|
+
pusher.bind('refresh', function(data) {
|
53
|
+
location.reload(true);
|
54
|
+
});
|
55
|
+
</script>
|
56
|
+
|
57
|
+
=== Usage without Watchr
|
58
|
+
|
59
|
+
The *autorefresh* system command sends a refresh signal to your channel.
|
60
|
+
$ autorefresh myproject
|
61
|
+
|
62
|
+
You could bind this to a key in your editor, or whatever other method you prefer.
|
63
|
+
|
64
|
+
== Contributing to AutoRefresh
|
65
|
+
|
66
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
67
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
68
|
+
* Fork the project
|
69
|
+
* Start a feature/bugfix branch
|
70
|
+
* Commit and push until you are happy with your contribution
|
71
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
72
|
+
* 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.
|
73
|
+
|
74
|
+
== Copyright
|
75
|
+
|
76
|
+
Copyright (c) 2011 Logan Koester. See LICENSE.txt for
|
77
|
+
further details.
|
78
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
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 = "autorefresh"
|
16
|
+
gem.homepage = "http://github.com/logankoester/autorefresh"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = %Q{Automatically refresh your browser when a file has changed (using WebSockets)}
|
19
|
+
gem.description = %Q{Automatically refresh your browser when a file has changed}
|
20
|
+
gem.email = "logan@logankoester.com"
|
21
|
+
gem.authors = ["Logan Koester"]
|
22
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
25
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
|
+
end
|
27
|
+
Jeweler::RubygemsDotOrgTasks.new
|
28
|
+
|
29
|
+
require 'rake/testtask'
|
30
|
+
Rake::TestTask.new(:spec) do |spec|
|
31
|
+
spec.libs << 'lib' << 'spec'
|
32
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
33
|
+
spec.verbose = true
|
34
|
+
end
|
35
|
+
|
36
|
+
require 'rcov/rcovtask'
|
37
|
+
Rcov::RcovTask.new do |spec|
|
38
|
+
spec.libs << 'spec'
|
39
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
40
|
+
spec.verbose = true
|
41
|
+
end
|
42
|
+
|
43
|
+
task :default => :spec
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "autorefresh #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
data/bin/autorefresh
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require File.join( File.expand_path(File.dirname(__FILE__)), '..', 'lib', 'autorefresh')
|
4
|
+
|
5
|
+
USAGE = %q{
|
6
|
+
autorefresh - Send listening browsers a signal to refresh the page.
|
7
|
+
|
8
|
+
Usage: autorefresh <channel>
|
9
|
+
|
10
|
+
For more information, see https://github.com/logankoester/autorefresh
|
11
|
+
}.lstrip
|
12
|
+
|
13
|
+
if ARGV[0]
|
14
|
+
AutoRefresh.refresh(ARGV[0])
|
15
|
+
else
|
16
|
+
puts USAGE
|
17
|
+
end
|
data/lib/autorefresh.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'pusher'
|
2
|
+
|
3
|
+
# Automatically refresh your browser using WebSockets
|
4
|
+
class AutoRefresh
|
5
|
+
@@pusher_key = 'a2024b659f492cab86cc'
|
6
|
+
@@pusher_app_id = '3735'
|
7
|
+
@@pusher_secret = '3ce64d76b4288e4ba449'
|
8
|
+
|
9
|
+
def self.channel(chan)
|
10
|
+
%q{
|
11
|
+
<script src="http://js.pusherapp.com/1.6/pusher.js" type="text/javascript"></script>
|
12
|
+
<script type="text/javascript">
|
13
|
+
var pusher = new Pusher('PUSHER_KEY');
|
14
|
+
pusher.subscribe('CHANNEL');
|
15
|
+
pusher.bind('refresh', function(data) {
|
16
|
+
location.reload(true);
|
17
|
+
});
|
18
|
+
</script>
|
19
|
+
}.gsub(/CHANNEL/, chan).gsub(/PUSHER_KEY/, @@pusher_key)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.refresh(chan)
|
23
|
+
Pusher.app_id = @@pusher_app_id
|
24
|
+
Pusher.key = @@pusher_key
|
25
|
+
Pusher.secret = @@pusher_secret
|
26
|
+
Pusher[chan].trigger('refresh', {})
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.join( File.expand_path(File.dirname(__FILE__)), 'spec_helper')
|
2
|
+
|
3
|
+
describe "The AutoRefresh helper" do
|
4
|
+
before do
|
5
|
+
@channel = 'testchannel'
|
6
|
+
@helper = AutoRefresh.channel(@channel)
|
7
|
+
end
|
8
|
+
it "should accept a channel name and return a string" do
|
9
|
+
@helper.class.should.equal String
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should include the pusher js client" do
|
13
|
+
@helper.should.match /src=".*pusher\.js/
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should set the Pusher key" do
|
17
|
+
@helper.should.match /new Pusher\('#{AutoRefresh.pusher_key}'\)/
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should subscribe to the specified channel" do
|
21
|
+
@helper.should.match /pusher\.subscribe\('#{@channel}'\)/
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "Sending a refresh event" do
|
26
|
+
before do
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should return true" do
|
30
|
+
@result = AutoRefresh.refresh(@channel)
|
31
|
+
@result.should.equal true
|
32
|
+
end
|
33
|
+
end
|
data/spec/spec.watchr
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,22 @@
|
|
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 'bacon'
|
11
|
+
|
12
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
require 'autorefresh'
|
15
|
+
|
16
|
+
Bacon.summary_on_exit
|
17
|
+
|
18
|
+
class AutoRefresh
|
19
|
+
def self.pusher_key
|
20
|
+
@@pusher_key
|
21
|
+
end
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: autorefresh
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
version: 1.0.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Logan Koester
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-01-18 00:00:00 -05:00
|
18
|
+
default_executable: autorefresh
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: pusher
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
- 7
|
30
|
+
- 0
|
31
|
+
version: 0.7.0
|
32
|
+
type: :runtime
|
33
|
+
prerelease: false
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: watchr
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
segments:
|
43
|
+
- 0
|
44
|
+
- 7
|
45
|
+
version: "0.7"
|
46
|
+
type: :runtime
|
47
|
+
prerelease: false
|
48
|
+
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: bacon
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
segments:
|
57
|
+
- 0
|
58
|
+
version: "0"
|
59
|
+
type: :development
|
60
|
+
prerelease: false
|
61
|
+
version_requirements: *id003
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: bundler
|
64
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
segments:
|
70
|
+
- 1
|
71
|
+
- 0
|
72
|
+
- 0
|
73
|
+
version: 1.0.0
|
74
|
+
type: :development
|
75
|
+
prerelease: false
|
76
|
+
version_requirements: *id004
|
77
|
+
- !ruby/object:Gem::Dependency
|
78
|
+
name: jeweler
|
79
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ~>
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
segments:
|
85
|
+
- 1
|
86
|
+
- 5
|
87
|
+
- 2
|
88
|
+
version: 1.5.2
|
89
|
+
type: :development
|
90
|
+
prerelease: false
|
91
|
+
version_requirements: *id005
|
92
|
+
- !ruby/object:Gem::Dependency
|
93
|
+
name: rcov
|
94
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
segments:
|
100
|
+
- 0
|
101
|
+
version: "0"
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: *id006
|
105
|
+
description: Automatically refresh your browser when a file has changed
|
106
|
+
email: logan@logankoester.com
|
107
|
+
executables:
|
108
|
+
- autorefresh
|
109
|
+
extensions: []
|
110
|
+
|
111
|
+
extra_rdoc_files:
|
112
|
+
- LICENSE.txt
|
113
|
+
- README.rdoc
|
114
|
+
files:
|
115
|
+
- .document
|
116
|
+
- Gemfile
|
117
|
+
- Gemfile.lock
|
118
|
+
- LICENSE.txt
|
119
|
+
- README.rdoc
|
120
|
+
- Rakefile
|
121
|
+
- VERSION
|
122
|
+
- bin/autorefresh
|
123
|
+
- lib/autorefresh.rb
|
124
|
+
- spec/autorefresh_spec.rb
|
125
|
+
- spec/spec.watchr
|
126
|
+
- spec/spec_helper.rb
|
127
|
+
has_rdoc: true
|
128
|
+
homepage: http://github.com/logankoester/autorefresh
|
129
|
+
licenses:
|
130
|
+
- MIT
|
131
|
+
post_install_message:
|
132
|
+
rdoc_options: []
|
133
|
+
|
134
|
+
require_paths:
|
135
|
+
- lib
|
136
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
hash: 2802726110151825551
|
142
|
+
segments:
|
143
|
+
- 0
|
144
|
+
version: "0"
|
145
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
|
+
none: false
|
147
|
+
requirements:
|
148
|
+
- - ">="
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
segments:
|
151
|
+
- 0
|
152
|
+
version: "0"
|
153
|
+
requirements: []
|
154
|
+
|
155
|
+
rubyforge_project:
|
156
|
+
rubygems_version: 1.3.7
|
157
|
+
signing_key:
|
158
|
+
specification_version: 3
|
159
|
+
summary: Automatically refresh your browser when a file has changed (using WebSockets)
|
160
|
+
test_files:
|
161
|
+
- spec/autorefresh_spec.rb
|
162
|
+
- spec/spec_helper.rb
|