class Marksman::Watcher

Public Class Methods

new(file, output_directory, theme_name = nil) click to toggle source
# File lib/marksman/watcher.rb, line 6
def initialize(file, output_directory, theme_name = nil)
  @file = Pathname.new file
  @output_directory = output_directory
  @theme_name = theme_name
end

Public Instance Methods

listen() click to toggle source
# File lib/marksman/watcher.rb, line 23
def listen
  puts 'Listening to changes...'
  @markdown_listener = Listen.to(Pathname.new(@file).dirname) do |modified, added, removed|
    if modified.include? @file.realpath.to_s
      update
    end
  end
  @markdown_listener.start
  sleep
end
start_theme_listener(theme) click to toggle source
# File lib/marksman/watcher.rb, line 34
def start_theme_listener(theme)
  @theme_listener = Listen.to(theme.path) do |modified, added, removed|
    update
  end
  @theme_listener.start
end
stop() click to toggle source
# File lib/marksman/watcher.rb, line 41
def stop
  @markdown_listener.stop
  @theme_listener.stop if @theme_listener
end
update(start_listener = false) click to toggle source
# File lib/marksman/watcher.rb, line 17
def update(start_listener = false)
  puts 'Updating files...'
  presentation = Marksman::Writer.new(@file, @output_directory, @theme_name).generate
  start_theme_listener(presentation.theme) unless @theme_listener
end
watch() click to toggle source
# File lib/marksman/watcher.rb, line 12
def watch
  update(true)
  listen
end