a little more code shuffling to clean up the body processor class a bit
This commit is contained in:
parent
13e09428f3
commit
176ce40003
@ -61,6 +61,7 @@ module Rack
|
||||
end
|
||||
|
||||
def process!(env)
|
||||
@env = env
|
||||
@body.close if @body.respond_to?(:close)
|
||||
|
||||
@new_body = [] ; @body.each { |line| @new_body << line.to_s }
|
||||
@ -70,10 +71,29 @@ module Rack
|
||||
|
||||
@new_body.each do |line|
|
||||
if !@livereload_added && line['<head']
|
||||
host_to_use = (@options[:host] || env['HTTP_HOST'] || 'localhost').gsub(%r{:.*}, '')
|
||||
line.gsub!(HEAD_TAG_REGEX) { |match| %{#{match}#{template.result(binding)}} }
|
||||
|
||||
app_root = ENV['RAILS_RELATIVE_URL_ROOT'] || ''
|
||||
@livereload_added = true
|
||||
end
|
||||
|
||||
@content_length += line.bytesize
|
||||
@processed = true
|
||||
end
|
||||
end
|
||||
|
||||
def app_root
|
||||
ENV['RAILS_RELATIVE_URL_ROOT'] || ''
|
||||
end
|
||||
|
||||
def host_to_use
|
||||
(@options[:host] || @env['HTTP_HOST'] || 'localhost').gsub(%r{:.*}, '')
|
||||
end
|
||||
|
||||
def template
|
||||
ERB.new(::File.read(::File.expand_path('../../../../skel/livereload.html.erb', __FILE__)))
|
||||
end
|
||||
|
||||
def livereload_source
|
||||
if use_vendored?
|
||||
src = "#{app_root}#{LIVERELOAD_JS_PATH.dup}?host=#{host_to_use}"
|
||||
else
|
||||
@ -84,16 +104,7 @@ module Rack
|
||||
src << "&maxdelay=#{@options[:max_delay]}" if @options[:max_delay]
|
||||
src << "&port=#{@options[:port]}" if @options[:port]
|
||||
|
||||
template = ERB.new(::File.read(::File.expand_path('../../../../skel/livereload.html.erb', __FILE__)))
|
||||
|
||||
line.gsub!(HEAD_TAG_REGEX) { |match| %{#{match}#{template.result(binding)}} }
|
||||
|
||||
@livereload_added = true
|
||||
end
|
||||
|
||||
@content_length += line.bytesize
|
||||
@processed = true
|
||||
end
|
||||
src
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -11,5 +11,5 @@
|
||||
<script type="text/javascript">
|
||||
RACK_LIVERELOAD_PORT = <%= @options[:live_reload_port] %>;
|
||||
</script>
|
||||
<script type="text/javascript" src="<%= src %>"></script>
|
||||
<script type="text/javascript" src="<%= livereload_source %>"></script>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user