module Syntropy

def self.file_watch(machine, *roots, period: 0.1, &block)

def self.file_watch(machine, *roots, period: 0.1, &block)
  raise 'Missing root paths' if roots.empty?
  require 'listen'
  queue = Thread::Queue.new
  listener = Listen.to(*roots) do |modified, added, removed|
    modified.each { queue.push([:modified, it]) }
    added.each    { queue.push([:added, it]) }
    removed.each  { queue.push([:removed, it]) }
  end
  listener.start
  loop do
    machine.sleep(period) while queue.empty?
    event, fn = queue.shift
    block.call(event, fn)
  end
rescue StandardError => e
  p e
  p e.backtrace
ensure
  listener.stop
end

def self.parse_markdown_file(path, opts)

Returns:
  • (Array) - an tuple containing properties, contents

Parameters:
  • path (String) -- file path
def self.parse_markdown_file(path, opts)
  content = IO.read(path) || ''
  atts = {}
  # Parse date from file name
  m = path.match(DATE_REGEXP)
  atts[:date] ||= Date.parse(m[1]) if m
  if (m = content.match(FRONT_MATTER_REGEXP))
    front_matter = m[1]
    content = m.post_match
    yaml = YAML.safe_load(front_matter, **YAML_OPTS)
    atts = atts.merge(yaml)
  end
  if opts[:location]
    atts[:url] = path
                 .gsub(/#{opts[:location]}/, '')
                 .gsub(/\.md$/, '')
  end
  [atts, content]
end

def colorize(color_code)

def colorize(color_code)
  "\e[#{color_code}m#{self}\e[0m"
end

def side_run(&block)

def side_run(&block)
  raise 'Syntropy.machine not set' if !@machine
  SideRun.call(@machine, &block)
end