Merge pull request #503 from bhollis/master
Clean up listener handling in preview server
This commit is contained in:
commit
121715e2be
2 changed files with 18 additions and 9 deletions
|
@ -62,6 +62,7 @@ Master
|
||||||
* `layout`, `ignore`, and `directory_index` can be set from front matter.
|
* `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.
|
* 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)
|
* 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.
|
* Include vendored assets in sprockets path.
|
||||||
* Finally support Compass in Sprockets! Thanks to @xdite and @petebrowne
|
* Finally support Compass in Sprockets! Thanks to @xdite and @petebrowne
|
||||||
* Moved Sprockets into an extension
|
* Moved Sprockets into an extension
|
||||||
|
|
|
@ -23,11 +23,13 @@ module Middleman
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
puts "== The Middleman is standing watch on port #{options[:port]||4567}"
|
port = options[:port] || DEFAULT_PORT
|
||||||
|
|
||||||
|
puts "== The Middleman is standing watch on port #{port}"
|
||||||
|
|
||||||
@webrick ||= setup_webrick(
|
@webrick ||= setup_webrick(
|
||||||
options[:host] || "0.0.0.0",
|
options[:host] || "0.0.0.0",
|
||||||
options[:port] || DEFAULT_PORT,
|
port,
|
||||||
options[:debug] || false
|
options[:debug] || false
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -53,6 +55,10 @@ module Middleman
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def stop
|
def stop
|
||||||
puts "== The Middleman is shutting down"
|
puts "== The Middleman is shutting down"
|
||||||
|
if @listener
|
||||||
|
@listener.stop
|
||||||
|
@listener = nil
|
||||||
|
end
|
||||||
unmount_instance
|
unmount_instance
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -76,16 +82,18 @@ module Middleman
|
||||||
# Watcher Library
|
# Watcher Library
|
||||||
require "listen"
|
require "listen"
|
||||||
|
|
||||||
listener = Listen.to(Dir.pwd, :relative_paths => true)
|
return if @listener
|
||||||
|
|
||||||
listener.change do |modified, added, removed|
|
@listener = Listen.to(Dir.pwd, :relative_paths => true)
|
||||||
|
|
||||||
|
@listener.change do |modified, added, removed|
|
||||||
added_and_modified = (modified + added)
|
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
|
# See if the changed file is config.rb or lib/*.rb
|
||||||
if needs_to_reload?(added_and_modified)
|
if needs_to_reload?(added_and_modified)
|
||||||
reload
|
reload
|
||||||
return listener.stop
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
# Otherwise forward to Middleman
|
# Otherwise forward to Middleman
|
||||||
|
@ -94,11 +102,11 @@ module Middleman
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if removed.length > 0
|
unless removed.empty?
|
||||||
# See if the changed file is config.rb or lib/*.rb
|
# See if the changed file is config.rb or lib/*.rb
|
||||||
if needs_to_reload?(removed)
|
if needs_to_reload?(removed)
|
||||||
reload
|
reload
|
||||||
return listener.stop
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
# Otherwise forward to Middleman
|
# Otherwise forward to Middleman
|
||||||
|
@ -109,7 +117,7 @@ module Middleman
|
||||||
end
|
end
|
||||||
|
|
||||||
# Don't block this thread
|
# Don't block this thread
|
||||||
listener.start(false)
|
@listener.start(false)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Trap the interupt signal and shut down smoothly
|
# Trap the interupt signal and shut down smoothly
|
||||||
|
|
Loading…
Reference in a new issue