Module: Middleman::PreviewServer

Defined in:
lib/middleman-core/preview_server.rb

Defined Under Namespace

Classes: FilteredWebrickLog

Constant Summary collapse

DEFAULT_PORT =
4567

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.appObject (readonly)

Returns the value of attribute app.



10
11
12
# File 'lib/middleman-core/preview_server.rb', line 10

def app
  @app
end

.hostObject (readonly)

Returns the value of attribute host.



10
11
12
# File 'lib/middleman-core/preview_server.rb', line 10

def host
  @host
end

.portObject (readonly)

Returns the value of attribute port.



10
11
12
# File 'lib/middleman-core/preview_server.rb', line 10

def port
  @port
end

Class Method Details

.reloadvoid

This method returns an undefined value.

Simply stop, then start the server



62
63
64
65
66
67
68
69
# File 'lib/middleman-core/preview_server.rb', line 62

def reload
  logger.info "== The Middleman is reloading"

  unmount_instance
  mount_instance

  logger.info "== The Middleman is standing watch at http://#{host}:#{port}"
end

.shutdownvoid

This method returns an undefined value.

Stop the current instance, exit Webrick



73
74
75
76
# File 'lib/middleman-core/preview_server.rb', line 73

def shutdown
  stop
  @webrick.shutdown
end

.start(opts = {}) ⇒ void

This method returns an undefined value.

Start an instance of Middleman::Application



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/middleman-core/preview_server.rb', line 15

def start(opts={})
  @options = opts
  @host = @options[:host] || Socket.gethostname
  @port = @options[:port] || DEFAULT_PORT

  mount_instance
  logger.info "== The Middleman is standing watch at http://#{host}:#{port}"
  logger.info "== Inspect your site configuration at http://#{host}:#{port}/__middleman/"

  @initialized ||= false
  unless @initialized
    @initialized = true

    register_signal_handlers

    # Save the last-used @options so it may be re-used when
    # reloading later on.
    ::Middleman::Profiling.report("server_start")

    @webrick.start

    # $mm_shutdown is set by the signal handler
    if $mm_shutdown
      shutdown
      exit
    end
  end
end

.stopvoid

This method returns an undefined value.

Detach the current Middleman::Application instance



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/middleman-core/preview_server.rb', line 46

def stop
  begin
    logger.info "== The Middleman is shutting down"
  rescue
    # if the user closed their terminal STDOUT/STDERR won't exist
  end

  if @listener
    @listener.stop
    @listener = nil
  end
  unmount_instance
end