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 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
@@ -1,5 +1,7 @@
1
1
  *.gem
2
2
  .bundle
3
3
  Gemfile.lock
4
+ gemfiles/*.lock
4
5
  pkg/*
5
6
  *.orig
7
+ tmp/
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/rails30.gemfile
10
- - gemfiles/rails31.gemfile
11
- - gemfiles/rails32.gemfile
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 'rails30' do
2
- gem 'rails', '~> 3.0.0'
1
+ appraise 'rails32' do
2
+ gem 'rails', '~> 3.2.0'
3
3
  end
4
4
 
5
- appraise 'rails31' do
6
- gem 'rails', '~> 3.1.0'
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', :cli => '-c' do
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
- <a href="http://travis-ci.org/johnbintz/rack-livereload"><img src="https://secure.travis-ci.org/johnbintz/rack-livereload.png" /></a>
2
- [![Code Climate](https://codeclimate.com/github/johnbintz/rack-livereload.png)](https://codeclimate.com/github/johnbintz/rack-livereload)
1
+ # Rack::LiveReload
3
2
 
4
- Hey, you've got [LiveReload](http://www.livereload.com/) in my [Rack](http://rack.rubyforge.org/)!
3
+ <a href="http://travis-ci.org/onesupercoder/rack-livereload"><img src="https://secure.travis-ci.org/onesupercoder/rack-livereload.png" /></a>
4
+ [![Code Climate](https://codeclimate.com/github/onesupercoder/rack-livereload.png)](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
- ## Install
12
+ ## Installation
11
13
 
12
- `gem install rack-livereload`
14
+ ### Rails
13
15
 
14
- ## Using in...
16
+ Add the gem to your Gemfile.
15
17
 
16
- ### Rails
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
- In `config/environments/development.rb`:
24
+ ```ruby
25
+ # config/environments/development.rb
20
26
 
21
- ``` ruby
22
27
  MyApp::Application.configure do
23
- config.middleware.insert_after(ActionDispatch::Static, Rack::LiveReload)
24
-
25
- # ...or, change some options...
26
-
27
- config.middleware.insert_before(
28
- Rack::Lock, Rack::LiveReload,
29
- :min_delay => 500,
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
- ### config.ru/Sinatra
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, :min_delay => 500, ...
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, :force_swf => true
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, :no_swf => true
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
@@ -1,4 +1,4 @@
1
1
  Then /^I should not have any Rack::LiveReload code$/ do
2
- @response.body.should_not include("rack/livereload.js")
2
+ expect(@response.body).not_to include("rack/livereload.js")
3
3
  end
4
4
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  source "http://rubygems.org"
4
4
 
5
- gem "rails", "~> 3.0.0"
5
+ gem "rails", "~> 4.0.0"
6
6
 
7
7
  gemspec :path=>"../"
@@ -0,0 +1,5 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "rails", "~> 5.1.6"
4
+
5
+ gemspec :path=>"../"
@@ -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
- "http://localhost:#{@options[:live_reload_port]}/livereload.js"
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
- @options[:ignore] and @options[:ignore].any? { |filter| @env['PATH_INFO'][filter] }
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
@@ -1,6 +1,6 @@
1
1
  require "rack/livereload"
2
2
 
3
3
  class Rack::LiveReload
4
- VERSION = '0.3.15'
4
+ VERSION = '0.3.17'
5
5
  end
6
6
 
@@ -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.4'
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
 
@@ -15,7 +15,7 @@ describe Rack::LiveReload::BodyProcessor do
15
15
  end
16
16
 
17
17
  it 'responds false when no head tag' do
18
- regex.match("<header></header>").should be_false
18
+ regex.match("<header></header>").should be_falsey
19
19
  end
20
20
  end
21
21
 
@@ -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 be_true
17
+ subject.skip_processing?.should be_truthy
18
18
  end
19
19
  end
20
20
 
21
- describe '#bad_browser?' do
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 'not root' do
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
- context 'not text/html' do
44
- let(:headers) { { 'Content-Type' => 'application/pdf' } }
45
-
46
- it { should_not be_html }
47
- end
37
+ describe '#chunked?' do
38
+ context 'regular response' do
39
+ it { should_not be_chunked }
40
+ end
48
41
 
49
- context 'chunked response' do
50
- let(:headers) { { 'Transfer-Encoding' => 'chunked' } }
42
+ context 'chunked response' do
43
+ let(:headers) { { 'Transfer-Encoding' => 'chunked' } }
51
44
 
52
- it { should be_chunked }
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
- context 'inline disposition' do
57
- let(:headers) { { 'Content-Disposition' => 'inline; filename=my_inlined_file' } }
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(:env) { { 'PATH_INFO' => path_info } }
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
- its(:app) { should == app }
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 be_true
25
+ middleware._call(env).should be_truthy
24
26
  end
25
27
  end
26
28
  end