rack-livereload 0.3.15 → 0.3.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/.ruby-version +1 -0
- data/.travis.yml +11 -5
- data/Appraisals +4 -8
- data/Guardfile +13 -1
- data/README.md +44 -25
- data/features/step_definitions/then/i_should_not_have_livereload_code.rb +1 -1
- data/gemfiles/{rails30.gemfile → rails40.gemfile} +1 -1
- data/gemfiles/rails51.gemfile +5 -0
- data/lib/rack/livereload/body_processor.rb +6 -2
- data/lib/rack/livereload/processing_skip_analyzer.rb +7 -2
- data/lib/rack-livereload.rb +1 -1
- data/rack-livereload.gemspec +6 -4
- data/spec/rack/livereload/body_processor_spec.rb +1 -1
- data/spec/rack/livereload/processing_skip_analyzer_spec.rb +85 -25
- data/spec/rack/livereload_spec.rb +4 -2
- metadata +65 -92
- data/gemfiles/rails30.gemfile.lock +0 -157
- data/gemfiles/rails31.gemfile +0 -7
- data/gemfiles/rails31.gemfile.lock +0 -169
- data/gemfiles/rails32.gemfile.lock +0 -167
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9d7123144df9a852f48e7d4874cd4e2fa0d23657ecf61de34d8606d2b3c1c62d
|
4
|
+
data.tar.gz: a3cad0cf894c0f73b49d0e158d03d46c4677bee5fe7cccb5b6b037aabf48980d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1b13c7bebc5da0079b56885f66e81260673fa6a343581e383e9e5904bc3bd9af3c6058869d2885f9d457c21294c24fb00d6133faf7b3789fce1f2d21ffa2e4a5
|
7
|
+
data.tar.gz: 4da3c3b25cacc908d99e169a902b4002bfb3ba737edbb58f695b4d9eb42d054609eacd027bfa0c1e579d085068a5352de62c47dcbf714f72c33a4c1e27da4d3c
|
data/.gitignore
CHANGED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.5.1
|
data/.travis.yml
CHANGED
@@ -1,11 +1,17 @@
|
|
1
1
|
rvm:
|
2
|
-
- 1.8.7
|
3
|
-
- 1.9.2
|
4
2
|
- 1.9.3
|
3
|
+
- 2.0.0
|
4
|
+
- 2.5.1
|
5
5
|
branches:
|
6
6
|
only:
|
7
7
|
- master
|
8
8
|
gemfile:
|
9
|
-
- gemfiles/
|
10
|
-
- gemfiles/
|
11
|
-
- gemfiles/
|
9
|
+
- gemfiles/rails32.gemfile
|
10
|
+
- gemfiles/rails40.gemfile
|
11
|
+
- gemfiles/rails51.gemfile
|
12
|
+
matrix:
|
13
|
+
exclude:
|
14
|
+
- rvm: 1.9.3
|
15
|
+
gemfile: gemfiles/rails51.gemfile
|
16
|
+
- rvm: 2.0.0
|
17
|
+
gemfile: gemfiles/rails51.gemfile
|
data/Appraisals
CHANGED
@@ -1,11 +1,7 @@
|
|
1
|
-
appraise '
|
2
|
-
gem 'rails', '~> 3.
|
1
|
+
appraise 'rails32' do
|
2
|
+
gem 'rails', '~> 3.2.0'
|
3
3
|
end
|
4
4
|
|
5
|
-
appraise '
|
6
|
-
gem 'rails', '~>
|
5
|
+
appraise 'rails40' do
|
6
|
+
gem 'rails', '~> 4.0.0'
|
7
7
|
end
|
8
|
-
|
9
|
-
appraise 'rails32' do
|
10
|
-
gem 'rails', '~> 3.2.0'
|
11
|
-
end
|
data/Guardfile
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# A sample Guardfile
|
2
2
|
# More info at https://github.com/guard/guard#readme
|
3
3
|
|
4
|
-
guard 'rspec', :
|
4
|
+
guard 'rspec', :cmd => 'rspec -c' do
|
5
5
|
watch(%r{^spec/.+_spec\.rb$})
|
6
6
|
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
7
7
|
watch('spec/spec_helper.rb') { "spec" }
|
@@ -15,3 +15,15 @@ guard 'cucumber' do
|
|
15
15
|
watch(%r{^features/.+\.feature$})
|
16
16
|
watch(%r{^features/support/.+$}) { 'features' }
|
17
17
|
end
|
18
|
+
|
19
|
+
guard :bundler do
|
20
|
+
require 'guard/bundler'
|
21
|
+
require 'guard/bundler/verify'
|
22
|
+
helper = Guard::Bundler::Verify.new
|
23
|
+
|
24
|
+
files = ['Gemfile']
|
25
|
+
files += Dir['*.gemspec'] if files.any? { |f| helper.uses_gemspec?(f) }
|
26
|
+
|
27
|
+
# Assume files are symlinked from somewhere
|
28
|
+
files.each { |file| watch(helper.real_path(file)) }
|
29
|
+
end
|
data/README.md
CHANGED
@@ -1,48 +1,67 @@
|
|
1
|
-
|
2
|
-
[](https://codeclimate.com/github/johnbintz/rack-livereload)
|
1
|
+
# Rack::LiveReload
|
3
2
|
|
4
|
-
|
3
|
+
<a href="http://travis-ci.org/onesupercoder/rack-livereload"><img src="https://secure.travis-ci.org/onesupercoder/rack-livereload.png" /></a>
|
4
|
+
[](https://codeclimate.com/github/onesupercoder/rack-livereload)
|
5
|
+
|
6
|
+
Hey, you've got [LiveReload](http://livereload.com/) in my [Rack](http://rack.rubyforge.org/)!
|
5
7
|
No need for browser extensions anymore! Just plug it in your middleware stack and go!
|
6
8
|
Even supports browsers without WebSockets!
|
7
9
|
|
8
10
|
Use this with [guard-livereload](http://github.com/guard/guard-livereload) for maximum fun!
|
9
11
|
|
10
|
-
##
|
12
|
+
## Installation
|
11
13
|
|
12
|
-
|
14
|
+
### Rails
|
13
15
|
|
14
|
-
|
16
|
+
Add the gem to your Gemfile.
|
15
17
|
|
16
|
-
|
18
|
+
```ruby
|
19
|
+
gem "rack-livereload", group: :development
|
20
|
+
```
|
17
21
|
|
22
|
+
Then add the middleware to your Rails middleware stack by editing your `config/environments/development.rb`.
|
18
23
|
|
19
|
-
|
24
|
+
```ruby
|
25
|
+
# config/environments/development.rb
|
20
26
|
|
21
|
-
``` ruby
|
22
27
|
MyApp::Application.configure do
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
config.middleware.insert_before
|
28
|
-
|
29
|
-
|
30
|
-
:max_delay => 10000,
|
31
|
-
:port => 56789,
|
32
|
-
:host => 'myhost.cool.wow',
|
33
|
-
:ignore => [ %r{dont/modify\.html$} ]
|
34
|
-
)
|
28
|
+
# Add Rack::LiveReload to the bottom of the middleware stack with the default options:
|
29
|
+
config.middleware.insert_after ActionDispatch::Static, Rack::LiveReload
|
30
|
+
|
31
|
+
# or, if you're using better_errors:
|
32
|
+
config.middleware.insert_before Rack::Lock, Rack::LiveReload
|
33
|
+
|
34
|
+
# ...
|
35
35
|
end
|
36
36
|
```
|
37
37
|
|
38
|
-
|
38
|
+
#### Tweaking the options
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
# Specifying Rack::LiveReload options.
|
42
|
+
config.middleware.use(Rack::LiveReload,
|
43
|
+
min_delay : 500, # default 1000
|
44
|
+
max_delay : 10_000, # default 60_000
|
45
|
+
live_reload_port : 56789, # default 35729
|
46
|
+
host : 'myhost.cool.wow',
|
47
|
+
ignore : [ %r{dont/modify\.html$} ]
|
48
|
+
)
|
49
|
+
```
|
50
|
+
|
51
|
+
In addition, Rack::LiveReload's position within middleware stack can be
|
52
|
+
specified by inserting it relative to an exsiting middleware via
|
53
|
+
`insert_before` or `insert_after`. See the [Rails on Rack: Adding a
|
54
|
+
Middleware](http://guides.rubyonrails.org/rails_on_rack.html#adding-a-middleware)
|
55
|
+
section for more detail.
|
56
|
+
|
57
|
+
### Sinatra / config.ru
|
39
58
|
|
40
59
|
``` ruby
|
41
60
|
require 'rack-livereload'
|
42
61
|
|
43
62
|
use Rack::LiveReload
|
44
63
|
# ...or...
|
45
|
-
use Rack::LiveReload, :
|
64
|
+
use Rack::LiveReload, min_delay: 500, ...
|
46
65
|
```
|
47
66
|
|
48
67
|
## How it works
|
@@ -70,13 +89,13 @@ your browser doesn't need it. The SWF WebSocket implementor won't be loaded unle
|
|
70
89
|
WebSockets support or if you force it in the middleware stack:
|
71
90
|
|
72
91
|
``` ruby
|
73
|
-
use Rack::LiveReload, :
|
92
|
+
use Rack::LiveReload, force_swf: true
|
74
93
|
```
|
75
94
|
|
76
95
|
If you don't want any of the web-sockets-js code included at all, use the `no_swf` option:
|
77
96
|
|
78
97
|
``` ruby
|
79
|
-
use Rack::LiveReload, :
|
98
|
+
use Rack::LiveReload, no_swf: true
|
80
99
|
```
|
81
100
|
|
82
101
|
Once more browsers support WebSockets than don't, this option will be reversed and you'll have
|
@@ -9,8 +9,12 @@ module Rack
|
|
9
9
|
|
10
10
|
attr_reader :content_length, :new_body, :livereload_added
|
11
11
|
|
12
|
+
def protocol
|
13
|
+
@options[:protocol] || "http"
|
14
|
+
end
|
15
|
+
|
12
16
|
def livereload_local_uri
|
13
|
-
"
|
17
|
+
"#{protocol}://localhost:#{@options[:live_reload_port]}/livereload.js"
|
14
18
|
end
|
15
19
|
|
16
20
|
def initialize(body, options)
|
@@ -45,7 +49,7 @@ module Rack
|
|
45
49
|
begin
|
46
50
|
http.send_request('GET', uri.path)
|
47
51
|
@use_vendored = false
|
48
|
-
rescue ::Timeout::Error, Errno::ECONNREFUSED, EOFError
|
52
|
+
rescue ::Timeout::Error, Errno::ECONNREFUSED, EOFError, IOError
|
49
53
|
@use_vendored = true
|
50
54
|
rescue => e
|
51
55
|
$stderr.puts e.inspect
|
@@ -16,7 +16,7 @@ module Rack
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def skip_processing?
|
19
|
-
!html? || chunked? || inline? || ignored? || bad_browser?
|
19
|
+
!html? || chunked? || inline? || ignored? || bad_browser? || !get?
|
20
20
|
end
|
21
21
|
|
22
22
|
def chunked?
|
@@ -28,7 +28,8 @@ module Rack
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def ignored?
|
31
|
-
@
|
31
|
+
path = @env['QUERY_STRING'].empty? ? @env['PATH_INFO'] : "#{@env['PATH_INFO']}?#{@env['QUERY_STRING']}"
|
32
|
+
@options[:ignore] and @options[:ignore].any? { |filter| path[filter] }
|
32
33
|
end
|
33
34
|
|
34
35
|
def bad_browser?
|
@@ -38,6 +39,10 @@ module Rack
|
|
38
39
|
def html?
|
39
40
|
@headers['Content-Type'] =~ %r{text/html}
|
40
41
|
end
|
42
|
+
|
43
|
+
def get?
|
44
|
+
@env['REQUEST_METHOD'] == 'GET'
|
45
|
+
end
|
41
46
|
end
|
42
47
|
end
|
43
48
|
end
|
data/lib/rack-livereload.rb
CHANGED
data/rack-livereload.gemspec
CHANGED
@@ -7,7 +7,8 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.version = Rack::LiveReload::VERSION
|
8
8
|
s.authors = ["John Bintz"]
|
9
9
|
s.email = ["john@coswellproductions.com"]
|
10
|
-
s.homepage = ""
|
10
|
+
s.homepage = "https://github.com/onesupercoder/rack-livereload"
|
11
|
+
s.license = "MIT"
|
11
12
|
s.summary = %q{Insert LiveReload into your app easily as Rack middleware}
|
12
13
|
s.description = %q{Insert LiveReload into your app easily as Rack middleware}
|
13
14
|
|
@@ -20,7 +21,7 @@ Gem::Specification.new do |s|
|
|
20
21
|
|
21
22
|
# specify any dependencies here; for example:
|
22
23
|
s.add_development_dependency "rspec"
|
23
|
-
s.add_development_dependency "cucumber"
|
24
|
+
s.add_development_dependency "cucumber", "< 3"
|
24
25
|
s.add_development_dependency "httparty"
|
25
26
|
s.add_development_dependency "sinatra"
|
26
27
|
s.add_development_dependency "shotgun"
|
@@ -31,9 +32,10 @@ Gem::Specification.new do |s|
|
|
31
32
|
s.add_development_dependency "guard-rspec"
|
32
33
|
s.add_development_dependency "guard-cucumber"
|
33
34
|
s.add_development_dependency "guard-livereload"
|
35
|
+
s.add_development_dependency "guard-bundler"
|
34
36
|
s.add_development_dependency "webmock"
|
35
|
-
s.add_development_dependency "nokogiri"
|
36
|
-
s.add_development_dependency 'appraisal', '~> 0
|
37
|
+
s.add_development_dependency "nokogiri", ("< 1.6" if RUBY_VERSION < "1.9") # Nokogiri >= 1.6 requires Ruby >= 1.9
|
38
|
+
s.add_development_dependency 'appraisal', '~> 2.2.0'
|
37
39
|
s.add_runtime_dependency "rack"
|
38
40
|
end
|
39
41
|
|
@@ -14,54 +14,50 @@ describe Rack::LiveReload::ProcessingSkipAnalyzer do
|
|
14
14
|
|
15
15
|
describe '#skip_processing?' do
|
16
16
|
it "should skip processing" do
|
17
|
-
subject.skip_processing?.should
|
17
|
+
subject.skip_processing?.should be_truthy
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
describe '#
|
22
|
-
let(:user_agent) { described_class::BAD_USER_AGENTS.first.source }
|
23
|
-
|
24
|
-
it { should be_bad_browser }
|
25
|
-
end
|
26
|
-
|
27
|
-
context 'ignored' do
|
21
|
+
describe '#ignored?' do
|
28
22
|
let(:options) { { :ignore => [ %r{file} ] } }
|
29
23
|
|
30
|
-
context '
|
31
|
-
let(:env) { { 'PATH_INFO' => '/this/file' } }
|
24
|
+
context 'path contains ignore pattern' do
|
25
|
+
let(:env) { { 'PATH_INFO' => '/this/file', 'QUERY_STRING' => '' } }
|
32
26
|
|
33
27
|
it { should be_ignored }
|
34
28
|
end
|
35
29
|
|
36
|
-
context 'root' do
|
37
|
-
let(:env) { { 'PATH_INFO' => '/' } }
|
30
|
+
context 'root path' do
|
31
|
+
let(:env) { { 'PATH_INFO' => '/', 'QUERY_STRING' => '' } }
|
38
32
|
|
39
33
|
it { should_not be_ignored }
|
40
34
|
end
|
41
35
|
end
|
42
36
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
end
|
37
|
+
describe '#chunked?' do
|
38
|
+
context 'regular response' do
|
39
|
+
it { should_not be_chunked }
|
40
|
+
end
|
48
41
|
|
49
|
-
|
50
|
-
|
42
|
+
context 'chunked response' do
|
43
|
+
let(:headers) { { 'Transfer-Encoding' => 'chunked' } }
|
51
44
|
|
52
|
-
|
45
|
+
it { should be_chunked }
|
46
|
+
end
|
53
47
|
end
|
54
48
|
|
49
|
+
describe '#inline?' do
|
50
|
+
context 'inline disposition' do
|
51
|
+
let(:headers) { { 'Content-Disposition' => 'inline; filename=my_inlined_file' } }
|
55
52
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
it { should be_inline }
|
53
|
+
it { should be_inline }
|
54
|
+
end
|
60
55
|
end
|
61
56
|
|
62
57
|
describe '#ignored?' do
|
63
58
|
let(:path_info) { 'path info' }
|
64
|
-
let(:
|
59
|
+
let(:query_string) { 'query_string' }
|
60
|
+
let(:env) { { 'PATH_INFO' => path_info, 'QUERY_STRING' => query_string } }
|
65
61
|
|
66
62
|
context 'no ignore set' do
|
67
63
|
it { should_not be_ignored }
|
@@ -72,6 +68,70 @@ describe Rack::LiveReload::ProcessingSkipAnalyzer do
|
|
72
68
|
|
73
69
|
it { should be_ignored }
|
74
70
|
end
|
71
|
+
|
72
|
+
context 'ignore set including query_string' do
|
73
|
+
let(:options) { { :ignore => [ %r{#{path_info}\?#{query_string}} ] } }
|
74
|
+
|
75
|
+
it { should be_ignored }
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe '#bad_browser?' do
|
80
|
+
context 'Firefox' do
|
81
|
+
it { should_not be_bad_browser }
|
82
|
+
end
|
83
|
+
|
84
|
+
context 'BAD browser' do
|
85
|
+
let(:user_agent) { described_class::BAD_USER_AGENTS.first.source }
|
86
|
+
|
87
|
+
it { should be_bad_browser }
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe '#html?' do
|
92
|
+
context 'HTML content' do
|
93
|
+
let(:headers) { { 'Content-Type' => 'text/html' } }
|
94
|
+
|
95
|
+
it { should be_html }
|
96
|
+
end
|
97
|
+
|
98
|
+
context 'PDF content' do
|
99
|
+
let(:headers) { { 'Content-Type' => 'application/pdf' } }
|
100
|
+
|
101
|
+
it { should_not be_html }
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe '#get?' do
|
106
|
+
context 'GET request' do
|
107
|
+
let(:env) { { 'REQUEST_METHOD' => 'GET' } }
|
108
|
+
|
109
|
+
it { should be_get }
|
110
|
+
end
|
111
|
+
|
112
|
+
context 'PUT request' do
|
113
|
+
let(:env) { { 'REQUEST_METHOD' => 'PUT' } }
|
114
|
+
|
115
|
+
it { should_not be_get }
|
116
|
+
end
|
117
|
+
|
118
|
+
context 'POST request' do
|
119
|
+
let(:env) { { 'REQUEST_METHOD' => 'POST' } }
|
120
|
+
|
121
|
+
it { should_not be_get }
|
122
|
+
end
|
123
|
+
|
124
|
+
context 'DELETE request' do
|
125
|
+
let(:env) { { 'REQUEST_METHOD' => 'DELETE' } }
|
126
|
+
|
127
|
+
it { should_not be_get }
|
128
|
+
end
|
129
|
+
|
130
|
+
context 'PATCH request' do
|
131
|
+
let(:env) { { 'REQUEST_METHOD' => 'PATCH' } }
|
132
|
+
|
133
|
+
it { should_not be_get }
|
134
|
+
end
|
75
135
|
end
|
76
136
|
end
|
77
137
|
|
@@ -7,7 +7,9 @@ describe Rack::LiveReload do
|
|
7
7
|
|
8
8
|
subject { middleware }
|
9
9
|
|
10
|
-
|
10
|
+
it 'should be an app' do
|
11
|
+
middleware.app.should be == app
|
12
|
+
end
|
11
13
|
|
12
14
|
let(:env) { {} }
|
13
15
|
let(:options) { {} }
|
@@ -20,7 +22,7 @@ describe Rack::LiveReload do
|
|
20
22
|
end
|
21
23
|
|
22
24
|
it 'should return the js file' do
|
23
|
-
middleware._call(env).should
|
25
|
+
middleware._call(env).should be_truthy
|
24
26
|
end
|
25
27
|
end
|
26
28
|
end
|