Class: Jekyll::Commands::Serve

Inherits:
Jekyll::Command show all
Defined in:
lib/jekyll/commands/serve.rb,
lib/jekyll/commands/serve/servlet.rb

Defined Under Namespace

Classes: Servlet

Constant Summary collapse

COMMAND_OPTIONS =
{
  "ssl_cert" => ["--ssl-cert [CERT]", "X.509 (SSL) certificate."],
  "host"     => ["host", "-H", "--host [HOST]", "Host to bind to"],
  "open_url" => ["-o", "--open-url", "Launch your browser with your site."],
  "detach"   => ["-B", "--detach", "Run the server in the background (detach)"],
  "ssl_key"  => ["--ssl-key [KEY]", "X.509 (SSL) Private Key."],
  "port"     => ["-P", "--port [PORT]", "Port to listen on"],
  "baseurl"  => ["-b", "--baseurl [URL]", "Base URL"],
  "skip_initial_build" => ["skip_initial_build", "--skip-initial-build",
    "Skips the initial site build which occurs before the server is started."]
}

Class Method Summary collapse

Methods inherited from Jekyll::Command

add_build_options, configuration_from_options, inherited, process_site, subclasses

Class Method Details

.init_with_program(prog) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/jekyll/commands/serve.rb', line 19

def init_with_program(prog)
  prog.command(:serve) do |cmd|
    cmd.description "Serve your site locally"
    cmd.syntax "serve [options]"
    cmd.alias :server
    cmd.alias :s

    add_build_options(cmd)
    COMMAND_OPTIONS.each do |key, val|
      cmd.option key, *val
    end

    cmd.action do |_, opts|
      opts["serving"] = true
      opts["watch"  ] = true unless opts.key?("watch")
      Build.process(opts)
      Serve.process(opts)
    end
  end
end

.process(opts) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/jekyll/commands/serve.rb', line 42

def process(opts)
  opts = configuration_from_options(opts)
  destination = opts["destination"]
  setup(destination)

  server = WEBrick::HTTPServer.new(webrick_opts(opts)).tap { |o| o.unmount("") }
  server.mount(opts["baseurl"], Servlet, destination, file_handler_opts)
  Jekyll.logger.info "Server address:", server_address(server, opts)
  launch_browser server, opts if opts["open_url"]
  boot_or_detach server, opts
end