Merge pull request #503 from bhollis/master

Clean up listener handling in preview server
This commit is contained in:
Thomas Reynolds 2012-06-28 01:07:31 -07:00
commit 121715e2be
2 changed files with 18 additions and 9 deletions

View file

@ -62,6 +62,7 @@ Master
* `layout`, `ignore`, and `directory_index` can be set from front matter.
* JavaScript and CSS are minified no matter where they are in the site, including in inline code blocks.
* Files with just a template extension get output with the correct exension (foo.erb => foo.html)
* `link_to` is smart about source paths, and can produce relative URLs with the `:relative` option or the sitewide `:relative_links` setting.
* Include vendored assets in sprockets path.
* Finally support Compass in Sprockets! Thanks to @xdite and @petebrowne
* Moved Sprockets into an extension

View file

@ -22,12 +22,14 @@ module Middleman
set :logging, true
end
end
port = options[:port] || DEFAULT_PORT
puts "== The Middleman is standing watch on port #{options[:port]||4567}"
puts "== The Middleman is standing watch on port #{port}"
@webrick ||= setup_webrick(
options[:host] || "0.0.0.0",
options[:port] || DEFAULT_PORT,
port,
options[:debug] || false
)
@ -53,6 +55,10 @@ module Middleman
# @return [void]
def stop
puts "== The Middleman is shutting down"
if @listener
@listener.stop
@listener = nil
end
unmount_instance
end
@ -76,16 +82,18 @@ module Middleman
# Watcher Library
require "listen"
listener = Listen.to(Dir.pwd, :relative_paths => true)
return if @listener
@listener = Listen.to(Dir.pwd, :relative_paths => true)
listener.change do |modified, added, removed|
@listener.change do |modified, added, removed|
added_and_modified = (modified + added)
if added_and_modified.length > 0
unless added_and_modified.empty?
# See if the changed file is config.rb or lib/*.rb
if needs_to_reload?(added_and_modified)
reload
return listener.stop
return
end
# Otherwise forward to Middleman
@ -94,11 +102,11 @@ module Middleman
end
end
if removed.length > 0
unless removed.empty?
# See if the changed file is config.rb or lib/*.rb
if needs_to_reload?(removed)
reload
return listener.stop
return
end
# Otherwise forward to Middleman
@ -109,7 +117,7 @@ module Middleman
end
# Don't block this thread
listener.start(false)
@listener.start(false)
end
# Trap the interupt signal and shut down smoothly