Class: Hawkins::Commands::LiveServe

Inherits:
Jekyll::Command
  • Object
show all
Defined in:
lib/hawkins/servlet.rb,
lib/hawkins/liveserve.rb

Defined Under Namespace

Classes: BodyProcessor, ReloadServlet, SkipAnalyzer

Constant Summary collapse

COMMAND_OPTIONS =
{
  "swf"      => ["--swf", "Use Flash for WebSockets support"],
  "ignore"   => ["--ignore GLOB1[,GLOB2[,...]]", "Files not to reload"],
  "min_delay" => ["--min-delay [SECONDS]", "Minimum reload delay"],
  "max_delay" => ["--max-delay [SECONDS]", "Maximum reload delay"],
  "reload_port" => ["--reload-port [PORT]", Integer, "Port for LiveReload to listen on"],
}.merge(Jekyll::Commands::Serve.singleton_class::COMMAND_OPTIONS).freeze
LIVERELOAD_PORT =
35729

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.is_runningObject (readonly)

Returns the value of attribute is_running.



23
24
25
# File 'lib/hawkins/liveserve.rb', line 23

def is_running
  @is_running
end

.mutexObject (readonly)

Returns the value of attribute mutex.



23
24
25
# File 'lib/hawkins/liveserve.rb', line 23

def mutex
  @mutex
end

.running_condObject (readonly)

Returns the value of attribute running_cond.



23
24
25
# File 'lib/hawkins/liveserve.rb', line 23

def running_cond
  @running_cond
end

Class Method Details

.init_with_program(prog) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/hawkins/liveserve.rb', line 27

def init_with_program(prog)
  prog.command(:liveserve) do |cmd|
    cmd.description "Serve your site locally with LiveReload"
    cmd.syntax "liveserve [options]"
    cmd.alias :liveserver
    cmd.alias :l

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

    cmd.action do |_, opts|
      opts["reload_port"] ||= LIVERELOAD_PORT
      opts["serving"] = true
      opts["watch"] = true unless opts.key?("watch")
      start(opts)
    end
  end
end

.process(opts) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/hawkins/liveserve.rb', line 57

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

  @reload_reactor.start(opts)
  @server = WEBrick::HTTPServer.new(webrick_opts(opts)).tap { |o| o.unmount("") }

  @server.mount("#{opts['baseurl']}/__livereload",
    WEBrick::HTTPServlet::FileHandler, LIVERELOAD_DIR)
  @server.mount(opts["baseurl"], ReloadServlet, 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

.shutdownObject



74
75
76
# File 'lib/hawkins/liveserve.rb', line 74

def shutdown
  @server.shutdown if @is_running
end

.start(opts) ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/hawkins/liveserve.rb', line 48

def start(opts)
  config = opts["config"]
  @reload_reactor = nil
  register_reload_hooks(opts)
  Jekyll::Commands::Build.process(opts)
  opts["config"] = config
  LiveServe.process(opts)
end