├── VERSION ├── .document ├── spec ├── spec.watchr ├── spec_helper.rb └── autorefresh_spec.rb ├── .gitignore ├── bin └── autorefresh ├── Gemfile ├── Gemfile.lock ├── lib └── autorefresh.rb ├── LICENSE.txt ├── Rakefile └── README.rdoc /VERSION: -------------------------------------------------------------------------------- 1 | 1.0.0 -------------------------------------------------------------------------------- /.document: -------------------------------------------------------------------------------- 1 | lib/**/*.rb 2 | bin/* 3 | - 4 | features/**/*.feature 5 | LICENSE.txt 6 | -------------------------------------------------------------------------------- /spec/spec.watchr: -------------------------------------------------------------------------------- 1 | watch( 'lib/(.*)\.rb' ) {|md| system("bacon spec/autorefresh_spec.rb") } 2 | watch( 'spec/(.*)\.rb' ) {|md| system("bacon spec/autorefresh_spec.rb") } 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## MAC OS 2 | .DS_Store 3 | 4 | ## TEXTMATE 5 | *.tmproj 6 | tmtags 7 | 8 | ## EMACS 9 | *~ 10 | \#* 11 | .\#* 12 | 13 | ## VIM 14 | *.swp 15 | 16 | ## PROJECT::GENERAL 17 | coverage 18 | rdoc 19 | pkg 20 | 21 | ## PROJECT::SPECIFIC 22 | .bundle/ 23 | -------------------------------------------------------------------------------- /bin/autorefresh: -------------------------------------------------------------------------------- 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 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 18 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 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 17 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 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 23 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 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) 34 | -------------------------------------------------------------------------------- /lib/autorefresh.rb: -------------------------------------------------------------------------------- 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 | 12 | 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 29 | -------------------------------------------------------------------------------- /spec/autorefresh_spec.rb: -------------------------------------------------------------------------------- 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 34 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 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. 21 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 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 54 | -------------------------------------------------------------------------------- /README.rdoc: -------------------------------------------------------------------------------- 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 | 27 | 28 | <%= AutoRefresh.channel('myproject') %> 29 | 30 | 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 | 49 | 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 | 79 | --------------------------------------------------------------------------------