class MarkD

Constants

ENGINES

Public Instance Methods

create_engine(extname) click to toggle source
# File lib/markd/markd.rb, line 13
def create_engine(extname)
  ENGINES.each do |regex, engine|
    return engine.new if regex =~ extname
  end
  ENGINES[nil].new
end
publish(filename, out_dir_path, out_filename) click to toggle source
# File lib/markd/markd.rb, line 20
def publish(filename, out_dir_path, out_filename)
  ext = File.extname(filename)
  engine = create_engine ext
  src = File.read filename
  
  # parse
  @html = engine.to_html(src)
  
  doc = Nokogiri::HTML::Document.parse @html
  @title = doc.css("h1:first").text
  
  # render
  erb_src = File.read "#{APP_ROOT}/template/template.html.erb"
  eruby = Erubis::Eruby.new(erb_src)
  html = eruby.result(binding)
  
  # output
  FileUtils.mkdir_p out_dir_path
  File.open("#{out_dir_path}/#{out_filename}", "w") { |f| f.puts html }
  dirs = ::RESOURCES.map { |d| "#{APP_ROOT}/template/#{d}"}
  FileUtils.cp_r(dirs, out_dir_path)
end