rack-livereload 0.3.11 → 0.3.12

Sign up to get free protection for your applications and to get access to all the features.
data/js/livereload.js CHANGED
@@ -317,7 +317,7 @@ var Options;
317
317
  __options.Options = Options = (function() {
318
318
  function Options() {
319
319
  this.host = null;
320
- this.port = 35729;
320
+ this.port = RACK_LIVERELOAD_PORT;
321
321
  this.snipver = null;
322
322
  this.ext = null;
323
323
  this.extver = null;
@@ -1,6 +1,6 @@
1
1
  require "rack/livereload"
2
2
 
3
3
  class Rack::LiveReload
4
- VERSION = '0.3.11'
4
+ VERSION = '0.3.12'
5
5
  end
6
6
 
@@ -3,15 +3,19 @@ require 'erb'
3
3
  module Rack
4
4
  class LiveReload
5
5
  LIVERELOAD_JS_PATH = '/__rack/livereload.js'
6
- LIVERELOAD_LOCAL_URI = 'http://localhost:35729/livereload.js'
7
6
  HEAD_TAG_REGEX = /<head>|<head[^(er)][^<]*>/
8
7
 
9
8
  BAD_USER_AGENTS = [ %r{MSIE} ]
10
9
 
10
+ def livereload_local_uri
11
+ "http://localhost:#{@port}/livereload.js"
12
+ end
13
+
11
14
  attr_reader :app
12
15
 
13
16
  def initialize(app, options = {})
14
17
  @app, @options = app, options
18
+ @port = @options[:live_reload_port] || 35729
15
19
  end
16
20
 
17
21
  def use_vendored?
@@ -23,7 +27,8 @@ module Rack
23
27
  require 'net/http'
24
28
  require 'uri'
25
29
 
26
- uri = URI.parse(LIVERELOAD_LOCAL_URI)
30
+
31
+ uri = URI.parse(livereload_local_uri)
27
32
 
28
33
  http = Net::HTTP.new(uri.host, uri.port)
29
34
  http.read_timeout = 1
@@ -54,7 +59,11 @@ module Rack
54
59
  else
55
60
  status, headers, body = result = @app.call(env)
56
61
 
57
- return result if headers['Content-Type'] and headers['Content-Type']['text/event-stream']
62
+ if (headers['Content-Type'] and headers['Content-Type']['text/event-stream']) or
63
+ headers['Transfer-Encoding'] == 'chunked' or
64
+ headers['Content-Disposition'] =~ %r{^inline}
65
+ return result
66
+ end
58
67
 
59
68
  body.close if body.respond_to?(:close)
60
69
 
@@ -71,12 +80,12 @@ module Rack
71
80
  if use_vendored?
72
81
  src = LIVERELOAD_JS_PATH.dup + "?host=#{host_to_use}"
73
82
  else
74
- src = LIVERELOAD_LOCAL_URI.dup.gsub('localhost', host_to_use) + '?'
83
+ src = livereload_local_uri.dup.gsub('localhost', host_to_use) + '?'
75
84
  end
76
85
 
77
- src << "&mindelay=#{@options[:min_delay]}" if @options[:min_delay]
78
- src << "&maxdelay=#{@options[:max_delay]}" if @options[:max_delay]
79
- src << "&port=#{@options[:port]}" if @options[:port]
86
+ src << "&amp;mindelay=#{@options[:min_delay]}" if @options[:min_delay]
87
+ src << "&amp;maxdelay=#{@options[:max_delay]}" if @options[:max_delay]
88
+ src << "&amp;port=#{@options[:port]}" if @options[:port]
80
89
 
81
90
  template = ERB.new(::File.read(::File.expand_path('../../../skel/livereload.html.erb', __FILE__)))
82
91
 
@@ -4,6 +4,7 @@
4
4
  <% if force_swf? %>
5
5
  WEB_SOCKET_FORCE_FLASH = true;
6
6
  <% end %>
7
+ RACK_LIVERELOAD_PORT = <%= @port %>;
7
8
  </script>
8
9
  <script type="text/javascript" src="/__rack/swfobject.js"></script>
9
10
  <script type="text/javascript" src="/__rack/web_socket.js"></script>
@@ -12,7 +12,7 @@ describe Rack::LiveReload do
12
12
  let(:env) { {} }
13
13
  let(:options) { {} }
14
14
 
15
- describe described_class::LIVERELOAD_LOCAL_URI do
15
+ describe "livereload local uri" do
16
16
  context 'does not exist' do
17
17
  before do
18
18
  stub_request(:any, 'localhost:35729/livereload.js').to_timeout
@@ -29,6 +29,16 @@ describe Rack::LiveReload do
29
29
  it { should_not use_vendored }
30
30
  end
31
31
 
32
+ context 'with custom port' do
33
+ let(:options) { {:live_reload_port => '12348'}}
34
+ context 'exists' do
35
+ before do
36
+ stub_request(:any, 'localhost:12348/livereload.js')
37
+ end
38
+ it { should_not use_vendored }
39
+ end
40
+ end
41
+
32
42
  context 'specify vendored' do
33
43
  let(:options) { { :source => :vendored } }
34
44
 
@@ -69,6 +79,36 @@ describe Rack::LiveReload do
69
79
  end
70
80
  end
71
81
 
82
+ context 'chunked response' do
83
+ let(:body) { [ '<head></head>' ] }
84
+ let(:ret) { [ 200, { 'Transfer-Encoding' => 'chunked' }, body ] }
85
+
86
+ before do
87
+ app.stubs(:call).with(env).returns(ret)
88
+ body.expects(:close).never
89
+ body.stubs(:respond_to?).with(:close).returns(true)
90
+ end
91
+
92
+ it 'should pass through' do
93
+ middleware.call(env).should == ret
94
+ end
95
+ end
96
+
97
+ context 'inline disposition' do
98
+ let(:body) { [ '<head></head>' ] }
99
+ let(:ret) { [ 200, { 'Content-Disposition' => 'inline; filename=my_inlined_file' }, body ] }
100
+
101
+ before do
102
+ app.stubs(:call).with(env).returns(ret)
103
+ body.expects(:close).never
104
+ body.stubs(:respond_to?).with(:close).returns(true)
105
+ end
106
+
107
+ it 'should pass through' do
108
+ middleware.call(env).should == ret
109
+ end
110
+ end
111
+
72
112
  context 'unknown Content-Type' do
73
113
  let(:ret) { [ 200, {}, [ 'hey ho' ] ] }
74
114
 
@@ -120,8 +160,18 @@ describe Rack::LiveReload do
120
160
  body_dom.at_css("script:eq(4)")[:src].should include(described_class::LIVERELOAD_JS_PATH)
121
161
  body_dom.at_css("script:last-child")[:insert].should == "before"
122
162
  end
163
+
123
164
  end
124
165
 
166
+ describe "LIVERELOAD_PORT value" do
167
+ let(:options) { {:live_reload_port => 12345 }}
168
+ it "sets the variable at the top of the file" do
169
+ body.should include 'RACK_LIVERELOAD_PORT = 12345'
170
+ end
171
+ end
172
+
173
+
174
+
125
175
  context 'in header tags' do
126
176
  let(:page_html) { "<header class='hero'><h1>Just a normal header tag</h1></header>" }
127
177
 
@@ -140,7 +190,7 @@ describe Rack::LiveReload do
140
190
 
141
191
  it 'should add the LR livereload js script tag' do
142
192
  body.should include("script")
143
- body.should include(described_class::LIVERELOAD_LOCAL_URI.gsub('localhost', 'host'))
193
+ body.should include(middleware.livereload_local_uri.gsub('localhost', 'host'))
144
194
  end
145
195
  end
146
196
 
metadata CHANGED
@@ -1,272 +1,272 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-livereload
3
3
  version: !ruby/object:Gem::Version
4
+ version: 0.3.12
4
5
  prerelease:
5
- version: 0.3.11
6
6
  platform: ruby
7
7
  authors:
8
8
  - John Bintz
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-24 00:00:00.000000000 Z
12
+ date: 2013-03-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- version_requirements: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ! '>='
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- none: false
21
- prerelease: false
22
15
  name: rspec
23
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
24
18
  requirements:
25
19
  - - ! '>='
26
20
  - !ruby/object:Gem::Version
27
21
  version: '0'
28
- none: false
29
22
  type: :development
30
- - !ruby/object:Gem::Dependency
23
+ prerelease: false
31
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
32
26
  requirements:
33
27
  - - ! '>='
34
28
  - !ruby/object:Gem::Version
35
29
  version: '0'
36
- none: false
37
- prerelease: false
30
+ - !ruby/object:Gem::Dependency
38
31
  name: cucumber
39
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
40
34
  requirements:
41
35
  - - ! '>='
42
36
  - !ruby/object:Gem::Version
43
37
  version: '0'
44
- none: false
45
38
  type: :development
46
- - !ruby/object:Gem::Dependency
39
+ prerelease: false
47
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
48
42
  requirements:
49
43
  - - ! '>='
50
44
  - !ruby/object:Gem::Version
51
45
  version: '0'
52
- none: false
53
- prerelease: false
46
+ - !ruby/object:Gem::Dependency
54
47
  name: httparty
55
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
56
50
  requirements:
57
51
  - - ! '>='
58
52
  - !ruby/object:Gem::Version
59
53
  version: '0'
60
- none: false
61
54
  type: :development
62
- - !ruby/object:Gem::Dependency
55
+ prerelease: false
63
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
64
58
  requirements:
65
59
  - - ! '>='
66
60
  - !ruby/object:Gem::Version
67
61
  version: '0'
68
- none: false
69
- prerelease: false
62
+ - !ruby/object:Gem::Dependency
70
63
  name: sinatra
71
64
  requirement: !ruby/object:Gem::Requirement
65
+ none: false
72
66
  requirements:
73
67
  - - ! '>='
74
68
  - !ruby/object:Gem::Version
75
69
  version: '0'
76
- none: false
77
70
  type: :development
78
- - !ruby/object:Gem::Dependency
71
+ prerelease: false
79
72
  version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
80
74
  requirements:
81
75
  - - ! '>='
82
76
  - !ruby/object:Gem::Version
83
77
  version: '0'
84
- none: false
85
- prerelease: false
78
+ - !ruby/object:Gem::Dependency
86
79
  name: shotgun
87
80
  requirement: !ruby/object:Gem::Requirement
81
+ none: false
88
82
  requirements:
89
83
  - - ! '>='
90
84
  - !ruby/object:Gem::Version
91
85
  version: '0'
92
- none: false
93
86
  type: :development
94
- - !ruby/object:Gem::Dependency
87
+ prerelease: false
95
88
  version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
96
90
  requirements:
97
91
  - - ! '>='
98
92
  - !ruby/object:Gem::Version
99
93
  version: '0'
100
- none: false
101
- prerelease: false
94
+ - !ruby/object:Gem::Dependency
102
95
  name: thin
103
96
  requirement: !ruby/object:Gem::Requirement
97
+ none: false
104
98
  requirements:
105
99
  - - ! '>='
106
100
  - !ruby/object:Gem::Version
107
101
  version: '0'
108
- none: false
109
102
  type: :development
110
- - !ruby/object:Gem::Dependency
103
+ prerelease: false
111
104
  version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
112
106
  requirements:
113
107
  - - ! '>='
114
108
  - !ruby/object:Gem::Version
115
109
  version: '0'
116
- none: false
117
- prerelease: false
110
+ - !ruby/object:Gem::Dependency
118
111
  name: rake
119
112
  requirement: !ruby/object:Gem::Requirement
113
+ none: false
120
114
  requirements:
121
115
  - - ! '>='
122
116
  - !ruby/object:Gem::Version
123
117
  version: '0'
124
- none: false
125
118
  type: :development
126
- - !ruby/object:Gem::Dependency
119
+ prerelease: false
127
120
  version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
128
122
  requirements:
129
123
  - - ! '>='
130
124
  - !ruby/object:Gem::Version
131
125
  version: '0'
132
- none: false
133
- prerelease: false
126
+ - !ruby/object:Gem::Dependency
134
127
  name: mocha
135
128
  requirement: !ruby/object:Gem::Requirement
129
+ none: false
136
130
  requirements:
137
131
  - - ! '>='
138
132
  - !ruby/object:Gem::Version
139
133
  version: '0'
140
- none: false
141
134
  type: :development
142
- - !ruby/object:Gem::Dependency
135
+ prerelease: false
143
136
  version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
144
138
  requirements:
145
139
  - - ! '>='
146
140
  - !ruby/object:Gem::Version
147
141
  version: '0'
148
- none: false
149
- prerelease: false
142
+ - !ruby/object:Gem::Dependency
150
143
  name: guard
151
144
  requirement: !ruby/object:Gem::Requirement
145
+ none: false
152
146
  requirements:
153
147
  - - ! '>='
154
148
  - !ruby/object:Gem::Version
155
149
  version: '0'
156
- none: false
157
150
  type: :development
158
- - !ruby/object:Gem::Dependency
151
+ prerelease: false
159
152
  version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
160
154
  requirements:
161
155
  - - ! '>='
162
156
  - !ruby/object:Gem::Version
163
157
  version: '0'
164
- none: false
165
- prerelease: false
158
+ - !ruby/object:Gem::Dependency
166
159
  name: guard-rspec
167
160
  requirement: !ruby/object:Gem::Requirement
161
+ none: false
168
162
  requirements:
169
163
  - - ! '>='
170
164
  - !ruby/object:Gem::Version
171
165
  version: '0'
172
- none: false
173
166
  type: :development
174
- - !ruby/object:Gem::Dependency
167
+ prerelease: false
175
168
  version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
176
170
  requirements:
177
171
  - - ! '>='
178
172
  - !ruby/object:Gem::Version
179
173
  version: '0'
180
- none: false
181
- prerelease: false
174
+ - !ruby/object:Gem::Dependency
182
175
  name: guard-cucumber
183
176
  requirement: !ruby/object:Gem::Requirement
177
+ none: false
184
178
  requirements:
185
179
  - - ! '>='
186
180
  - !ruby/object:Gem::Version
187
181
  version: '0'
188
- none: false
189
182
  type: :development
190
- - !ruby/object:Gem::Dependency
183
+ prerelease: false
191
184
  version_requirements: !ruby/object:Gem::Requirement
185
+ none: false
192
186
  requirements:
193
187
  - - ! '>='
194
188
  - !ruby/object:Gem::Version
195
189
  version: '0'
196
- none: false
197
- prerelease: false
190
+ - !ruby/object:Gem::Dependency
198
191
  name: guard-livereload
199
192
  requirement: !ruby/object:Gem::Requirement
193
+ none: false
200
194
  requirements:
201
195
  - - ! '>='
202
196
  - !ruby/object:Gem::Version
203
197
  version: '0'
204
- none: false
205
198
  type: :development
206
- - !ruby/object:Gem::Dependency
199
+ prerelease: false
207
200
  version_requirements: !ruby/object:Gem::Requirement
201
+ none: false
208
202
  requirements:
209
203
  - - ! '>='
210
204
  - !ruby/object:Gem::Version
211
205
  version: '0'
212
- none: false
213
- prerelease: false
206
+ - !ruby/object:Gem::Dependency
214
207
  name: webmock
215
208
  requirement: !ruby/object:Gem::Requirement
209
+ none: false
216
210
  requirements:
217
211
  - - ! '>='
218
212
  - !ruby/object:Gem::Version
219
213
  version: '0'
220
- none: false
221
214
  type: :development
222
- - !ruby/object:Gem::Dependency
215
+ prerelease: false
223
216
  version_requirements: !ruby/object:Gem::Requirement
217
+ none: false
224
218
  requirements:
225
219
  - - ! '>='
226
220
  - !ruby/object:Gem::Version
227
221
  version: '0'
228
- none: false
229
- prerelease: false
222
+ - !ruby/object:Gem::Dependency
230
223
  name: nokogiri
231
224
  requirement: !ruby/object:Gem::Requirement
225
+ none: false
232
226
  requirements:
233
227
  - - ! '>='
234
228
  - !ruby/object:Gem::Version
235
229
  version: '0'
236
- none: false
237
230
  type: :development
238
- - !ruby/object:Gem::Dependency
231
+ prerelease: false
239
232
  version_requirements: !ruby/object:Gem::Requirement
233
+ none: false
240
234
  requirements:
241
- - - ~>
235
+ - - ! '>='
242
236
  - !ruby/object:Gem::Version
243
- version: '0.4'
244
- none: false
245
- prerelease: false
237
+ version: '0'
238
+ - !ruby/object:Gem::Dependency
246
239
  name: appraisal
247
240
  requirement: !ruby/object:Gem::Requirement
241
+ none: false
248
242
  requirements:
249
243
  - - ~>
250
244
  - !ruby/object:Gem::Version
251
245
  version: '0.4'
252
- none: false
253
246
  type: :development
254
- - !ruby/object:Gem::Dependency
247
+ prerelease: false
255
248
  version_requirements: !ruby/object:Gem::Requirement
249
+ none: false
256
250
  requirements:
257
- - - ! '>='
251
+ - - ~>
258
252
  - !ruby/object:Gem::Version
259
- version: '0'
260
- none: false
261
- prerelease: false
253
+ version: '0.4'
254
+ - !ruby/object:Gem::Dependency
262
255
  name: rack
263
256
  requirement: !ruby/object:Gem::Requirement
257
+ none: false
264
258
  requirements:
265
259
  - - ! '>='
266
260
  - !ruby/object:Gem::Version
267
261
  version: '0'
268
- none: false
269
262
  type: :runtime
263
+ prerelease: false
264
+ version_requirements: !ruby/object:Gem::Requirement
265
+ none: false
266
+ requirements:
267
+ - - ! '>='
268
+ - !ruby/object:Gem::Version
269
+ version: '0'
270
270
  description: Insert LiveReload into your app easily as Rack middleware
271
271
  email:
272
272
  - john@coswellproductions.com
@@ -312,26 +312,26 @@ rdoc_options: []
312
312
  require_paths:
313
313
  - lib
314
314
  required_ruby_version: !ruby/object:Gem::Requirement
315
+ none: false
315
316
  requirements:
316
317
  - - ! '>='
317
318
  - !ruby/object:Gem::Version
318
319
  version: '0'
319
320
  segments:
320
321
  - 0
321
- hash: 3395376648771001342
322
- none: false
322
+ hash: 1147904501328183443
323
323
  required_rubygems_version: !ruby/object:Gem::Requirement
324
+ none: false
324
325
  requirements:
325
326
  - - ! '>='
326
327
  - !ruby/object:Gem::Version
327
328
  version: '0'
328
329
  segments:
329
330
  - 0
330
- hash: 3395376648771001342
331
- none: false
331
+ hash: 1147904501328183443
332
332
  requirements: []
333
333
  rubyforge_project: rack-livereload
334
- rubygems_version: 1.8.24
334
+ rubygems_version: 1.8.25
335
335
  signing_key:
336
336
  specification_version: 3
337
337
  summary: Insert LiveReload into your app easily as Rack middleware