Compare commits
1 Commits
master
...
nathanhoel
Author | SHA1 | Date | |
---|---|---|---|
|
3c58d4b0c0 |
11
.travis.yml
11
.travis.yml
@ -1,10 +1,19 @@
|
|||||||
rvm:
|
rvm:
|
||||||
|
- 1.8.7
|
||||||
|
- 1.9.2
|
||||||
- 1.9.3
|
- 1.9.3
|
||||||
- 2.0.0
|
- 2.0.0
|
||||||
branches:
|
branches:
|
||||||
only:
|
only:
|
||||||
- master
|
- master
|
||||||
gemfile:
|
gemfile:
|
||||||
|
- gemfiles/rails30.gemfile
|
||||||
|
- gemfiles/rails31.gemfile
|
||||||
- gemfiles/rails32.gemfile
|
- gemfiles/rails32.gemfile
|
||||||
- gemfiles/rails40.gemfile
|
- gemfiles/rails40.gemfile
|
||||||
|
matrix:
|
||||||
|
exclude:
|
||||||
|
- rvm: 1.8.7
|
||||||
|
gemfile: gemfiles/rails40.gemfile
|
||||||
|
- rvm: 1.9.2
|
||||||
|
gemfile: gemfiles/rails40.gemfile
|
||||||
|
@ -1,3 +1,11 @@
|
|||||||
|
appraise 'rails30' do
|
||||||
|
gem 'rails', '~> 3.0.0'
|
||||||
|
end
|
||||||
|
|
||||||
|
appraise 'rails31' do
|
||||||
|
gem 'rails', '~> 3.1.0'
|
||||||
|
end
|
||||||
|
|
||||||
appraise 'rails32' do
|
appraise 'rails32' do
|
||||||
gem 'rails', '~> 3.2.0'
|
gem 'rails', '~> 3.2.0'
|
||||||
end
|
end
|
||||||
|
37
README.md
37
README.md
@ -1,11 +1,9 @@
|
|||||||
# Rack::LiveReload
|
# Rack::LiveReload
|
||||||
|
|
||||||
_This fork is deprecated: Go check out https://github.com/onesupercoder/rack-livereload instead._
|
|
||||||
|
|
||||||
<a href="http://travis-ci.org/johnbintz/rack-livereload"><img src="https://secure.travis-ci.org/johnbintz/rack-livereload.png" /></a>
|
<a href="http://travis-ci.org/johnbintz/rack-livereload"><img src="https://secure.travis-ci.org/johnbintz/rack-livereload.png" /></a>
|
||||||
[![Code Climate](https://codeclimate.com/github/johnbintz/rack-livereload.png)](https://codeclimate.com/github/johnbintz/rack-livereload)
|
[![Code Climate](https://codeclimate.com/github/johnbintz/rack-livereload.png)](https://codeclimate.com/github/johnbintz/rack-livereload)
|
||||||
|
|
||||||
Hey, you've got [LiveReload](http://livereload.com/) in my [Rack](http://rack.rubyforge.org/)!
|
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!
|
No need for browser extensions anymore! Just plug it in your middleware stack and go!
|
||||||
Even supports browsers without WebSockets!
|
Even supports browsers without WebSockets!
|
||||||
|
|
||||||
@ -18,7 +16,7 @@ Use this with [guard-livereload](http://github.com/guard/guard-livereload) for m
|
|||||||
Add the gem to your Gemfile.
|
Add the gem to your Gemfile.
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
gem "rack-livereload", group: :development
|
gem "rack-livereload", :group => :development
|
||||||
```
|
```
|
||||||
|
|
||||||
Then add the middleware to your Rails middleware stack by editing your `config/environments/development.rb`.
|
Then add the middleware to your Rails middleware stack by editing your `config/environments/development.rb`.
|
||||||
@ -27,12 +25,9 @@ Then add the middleware to your Rails middleware stack by editing your `config/e
|
|||||||
# config/environments/development.rb
|
# config/environments/development.rb
|
||||||
|
|
||||||
MyApp::Application.configure do
|
MyApp::Application.configure do
|
||||||
# Add Rack::LiveReload to the bottom of the middleware stack with the default options:
|
# Add Rack::LiveReload to the bottom of the middleware stack with the default options.
|
||||||
config.middleware.insert_after ActionDispatch::Static, Rack::LiveReload
|
config.middleware.use Rack::LiveReload
|
||||||
|
|
||||||
# or, if you're using better_errors:
|
|
||||||
config.middleware.insert_before Rack::Lock, Rack::LiveReload
|
|
||||||
|
|
||||||
# ...
|
# ...
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
@ -42,19 +37,15 @@ end
|
|||||||
```ruby
|
```ruby
|
||||||
# Specifying Rack::LiveReload options.
|
# Specifying Rack::LiveReload options.
|
||||||
config.middleware.use(Rack::LiveReload,
|
config.middleware.use(Rack::LiveReload,
|
||||||
min_delay : 500, # default 1000
|
:min_delay => 500, # default 1000
|
||||||
max_delay : 10_000, # default 60_000
|
:max_delay => 10_000, # default 60_000
|
||||||
live_reload_port : 56789, # default 35729
|
:live_reload_port => 56789, # default 35729
|
||||||
host : 'myhost.cool.wow',
|
:host => 'myhost.cool.wow',
|
||||||
ignore : [ %r{dont/modify\.html$} ]
|
:ignore => [ %r{dont/modify\.html$} ]
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
In addition, Rack::LiveReload's position within middleware stack can be
|
In addition, Rack::LiveReload's position within middleware stack can be specified by inserting it relative to an exsiting middleware via `insert_before` or `insert_after`. See the [Rails on Rack: Adding a Middleware](http://guides.rubyonrails.org/rails_on_rack.html#adding-a-middleware) section for more detail.
|
||||||
specified by inserting it relative to an exsiting middleware via
|
|
||||||
`insert_before` or `insert_after`. See the [Rails on Rack: Adding a
|
|
||||||
Middleware](http://guides.rubyonrails.org/rails_on_rack.html#adding-a-middleware)
|
|
||||||
section for more detail.
|
|
||||||
|
|
||||||
### Sinatra / config.ru
|
### Sinatra / config.ru
|
||||||
|
|
||||||
@ -63,7 +54,7 @@ require 'rack-livereload'
|
|||||||
|
|
||||||
use Rack::LiveReload
|
use Rack::LiveReload
|
||||||
# ...or...
|
# ...or...
|
||||||
use Rack::LiveReload, min_delay: 500, ...
|
use Rack::LiveReload, :min_delay => 500, ...
|
||||||
```
|
```
|
||||||
|
|
||||||
## How it works
|
## How it works
|
||||||
@ -91,13 +82,13 @@ your browser doesn't need it. The SWF WebSocket implementor won't be loaded unle
|
|||||||
WebSockets support or if you force it in the middleware stack:
|
WebSockets support or if you force it in the middleware stack:
|
||||||
|
|
||||||
``` ruby
|
``` ruby
|
||||||
use Rack::LiveReload, force_swf: true
|
use Rack::LiveReload, :force_swf => true
|
||||||
```
|
```
|
||||||
|
|
||||||
If you don't want any of the web-sockets-js code included at all, use the `no_swf` option:
|
If you don't want any of the web-sockets-js code included at all, use the `no_swf` option:
|
||||||
|
|
||||||
``` ruby
|
``` ruby
|
||||||
use Rack::LiveReload, no_swf: true
|
use Rack::LiveReload, :no_swf => true
|
||||||
```
|
```
|
||||||
|
|
||||||
Once more browsers support WebSockets than don't, this option will be reversed and you'll have
|
Once more browsers support WebSockets than don't, this option will be reversed and you'll have
|
||||||
|
7
gemfiles/rails30.gemfile
Normal file
7
gemfiles/rails30.gemfile
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# This file was generated by Appraisal
|
||||||
|
|
||||||
|
source "http://rubygems.org"
|
||||||
|
|
||||||
|
gem "rails", "~> 3.0.0"
|
||||||
|
|
||||||
|
gemspec :path=>"../"
|
7
gemfiles/rails31.gemfile
Normal file
7
gemfiles/rails31.gemfile
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# This file was generated by Appraisal
|
||||||
|
|
||||||
|
source "http://rubygems.org"
|
||||||
|
|
||||||
|
gem "rails", "~> 3.1.0"
|
||||||
|
|
||||||
|
gemspec :path=>"../"
|
@ -1,6 +1,6 @@
|
|||||||
require "rack/livereload"
|
require "rack/livereload"
|
||||||
|
|
||||||
class Rack::LiveReload
|
class Rack::LiveReload
|
||||||
VERSION = '0.3.16'
|
VERSION = '0.3.15'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -9,12 +9,8 @@ module Rack
|
|||||||
|
|
||||||
attr_reader :content_length, :new_body, :livereload_added
|
attr_reader :content_length, :new_body, :livereload_added
|
||||||
|
|
||||||
def protocol
|
|
||||||
@options[:protocol] || "http"
|
|
||||||
end
|
|
||||||
|
|
||||||
def livereload_local_uri
|
def livereload_local_uri
|
||||||
"#{protocol}://localhost:#{@options[:live_reload_port]}/livereload.js"
|
"http://localhost:#{@options[:live_reload_port]}/livereload.js"
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(body, options)
|
def initialize(body, options)
|
||||||
@ -75,7 +71,7 @@ module Rack
|
|||||||
|
|
||||||
@new_body.each do |line|
|
@new_body.each do |line|
|
||||||
if !@livereload_added && line['<head']
|
if !@livereload_added && line['<head']
|
||||||
line.gsub!(HEAD_TAG_REGEX) { |match| %{#{match}#{template.result(binding)}} }
|
line.sub!(HEAD_TAG_REGEX) { |match| %{#{match}#{template.result(binding)}} }
|
||||||
|
|
||||||
@livereload_added = true
|
@livereload_added = true
|
||||||
end
|
end
|
||||||
@ -113,4 +109,3 @@ module Rack
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -28,8 +28,7 @@ module Rack
|
|||||||
end
|
end
|
||||||
|
|
||||||
def ignored?
|
def ignored?
|
||||||
path = @env['QUERY_STRING'].empty? ? @env['PATH_INFO'] : "#{@env['PATH_INFO']}?#{@env['QUERY_STRING']}"
|
@options[:ignore] and @options[:ignore].any? { |filter| @env['PATH_INFO'][filter] }
|
||||||
@options[:ignore] and @options[:ignore].any? { |filter| path[filter] }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def bad_browser?
|
def bad_browser?
|
||||||
|
@ -21,6 +21,7 @@ Gem::Specification.new do |s|
|
|||||||
|
|
||||||
# specify any dependencies here; for example:
|
# specify any dependencies here; for example:
|
||||||
s.add_development_dependency "rspec"
|
s.add_development_dependency "rspec"
|
||||||
|
s.add_development_dependency "rspec-its"
|
||||||
s.add_development_dependency "cucumber"
|
s.add_development_dependency "cucumber"
|
||||||
s.add_development_dependency "httparty"
|
s.add_development_dependency "httparty"
|
||||||
s.add_development_dependency "sinatra"
|
s.add_development_dependency "sinatra"
|
||||||
|
@ -143,6 +143,14 @@ describe Rack::LiveReload::BodyProcessor do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'in document with more than one reference to a head tag' do
|
||||||
|
let(:page_html) { "<head><head><!-- <head></head> -->" }
|
||||||
|
|
||||||
|
it 'should not add the livereload js' do
|
||||||
|
processed_body.should include == "<!-- <head></head> -->"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'not vendored' do
|
context 'not vendored' do
|
||||||
before do
|
before do
|
||||||
processor.stubs(:use_vendored?).returns(false)
|
processor.stubs(:use_vendored?).returns(false)
|
||||||
|
@ -22,13 +22,13 @@ describe Rack::LiveReload::ProcessingSkipAnalyzer do
|
|||||||
let(:options) { { :ignore => [ %r{file} ] } }
|
let(:options) { { :ignore => [ %r{file} ] } }
|
||||||
|
|
||||||
context 'path contains ignore pattern' do
|
context 'path contains ignore pattern' do
|
||||||
let(:env) { { 'PATH_INFO' => '/this/file', 'QUERY_STRING' => '' } }
|
let(:env) { { 'PATH_INFO' => '/this/file' } }
|
||||||
|
|
||||||
it { should be_ignored }
|
it { should be_ignored }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'root path' do
|
context 'root path' do
|
||||||
let(:env) { { 'PATH_INFO' => '/', 'QUERY_STRING' => '' } }
|
let(:env) { { 'PATH_INFO' => '/' } }
|
||||||
|
|
||||||
it { should_not be_ignored }
|
it { should_not be_ignored }
|
||||||
end
|
end
|
||||||
@ -56,8 +56,7 @@ describe Rack::LiveReload::ProcessingSkipAnalyzer do
|
|||||||
|
|
||||||
describe '#ignored?' do
|
describe '#ignored?' do
|
||||||
let(:path_info) { 'path info' }
|
let(:path_info) { 'path info' }
|
||||||
let(:query_string) { 'query_string' }
|
let(:env) { { 'PATH_INFO' => path_info } }
|
||||||
let(:env) { { 'PATH_INFO' => path_info, 'QUERY_STRING' => query_string } }
|
|
||||||
|
|
||||||
context 'no ignore set' do
|
context 'no ignore set' do
|
||||||
it { should_not be_ignored }
|
it { should_not be_ignored }
|
||||||
@ -68,12 +67,6 @@ describe Rack::LiveReload::ProcessingSkipAnalyzer do
|
|||||||
|
|
||||||
it { should be_ignored }
|
it { should be_ignored }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'ignore set including query_string' do
|
|
||||||
let(:options) { { :ignore => [ %r{#{path_info}\?#{query_string}} ] } }
|
|
||||||
|
|
||||||
it { should be_ignored }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#bad_browser?' do
|
describe '#bad_browser?' do
|
||||||
|
@ -7,9 +7,7 @@ describe Rack::LiveReload do
|
|||||||
|
|
||||||
subject { middleware }
|
subject { middleware }
|
||||||
|
|
||||||
it 'should be an app' do
|
its(:app) { should == app }
|
||||||
middleware.app.should be == app
|
|
||||||
end
|
|
||||||
|
|
||||||
let(:env) { {} }
|
let(:env) { {} }
|
||||||
let(:options) { {} }
|
let(:options) { {} }
|
||||||
|
@ -1,9 +1,14 @@
|
|||||||
require 'mocha/api'
|
require 'mocha/api'
|
||||||
require 'webmock/rspec'
|
require 'webmock/rspec'
|
||||||
|
require 'rspec/its'
|
||||||
|
|
||||||
require 'rack-livereload'
|
require 'rack-livereload'
|
||||||
|
|
||||||
RSpec.configure do |c|
|
RSpec.configure do |c|
|
||||||
|
c.expect_with :rspec do |config|
|
||||||
|
config.syntax = :should
|
||||||
|
end
|
||||||
|
|
||||||
c.mock_with :mocha
|
c.mock_with :mocha
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user