diff --git a/lib/rack/livereload.rb b/lib/rack/livereload.rb index 4555892..803c4c5 100644 --- a/lib/rack/livereload.rb +++ b/lib/rack/livereload.rb @@ -61,7 +61,7 @@ module Rack content_length = 0 new_body.each do |line| - if !headers['X-Rack-LiveReload'] && (line[''] || line['', %{#{template.result(binding)}}) + if line[']*>/) { |match| %{#{match}#{template.result(binding)}} } end headers["X-Rack-LiveReload"] = '1' diff --git a/spec/rack/livereload_spec.rb b/spec/rack/livereload_spec.rb index 7bb5081..179a5ec 100644 --- a/spec/rack/livereload_spec.rb +++ b/spec/rack/livereload_spec.rb @@ -95,12 +95,13 @@ describe Rack::LiveReload do end end - context 'before script tags' do - let(:page_html) { '' } + context 'at the top of the head tag' do + let(:page_html) { '' } let(:body_dom) { Nokogiri::XML(body) } it 'should add the livereload js script tag before all other script tags' do + body_dom.at_css("head")[:attribute].should == 'attribute' body_dom.at_css("script:eq(4)")[:src].should include(described_class::LIVERELOAD_JS_PATH) body_dom.at_css("script:last-child")[:insert].should == "before" end