Sha256: e991339b04719c309befa8ab59b793d01abcd74efab6851b01ef5b02b1e2fe19
Contents?: true
Size: 849 Bytes
Versions: 2
Compression:
Stored size: 849 Bytes
Contents
module Mdify HTML_TEMPLATE_PATH = File.join(File.dirname(__FILE__), "..", "..", "vendor", "template.html") class Renderer attr_reader :title, :content def initialize(filename) @title = filename.split("/").last @content = File.read(filename) end def render html = Redcarpet.new(@content).to_html document = render_html(@title, html) temp_file = create_temp_file(document) exec "launchy #{temp_file}" end protected def render_html(title, html) template_file = File.read(HTML_TEMPLATE_PATH) document = template_file.sub(/\{\{ title \}\}/, title) document.sub!(/\{\{ body \}\}/, html) end def create_temp_file(contents) temp_file = Tempfile.new("mdify") temp_file.write(contents) temp_file.close temp_file.path end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
mdify-1.0.0 | lib/mdify/renderer.rb |
mdify-0.4 | lib/mdify/renderer.rb |