rack-livereload 0.3.8 → 0.3.9

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright © 2012 John Bintz
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the “Software”), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7
+ of the Software, and to permit persons to whom the Software is furnished to do
8
+ so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
data/README.md CHANGED
@@ -19,7 +19,7 @@ In `config/environments/development.rb`:
19
19
 
20
20
  ``` ruby
21
21
  MyApp::Application.configure do
22
- config.middleware.insert_before(Rack::Lock, Rack::LiveReload)
22
+ config.middleware.insert_after(ActionDispatch::Static, Rack::LiveReload)
23
23
 
24
24
  # ...or, change some options...
25
25
 
@@ -47,7 +47,7 @@ use Rack::LiveReload, :min_delay => 500, ...
47
47
  ## How it works
48
48
 
49
49
  The necessary `script` tag to bring in a copy of [livereload.js](https://github.com/livereload/livereload-js) is
50
- injected right before the closing `head` tag in any `text/html` pages that come through. The `script` tag is built in
50
+ injected right after the opening `head` tag in any `text/html` pages that come through. The `script` tag is built in
51
51
  such a way that the `HTTP_HOST` is used as the LiveReload host, so you can connect from external machines (say, to
52
52
  `mycomputer:3000` instead of `localhost:3000`) and as long as the LiveReload port is accessible from the external machine,
53
53
  you'll connect and be LiveReloading away!
@@ -81,5 +81,3 @@ use Rack::LiveReload, :no_swf => true
81
81
  Once more browsers support WebSockets than don't, this option will be reversed and you'll have
82
82
  to explicitly include the Flash shim.
83
83
 
84
- As usual, super-alpha!
85
-
@@ -1,6 +1,6 @@
1
1
  require "rack/livereload"
2
2
 
3
3
  class Rack::LiveReload
4
- VERSION = '0.3.8'
4
+ VERSION = '0.3.9'
5
5
  end
6
6
 
@@ -61,7 +61,7 @@ module Rack
61
61
  content_length = 0
62
62
 
63
63
  new_body.each do |line|
64
- if !headers['X-Rack-LiveReload'] && line['</head>']
64
+ if !headers['X-Rack-LiveReload'] && line['<head']
65
65
  host_to_use = (@options[:host] || env['HTTP_HOST'] || 'localhost').gsub(%r{:.*}, '')
66
66
 
67
67
  if use_vendored?
@@ -76,7 +76,9 @@ module Rack
76
76
 
77
77
  template = ERB.new(::File.read(::File.expand_path('../../../skel/livereload.html.erb', __FILE__)))
78
78
 
79
- line.gsub!('</head>', %{#{template.result(binding)}</head>})
79
+ if line['<head']
80
+ line.gsub!(/<head[^>]*>/) { |match| %{#{match}#{template.result(binding)}} }
81
+ end
80
82
 
81
83
  headers["X-Rack-LiveReload"] = '1'
82
84
  end
@@ -32,6 +32,7 @@ Gem::Specification.new do |s|
32
32
  s.add_development_dependency "guard-cucumber"
33
33
  s.add_development_dependency "guard-livereload"
34
34
  s.add_development_dependency "webmock"
35
+ s.add_development_dependency "nokogiri"
35
36
  s.add_development_dependency 'appraisal', '~> 0.4'
36
37
  s.add_runtime_dependency "rack"
37
38
  end
@@ -1,4 +1,5 @@
1
1
  require 'spec_helper'
2
+ require 'nokogiri'
2
3
 
3
4
  describe Rack::LiveReload do
4
5
  let(:middleware) { described_class.new(app, options) }
@@ -67,7 +68,7 @@ describe Rack::LiveReload do
67
68
 
68
69
  context 'text/html' do
69
70
  before do
70
- app.stubs(:call).with(env).returns([ 200, { 'Content-Type' => 'text/html', 'Content-Length' => 0 }, [ '<head></head>' ] ])
71
+ app.stubs(:call).with(env).returns([ 200, { 'Content-Type' => 'text/html', 'Content-Length' => 0 }, [ page_html ] ])
71
72
  middleware.stubs(:use_vendored?).returns(true)
72
73
  end
73
74
 
@@ -78,6 +79,8 @@ describe Rack::LiveReload do
78
79
  let(:body) { ret.last.join }
79
80
  let(:length) { ret[1]['Content-Length'] }
80
81
 
82
+ let(:page_html) { '<head></head>' }
83
+
81
84
  context 'vendored' do
82
85
  it 'should add the vendored livereload js script tag' do
83
86
  body.should include("script")
@@ -92,6 +95,18 @@ describe Rack::LiveReload do
92
95
  end
93
96
  end
94
97
 
98
+ context 'at the top of the head tag' do
99
+ let(:page_html) { '<head attribute="attribute"><script type="text/javascript" insert="first"></script><script type="text/javascript" insert="before"></script></head>' }
100
+
101
+ let(:body_dom) { Nokogiri::XML(body) }
102
+
103
+ it 'should add the livereload js script tag before all other script tags' do
104
+ body_dom.at_css("head")[:attribute].should == 'attribute'
105
+ body_dom.at_css("script:eq(4)")[:src].should include(described_class::LIVERELOAD_JS_PATH)
106
+ body_dom.at_css("script:last-child")[:insert].should == "before"
107
+ end
108
+ end
109
+
95
110
  context 'not vendored' do
96
111
  before do
97
112
  middleware.stubs(:use_vendored?).returns(false)
metadata CHANGED
@@ -1,256 +1,272 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-livereload
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.8
5
4
  prerelease:
5
+ version: 0.3.9
6
6
  platform: ruby
7
7
  authors:
8
8
  - John Bintz
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-18 00:00:00.000000000 Z
12
+ date: 2012-12-05 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
15
22
  name: rspec
16
23
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
24
  requirements:
19
25
  - - ! '>='
20
26
  - !ruby/object:Gem::Version
21
27
  version: '0'
28
+ none: false
22
29
  type: :development
23
- prerelease: false
30
+ - !ruby/object:Gem::Dependency
24
31
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
32
  requirements:
27
33
  - - ! '>='
28
34
  - !ruby/object:Gem::Version
29
35
  version: '0'
30
- - !ruby/object:Gem::Dependency
36
+ none: false
37
+ prerelease: false
31
38
  name: cucumber
32
39
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
40
  requirements:
35
41
  - - ! '>='
36
42
  - !ruby/object:Gem::Version
37
43
  version: '0'
44
+ none: false
38
45
  type: :development
39
- prerelease: false
46
+ - !ruby/object:Gem::Dependency
40
47
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
48
  requirements:
43
49
  - - ! '>='
44
50
  - !ruby/object:Gem::Version
45
51
  version: '0'
46
- - !ruby/object:Gem::Dependency
52
+ none: false
53
+ prerelease: false
47
54
  name: httparty
48
55
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
56
  requirements:
51
57
  - - ! '>='
52
58
  - !ruby/object:Gem::Version
53
59
  version: '0'
60
+ none: false
54
61
  type: :development
55
- prerelease: false
62
+ - !ruby/object:Gem::Dependency
56
63
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
64
  requirements:
59
65
  - - ! '>='
60
66
  - !ruby/object:Gem::Version
61
67
  version: '0'
62
- - !ruby/object:Gem::Dependency
68
+ none: false
69
+ prerelease: false
63
70
  name: sinatra
64
71
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
72
  requirements:
67
73
  - - ! '>='
68
74
  - !ruby/object:Gem::Version
69
75
  version: '0'
76
+ none: false
70
77
  type: :development
71
- prerelease: false
78
+ - !ruby/object:Gem::Dependency
72
79
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
80
  requirements:
75
81
  - - ! '>='
76
82
  - !ruby/object:Gem::Version
77
83
  version: '0'
78
- - !ruby/object:Gem::Dependency
84
+ none: false
85
+ prerelease: false
79
86
  name: shotgun
80
87
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
88
  requirements:
83
89
  - - ! '>='
84
90
  - !ruby/object:Gem::Version
85
91
  version: '0'
92
+ none: false
86
93
  type: :development
87
- prerelease: false
94
+ - !ruby/object:Gem::Dependency
88
95
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
96
  requirements:
91
97
  - - ! '>='
92
98
  - !ruby/object:Gem::Version
93
99
  version: '0'
94
- - !ruby/object:Gem::Dependency
100
+ none: false
101
+ prerelease: false
95
102
  name: thin
96
103
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
104
  requirements:
99
105
  - - ! '>='
100
106
  - !ruby/object:Gem::Version
101
107
  version: '0'
108
+ none: false
102
109
  type: :development
103
- prerelease: false
110
+ - !ruby/object:Gem::Dependency
104
111
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
112
  requirements:
107
113
  - - ! '>='
108
114
  - !ruby/object:Gem::Version
109
115
  version: '0'
110
- - !ruby/object:Gem::Dependency
116
+ none: false
117
+ prerelease: false
111
118
  name: rake
112
119
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
120
  requirements:
115
121
  - - ! '>='
116
122
  - !ruby/object:Gem::Version
117
123
  version: '0'
124
+ none: false
118
125
  type: :development
119
- prerelease: false
126
+ - !ruby/object:Gem::Dependency
120
127
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
128
  requirements:
123
129
  - - ! '>='
124
130
  - !ruby/object:Gem::Version
125
131
  version: '0'
126
- - !ruby/object:Gem::Dependency
132
+ none: false
133
+ prerelease: false
127
134
  name: mocha
128
135
  requirement: !ruby/object:Gem::Requirement
129
- none: false
130
136
  requirements:
131
137
  - - ! '>='
132
138
  - !ruby/object:Gem::Version
133
139
  version: '0'
140
+ none: false
134
141
  type: :development
135
- prerelease: false
142
+ - !ruby/object:Gem::Dependency
136
143
  version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
144
  requirements:
139
145
  - - ! '>='
140
146
  - !ruby/object:Gem::Version
141
147
  version: '0'
142
- - !ruby/object:Gem::Dependency
148
+ none: false
149
+ prerelease: false
143
150
  name: guard
144
151
  requirement: !ruby/object:Gem::Requirement
145
- none: false
146
152
  requirements:
147
153
  - - ! '>='
148
154
  - !ruby/object:Gem::Version
149
155
  version: '0'
156
+ none: false
150
157
  type: :development
151
- prerelease: false
158
+ - !ruby/object:Gem::Dependency
152
159
  version_requirements: !ruby/object:Gem::Requirement
153
- none: false
154
160
  requirements:
155
161
  - - ! '>='
156
162
  - !ruby/object:Gem::Version
157
163
  version: '0'
158
- - !ruby/object:Gem::Dependency
164
+ none: false
165
+ prerelease: false
159
166
  name: guard-rspec
160
167
  requirement: !ruby/object:Gem::Requirement
161
- none: false
162
168
  requirements:
163
169
  - - ! '>='
164
170
  - !ruby/object:Gem::Version
165
171
  version: '0'
172
+ none: false
166
173
  type: :development
167
- prerelease: false
174
+ - !ruby/object:Gem::Dependency
168
175
  version_requirements: !ruby/object:Gem::Requirement
169
- none: false
170
176
  requirements:
171
177
  - - ! '>='
172
178
  - !ruby/object:Gem::Version
173
179
  version: '0'
174
- - !ruby/object:Gem::Dependency
180
+ none: false
181
+ prerelease: false
175
182
  name: guard-cucumber
176
183
  requirement: !ruby/object:Gem::Requirement
177
- none: false
178
184
  requirements:
179
185
  - - ! '>='
180
186
  - !ruby/object:Gem::Version
181
187
  version: '0'
188
+ none: false
182
189
  type: :development
183
- prerelease: false
190
+ - !ruby/object:Gem::Dependency
184
191
  version_requirements: !ruby/object:Gem::Requirement
185
- none: false
186
192
  requirements:
187
193
  - - ! '>='
188
194
  - !ruby/object:Gem::Version
189
195
  version: '0'
190
- - !ruby/object:Gem::Dependency
196
+ none: false
197
+ prerelease: false
191
198
  name: guard-livereload
192
199
  requirement: !ruby/object:Gem::Requirement
193
- none: false
194
200
  requirements:
195
201
  - - ! '>='
196
202
  - !ruby/object:Gem::Version
197
203
  version: '0'
204
+ none: false
198
205
  type: :development
199
- prerelease: false
206
+ - !ruby/object:Gem::Dependency
200
207
  version_requirements: !ruby/object:Gem::Requirement
201
- none: false
202
208
  requirements:
203
209
  - - ! '>='
204
210
  - !ruby/object:Gem::Version
205
211
  version: '0'
206
- - !ruby/object:Gem::Dependency
212
+ none: false
213
+ prerelease: false
207
214
  name: webmock
208
215
  requirement: !ruby/object:Gem::Requirement
209
- none: false
210
216
  requirements:
211
217
  - - ! '>='
212
218
  - !ruby/object:Gem::Version
213
219
  version: '0'
220
+ none: false
214
221
  type: :development
215
- prerelease: false
222
+ - !ruby/object:Gem::Dependency
216
223
  version_requirements: !ruby/object:Gem::Requirement
217
- none: false
218
224
  requirements:
219
225
  - - ! '>='
220
226
  - !ruby/object:Gem::Version
221
227
  version: '0'
222
- - !ruby/object:Gem::Dependency
223
- name: appraisal
228
+ none: false
229
+ prerelease: false
230
+ name: nokogiri
224
231
  requirement: !ruby/object:Gem::Requirement
232
+ requirements:
233
+ - - ! '>='
234
+ - !ruby/object:Gem::Version
235
+ version: '0'
225
236
  none: false
237
+ type: :development
238
+ - !ruby/object:Gem::Dependency
239
+ version_requirements: !ruby/object:Gem::Requirement
226
240
  requirements:
227
241
  - - ~>
228
242
  - !ruby/object:Gem::Version
229
243
  version: '0.4'
230
- type: :development
231
- prerelease: false
232
- version_requirements: !ruby/object:Gem::Requirement
233
244
  none: false
245
+ prerelease: false
246
+ name: appraisal
247
+ requirement: !ruby/object:Gem::Requirement
234
248
  requirements:
235
249
  - - ~>
236
250
  - !ruby/object:Gem::Version
237
251
  version: '0.4'
238
- - !ruby/object:Gem::Dependency
239
- name: rack
240
- requirement: !ruby/object:Gem::Requirement
241
252
  none: false
253
+ type: :development
254
+ - !ruby/object:Gem::Dependency
255
+ version_requirements: !ruby/object:Gem::Requirement
242
256
  requirements:
243
257
  - - ! '>='
244
258
  - !ruby/object:Gem::Version
245
259
  version: '0'
246
- type: :runtime
247
- prerelease: false
248
- version_requirements: !ruby/object:Gem::Requirement
249
260
  none: false
261
+ prerelease: false
262
+ name: rack
263
+ requirement: !ruby/object:Gem::Requirement
250
264
  requirements:
251
265
  - - ! '>='
252
266
  - !ruby/object:Gem::Version
253
267
  version: '0'
268
+ none: false
269
+ type: :runtime
254
270
  description: Insert LiveReload into your app easily as Rack middleware
255
271
  email:
256
272
  - john@coswellproductions.com
@@ -263,6 +279,7 @@ files:
263
279
  - Appraisals
264
280
  - Gemfile
265
281
  - Guardfile
282
+ - LICENSE
266
283
  - README.md
267
284
  - Rakefile
268
285
  - config.ru
@@ -295,26 +312,26 @@ rdoc_options: []
295
312
  require_paths:
296
313
  - lib
297
314
  required_ruby_version: !ruby/object:Gem::Requirement
298
- none: false
299
315
  requirements:
300
316
  - - ! '>='
301
317
  - !ruby/object:Gem::Version
302
318
  version: '0'
303
319
  segments:
304
320
  - 0
305
- hash: -1677998707984246668
306
- required_rubygems_version: !ruby/object:Gem::Requirement
321
+ hash: -4083395389572261075
307
322
  none: false
323
+ required_rubygems_version: !ruby/object:Gem::Requirement
308
324
  requirements:
309
325
  - - ! '>='
310
326
  - !ruby/object:Gem::Version
311
327
  version: '0'
312
328
  segments:
313
329
  - 0
314
- hash: -1677998707984246668
330
+ hash: -4083395389572261075
331
+ none: false
315
332
  requirements: []
316
333
  rubyforge_project: rack-livereload
317
- rubygems_version: 1.8.23
334
+ rubygems_version: 1.8.24
318
335
  signing_key:
319
336
  specification_version: 3
320
337
  summary: Insert LiveReload into your app easily as Rack middleware