rack-livereload 0.3.9 → 0.3.10
Sign up to get free protection for your applications and to get access to all the features.
- data/Guardfile +1 -1
- data/lib/rack-livereload.rb +1 -1
- data/lib/rack/livereload.rb +2 -1
- data/spec/rack/livereload_spec.rb +28 -0
- data/spec/spec_helper.rb +1 -1
- metadata +4 -4
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', :cli => '-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" }
|
data/lib/rack-livereload.rb
CHANGED
data/lib/rack/livereload.rb
CHANGED
@@ -4,6 +4,7 @@ module Rack
|
|
4
4
|
class LiveReload
|
5
5
|
LIVERELOAD_JS_PATH = '/__rack/livereload.js'
|
6
6
|
LIVERELOAD_LOCAL_URI = 'http://localhost:35729/livereload.js'
|
7
|
+
HEAD_TAG_REGEX = /<head>|<head[^(er)][^<]*>/
|
7
8
|
|
8
9
|
BAD_USER_AGENTS = [ %r{MSIE} ]
|
9
10
|
|
@@ -77,7 +78,7 @@ module Rack
|
|
77
78
|
template = ERB.new(::File.read(::File.expand_path('../../../skel/livereload.html.erb', __FILE__)))
|
78
79
|
|
79
80
|
if line['<head']
|
80
|
-
line.gsub!(
|
81
|
+
line.gsub!(HEAD_TAG_REGEX) { |match| %{#{match}#{template.result(binding)}} }
|
81
82
|
end
|
82
83
|
|
83
84
|
headers["X-Rack-LiveReload"] = '1'
|
@@ -107,6 +107,17 @@ describe Rack::LiveReload do
|
|
107
107
|
end
|
108
108
|
end
|
109
109
|
|
110
|
+
context 'in header tags' do
|
111
|
+
let(:page_html) { "<header class='hero'><h1>Just a normal header tag</h1></header>" }
|
112
|
+
|
113
|
+
let(:body_dom) { Nokogiri::XML(body) }
|
114
|
+
|
115
|
+
it 'should not add the livereload js' do
|
116
|
+
body_dom.at_css("header")[:class].should == 'hero'
|
117
|
+
body_dom.css('script').should be_empty
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
110
121
|
context 'not vendored' do
|
111
122
|
before do
|
112
123
|
middleware.stubs(:use_vendored?).returns(false)
|
@@ -212,5 +223,22 @@ describe Rack::LiveReload do
|
|
212
223
|
|
213
224
|
it { should be_bad_browser(user_agent) }
|
214
225
|
end
|
226
|
+
|
227
|
+
describe 'head tag regex' do
|
228
|
+
let(:regex) { described_class::HEAD_TAG_REGEX }
|
229
|
+
subject { regex }
|
230
|
+
|
231
|
+
it { should be_kind_of(Regexp) }
|
232
|
+
|
233
|
+
it 'only picks a valid <head> tag' do
|
234
|
+
regex.match("<head></head>").to_s.should eq('<head>')
|
235
|
+
regex.match("<head><title></title></head>").to_s.should eq('<head>')
|
236
|
+
regex.match("<head attribute='something'><title></title></head>").to_s.should eq("<head attribute='something'>")
|
237
|
+
end
|
238
|
+
|
239
|
+
it 'responds false when no head tag' do
|
240
|
+
regex.match("<header></header>").should be_false
|
241
|
+
end
|
242
|
+
end
|
215
243
|
end
|
216
244
|
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
name: rack-livereload
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.3.
|
5
|
+
version: 0.3.10
|
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-12-
|
12
|
+
date: 2012-12-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -318,7 +318,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
318
318
|
version: '0'
|
319
319
|
segments:
|
320
320
|
- 0
|
321
|
-
hash:
|
321
|
+
hash: 78031654202498146
|
322
322
|
none: false
|
323
323
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
324
324
|
requirements:
|
@@ -327,7 +327,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
327
327
|
version: '0'
|
328
328
|
segments:
|
329
329
|
- 0
|
330
|
-
hash:
|
330
|
+
hash: 78031654202498146
|
331
331
|
none: false
|
332
332
|
requirements: []
|
333
333
|
rubyforge_project: rack-livereload
|