From f6cf8de14116428eb14503b0e58d1bf2900986d9 Mon Sep 17 00:00:00 2001 From: Kunal Parikh Date: Sun, 11 Nov 2012 13:16:47 +1100 Subject: [PATCH] Changed log message when middleman starts. Old message: == The Middleman is standing watch on port 4567 New message: == The Middleman is standing watch at http://0.0.0.0:4567 The URL in the message makes it clickable if the terminal supports it. --- .../lib/middleman-core/preview_server.rb | 39 +++++++++---------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/middleman-core/lib/middleman-core/preview_server.rb b/middleman-core/lib/middleman-core/preview_server.rb index 2d6f187d..5713c619 100644 --- a/middleman-core/lib/middleman-core/preview_server.rb +++ b/middleman-core/lib/middleman-core/preview_server.rb @@ -3,20 +3,22 @@ require "webrick" module Middleman module PreviewServer + DEFAULT_HOST = '0.0.0.0' DEFAULT_PORT = 4567 class << self - attr_reader :app, :port + attr_reader :app, :host, :port delegate :logger, :to => :app # Start an instance of Middleman::Application # @return [void] def start(opts={}) @options = opts + @host = @options[:host] || DEFAULT_HOST @port = @options[:port] || DEFAULT_PORT mount_instance - logger.info "== The Middleman is standing watch on port #{port}" + logger.info "== The Middleman is standing watch at http://#{host}:#{port}" @initialized ||= false unless @initialized @@ -52,11 +54,11 @@ module Middleman # @return [void] def reload logger.info "== The Middleman is reloading" - + unmount_instance mount_instance - - logger.info "== The Middleman is standing watch on port #{port}" + + logger.info "== The Middleman is standing watch at http://#{host}:#{port}" end # Stop the current instance, exit Webrick @@ -73,22 +75,22 @@ module Middleman if opts[:environment] set :environment, opts[:environment].to_sym end - + logger(opts[:debug] ? 0 : 1, opts[:instrumenting] || false) end end def start_file_watcher return if @options[:"disable-watcher"] - + first_run = !@listener - + if first_run # Watcher Library require "listen" @listener = Listen.to(Dir.pwd, :relative_paths => true) end - + @listener.change do |modified, added, removed| added_and_modified = (modified + added) @@ -125,11 +127,9 @@ module Middleman # Initialize webrick # @return [void] - def setup_webrick(host, is_logging) - @host = host - + def setup_webrick(is_logging) http_opts = { - :BindAddress => @host, + :BindAddress => host, :Port => port, :AccessLog => [] } @@ -154,13 +154,10 @@ module Middleman def mount_instance @app = new_app - @webrick ||= setup_webrick( - @options[:host] || "0.0.0.0", - @options[:debug] || false - ) - + @webrick ||= setup_webrick(@options[:debug] || false) + start_file_watcher - + @webrick.mount "/", ::Rack::Handler::WEBrick, app.class.to_rack_app end @@ -180,13 +177,13 @@ module Middleman %r{^lib/^[^\.](.*)\.rb$}, %r{^helpers/^[^\.](.*)_helper\.rb$} ] - + if @options[:reload_paths] @options[:reload_paths].split(',').each do |part| match_against << %r{^#{part}} end end - + paths.any? do |path| match_against.any? do |matcher| path.match(matcher)