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
|
end
|
||||||
|
|
||||||
def process!(env)
|
def process!(env)
|
||||||
|
@env = env
|
||||||
@body.close if @body.respond_to?(:close)
|
@body.close if @body.respond_to?(:close)
|
||||||
|
|
||||||
@new_body = [] ; @body.each { |line| @new_body << line.to_s }
|
@new_body = [] ; @body.each { |line| @new_body << line.to_s }
|
||||||
@ -70,22 +71,6 @@ module Rack
|
|||||||
|
|
||||||
@new_body.each do |line|
|
@new_body.each do |line|
|
||||||
if !@livereload_added && line['<head']
|
if !@livereload_added && line['<head']
|
||||||
host_to_use = (@options[:host] || env['HTTP_HOST'] || 'localhost').gsub(%r{:.*}, '')
|
|
||||||
|
|
||||||
app_root = ENV['RAILS_RELATIVE_URL_ROOT'] || ''
|
|
||||||
|
|
||||||
if use_vendored?
|
|
||||||
src = "#{app_root}#{LIVERELOAD_JS_PATH.dup}?host=#{host_to_use}"
|
|
||||||
else
|
|
||||||
src = livereload_local_uri.dup.gsub('localhost', host_to_use) + '?'
|
|
||||||
end
|
|
||||||
|
|
||||||
src << "&mindelay=#{@options[:min_delay]}" if @options[:min_delay]
|
|
||||||
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)}} }
|
line.gsub!(HEAD_TAG_REGEX) { |match| %{#{match}#{template.result(binding)}} }
|
||||||
|
|
||||||
@livereload_added = true
|
@livereload_added = true
|
||||||
@ -95,6 +80,32 @@ module Rack
|
|||||||
@processed = true
|
@processed = true
|
||||||
end
|
end
|
||||||
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
|
||||||
|
src = livereload_local_uri.dup.gsub('localhost', host_to_use) + '?'
|
||||||
|
end
|
||||||
|
|
||||||
|
src << "&mindelay=#{@options[:min_delay]}" if @options[:min_delay]
|
||||||
|
src << "&maxdelay=#{@options[:max_delay]}" if @options[:max_delay]
|
||||||
|
src << "&port=#{@options[:port]}" if @options[:port]
|
||||||
|
|
||||||
|
src
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -11,5 +11,5 @@
|
|||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
RACK_LIVERELOAD_PORT = <%= @options[:live_reload_port] %>;
|
RACK_LIVERELOAD_PORT = <%= @options[:live_reload_port] %>;
|
||||||
</script>
|
</script>
|
||||||
<script type="text/javascript" src="<%= src %>"></script>
|
<script type="text/javascript" src="<%= livereload_source %>"></script>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user