class ToDo::Visualizer

Relies on pandoc to generate HTML out from a Github flavored markdown file. pandoc.org/installing.html

Constants

BODY_CSS
CSS_URL

Attributes

context[R]

Public Class Methods

new(context) click to toggle source
# File lib/visualizer.rb, line 17
def initialize(context)
  @context = context
end

Public Instance Methods

view() click to toggle source
# File lib/visualizer.rb, line 21
def view
  exit_and_install_pandoc unless system('command -v pandoc', out: ['/dev/null'])
  raise 'Something failed with Pandoc' unless system(command)

  update_body_class
  system("open #{tmpfile}")
end

Private Instance Methods

command() click to toggle source
# File lib/visualizer.rb, line 31
def command
  [
    "pandoc #{context.file_path}",
    '-f gfm',
    '-s',
    "-o #{tmpfile}",
    '--metadata title="TODO"',
    "-c #{CSS_URL}"
  ].join(' ')
end
exit_and_install_pandoc() click to toggle source
# File lib/visualizer.rb, line 42
def exit_and_install_pandoc
  puts 'Please install pandoc first. https://pandoc.org/installing.html'
  exit 1
end
tmpfile() click to toggle source
# File lib/visualizer.rb, line 47
def tmpfile
  "#{File.join(Dir.tmpdir, context.file_name)}.html"
end
update_body_class() click to toggle source

TODO: This can be updated to just modify the body tag

# File lib/visualizer.rb, line 52
def update_body_class
  html = File.read(tmpfile)
  html.sub!('<body>', "<body class='markdown-body' style='#{BODY_CSS}'>")
  File.open(tmpfile, 'wb') { |f| f.puts(html) }
end