From 17d4bed4eb4139282d31e6aacded94011e4bba1a Mon Sep 17 00:00:00 2001 From: John Bintz Date: Mon, 7 Nov 2011 08:49:42 -0500 Subject: [PATCH] a few more fixes --- Guardfile | 14 +------------- lib/rack/livereload.rb | 11 +++++++---- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/Guardfile b/Guardfile index ead071e..eed3765 100644 --- a/Guardfile +++ b/Guardfile @@ -3,19 +3,7 @@ guard 'rspec', :version => 2 do watch(%r{^spec/.+_spec\.rb$}) - watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" } + watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } watch('spec/spec_helper.rb') { "spec" } - - # Rails example - watch(%r{^spec/.+_spec\.rb$}) - watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } - watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" } - watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] } - watch(%r{^spec/support/(.+)\.rb$}) { "spec" } - watch('spec/spec_helper.rb') { "spec" } - watch('config/routes.rb') { "spec/routing" } - watch('app/controllers/application_controller.rb') { "spec/controllers" } - # Capybara request specs - watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" } end diff --git a/lib/rack/livereload.rb b/lib/rack/livereload.rb index bc42950..a1592c6 100644 --- a/lib/rack/livereload.rb +++ b/lib/rack/livereload.rb @@ -16,19 +16,22 @@ module Rack case headers['Content-Type'] when %r{text/html} + content_length = 0 + body.each do |line| - if line[''] + if !headers['X-Rack-LiveReload'] && line[''] src = LIVERELOAD_JS_PATH.dup src << "?host=#{env['HTTP_HOST'].gsub(%r{:.*}, '')}" if env['HTTP_HOST'] line.gsub!('', %{}) - headers["X-Rack-LiveReload"] = '1' - break + headers["X-Rack-LiveReload"] = '1' end + + content_length += line.length end - headers['Content-Length'] = body.join.length.to_s + headers['Content-Length'] = content_length.to_s end [ status, headers, body ]