Remove duplicate server methods and solve webrick logging in a platform-independent way

This commit is contained in:
Ben Hollis 2012-05-16 21:19:03 -07:00
parent 8c87bbc757
commit 64a2933161
5 changed files with 6 additions and 43 deletions

View file

@ -262,41 +262,4 @@ module Middleman
end
end
class << self
# Create a new Class which is based on Middleman::Application
# Used to create a safe sandbox into which extensions and
# configuration can be included later without impacting
# other classes and instances.
#
# @return [Class]
def server(&block)
@@servercounter ||= 0
@@servercounter += 1
const_set("MiddlemanApplication#{@@servercounter}", Class.new(Middleman::Application))
end
# Creates a new Rack::Server
#
# @param [Hash] options to pass to Rack::Server.new
# @return [Rack::Server]
def start_server(options={})
opts = {
:Port => options[:port] || 4567,
:Host => options[:host] || "0.0.0.0",
:AccessLog => []
}
app_class = options[:app] ||= ::Middleman.server.inst
opts[:app] = app_class
require "webrick"
opts[:Logger] = WEBrick::Log::new("/dev/null", 7) if !options[:logging]
opts[:server] = 'webrick'
server = ::Rack::Server.new(opts)
server.start
server
end
end
end

View file

@ -61,7 +61,7 @@ module Middleman::Cli
#
# @return [Middleman::Application]
def shared_instance(verbose=false)
@_shared_instance ||= ::Middleman.server.inst do
@_shared_instance ||= ::Middleman::Application.server.inst do
set :environment, :build
set :logging, verbose
end

View file

@ -149,7 +149,7 @@ module Middleman
opts[:app] = app_class
require "webrick"
opts[:Logger] = WEBrick::Log::new(RUBY_PLATFORM =~ /(mingw|bccwin|wince|mswin32)/i ? 'NUL:' : '/dev/null', 7) if !options[:logging]
opts[:Logger] = WEBrick::Log::new(nil, 0) if !options[:logging]
opts[:server] = 'webrick'
server = ::Rack::Server.new(opts)

View file

@ -47,7 +47,7 @@ Given /^the Server is running$/ do
set :show_exceptions, false
}
@server_inst = Middleman.server.inst do
@server_inst = Middleman::Application.server.inst do
initialize_commands.each do |p|
instance_exec(&p)
end

View file

@ -65,7 +65,7 @@ module Middleman
env = (@options[:environment] || "development").to_sym
is_logging = @options.has_key?(:debug) && @options[:debug]
app = ::Middleman.server.inst do
app = ::Middleman::Application.server.inst do
set :environment, env
set :logging, is_logging
end
@ -76,7 +76,7 @@ module Middleman
opts[:app] = app_rack
opts[:logging] = is_logging
puts "== The Middleman is standing watch on port #{opts[:port]||4567}"
::Middleman.start_server(opts)
::Middleman::Application.start_server(opts)
end
# Stop the forked Middleman