Module: Jekyll::Watcher

Extended by:
Watcher
Included in:
Watcher
Defined in:
lib/jekyll/watcher.rb

Instance Method Summary collapse

Instance Method Details

#watch(options, site = nil) ⇒ Object

Public: Continuously watch for file changes and rebuild the site whenever a change is detected.

If the optional site argument is populated, that site instance will be reused and the options Hash ignored. Otherwise, a new site instance will be instantiated from the options Hash and used.

options - A Hash containing the site configuration site - The current site instance (populated starting with Jekyll 3.2)

(optional, default: nil)

Returns nothing.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/jekyll/watcher.rb', line 21

def watch(options, site = nil)
  ENV["LISTEN_GEM_DEBUGGING"] ||= "1" if options["verbose"]

  site ||= Jekyll::Site.new(options)
  listener = build_listener(site, options)
  listener.start

  Jekyll.logger.info "Auto-regeneration:", "enabled for '#{options["source"]}'"

  unless options["serving"]
    trap("INT") do
      listener.stop
      puts "     Halting auto-regeneration."
      exit 0
    end

    sleep_forever
  end
rescue ThreadError
  # You pressed Ctrl-C, oh my!
end