class Mdify::Renderer

Attributes

content[R]
title[R]

Public Class Methods

new(filename) click to toggle source
# File lib/mdify/renderer.rb, line 7
def initialize(filename)
  @title = filename.split("/").last
  @content = File.read(filename)
end

Public Instance Methods

render() click to toggle source
# File lib/mdify/renderer.rb, line 12
def render
  html = Redcarpet.new(@content).to_html
  document = render_html(@title, html)
  temp_file = create_temp_file(document)
  if RUBY_PLATFORM.downcase.include?("darwin")
    exec "open #{temp_file}"
  else
    exec "launchy #{temp_file}"
  end
end

Protected Instance Methods

create_temp_file(contents) click to toggle source
# File lib/mdify/renderer.rb, line 31
def create_temp_file(contents)
  temp_file = Tempfile.new("mdify")
  temp_file.write(contents)
  temp_file.close
  temp_file.path
end
render_html(title, html) click to toggle source
# File lib/mdify/renderer.rb, line 25
def render_html(title, html)
  template_file = File.read(HTML_TEMPLATE_PATH)
  document = template_file.sub(/\{\{ title \}\}/, title)
  document.sub!(/\{\{ body \}\}/, html)
end