Skip to content
Permalink
Browse files

initial commit

  • Loading branch information...
johnbintz committed Nov 4, 2011
0 parents commit 2115047ab12dcb6b91e509d94a342cf50f54f142
Showing with 1,044 additions and 0 deletions.
  1. +4 −0 .gitignore
  2. +4 −0 Gemfile
  3. +21 −0 Guardfile
  4. +41 −0 README.md
  5. +11 −0 Rakefile
  6. +13 −0 config.ru
  7. +804 −0 js/livereload.js
  8. +6 −0 lib/rack-livereload.rb
  9. +46 −0 lib/rack/livereload.rb
  10. +34 −0 rack-livereload.gemspec
  11. +53 −0 spec/rack/livereload_spec.rb
  12. +7 −0 spec/spec_helper.rb
@@ -0,0 +1,4 @@
*.gem
.bundle
Gemfile.lock
pkg/*
@@ -0,0 +1,4 @@
source "http://rubygems.org"

# Specify your gem's dependencies in rack-livereload.gemspec
gemspec
@@ -0,0 +1,21 @@
# A sample Guardfile
# More info at https://github.com/guard/guard#readme

guard 'rspec', :version => 2 do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }

# Rails example
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
watch('spec/spec_helper.rb') { "spec" }
watch('config/routes.rb') { "spec/routing" }
watch('app/controllers/application_controller.rb') { "spec/controllers" }
# Capybara request specs
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
end

@@ -0,0 +1,41 @@
Hey, you've got [LiveReload](http://www.livereload.com/) in my [Rack](http://rack.rubyforge.org/)!
No need for browser extensions anymore! Just plug it in your middleware stack and go!

Use this with [guard-livereload](http://github.com/guard/guard-livereload) for maximum fun!

## Using in...

### Rails

In `config/initializers/development.rb`:

``` ruby
MyApp::Application.configure do
config.middleware.insert_before(Rack::Lock, Rack::LiveReload)
end
```

### config.ru/Sinatra

``` ruby
require 'rack-livereload'
use Rack::LiveReload
```

## How it works

The necessary `script` tag to bring in a vendored copy of [livereload.js](https://github.com/livereload/livereload-js) is
injected right before the closing `head` tag in any `text/html` pages that come through. The `script` tag is built in
such a way that the `HTTP_HOST` is used as the LiveReload host, so you can connect from external machines (say, to
`mycomputer:3000` instead of `localhost:3000`) and as long as the LiveReload port is accessible from the external machine,
you'll connect and be LiveReloading away!

## To-do

* Specify the `port`
* Override the `host`
* Change the reload delays

As usual, super-alpha!

@@ -0,0 +1,11 @@
require "bundler/gem_tasks"

desc 'Update livereload.js'
task :update_livereload_js do
require 'httparty'

File.open('js/livereload.js', 'wb') { |fh|
fh.print HTTParty.get('https://raw.github.com/livereload/livereload-js/master/dist/livereload.js').body
}
end

@@ -0,0 +1,13 @@
require 'sinatra'
$: << 'lib'

require 'rack/livereload'

use Rack::LiveReload

get '/' do
"<html><head><title>Hi</title></head><body>Hi</body></html>"
end

run Sinatra::Application

0 comments on commit 2115047

Please sign in to comment.
You can’t perform that action at this time.