class DataStory::Renderer
Public Class Methods
new(path)
click to toggle source
# File lib/datastory.rb, line 8 def initialize(path) @path = path @markdown = Redcarpet::Markdown.new(DataStory::MarkdownRenderer, no_intra_emphasis: true, fenced_code_blocks: true, autolink: true, disable_indented_code_blocks: true, strikethrough: true, lax_spacing: true, space_after_headers: true, superscript: true, underline: true, highlight: true, footnotes: true) end
Public Instance Methods
render_to(output_path)
click to toggle source
# File lib/datastory.rb, line 24 def render_to(output_path) markdown_data = File.read(@path) output = @markdown.render(markdown_data) doc = <<-EOF <!DOCTYPE html> <html> <head> <title>DataStory</title> <style> body { font-family: Helvetica, Arial, sans-serif; font-size: 100%; } h1,h2,h3,h4,h5,h6 { font-family: "Times", "Times New Roman", serif; } h1 { font-size: 2.5rem; } pre { background: #eee; padding: 8px; } footer { font-size: .8rem; border-top: 2px solid #eee; } table { max-width: 100%; overflow: scroll; border-collapse: collapse; margin: 1rem 0; font-size: .8rem } table caption { margin-bottom: .5rem; font-size: 1rem; } td, th { border: 1px solid #ccc; padding: 3px; } th { background: #eee; } .content { width: 80%; margin: 0 auto; } </style> </head> <body> <div class="content"> #{output} <footer> <p> <em>Generated by <a href="http://github.com/commondream/datastory">DataStory</a> on #{Time.now}</em>. <a href="#{DataURI.from_data("text/plain", markdown_data)}">Original Source</a> </p> </footer> </div> </body> </html> EOF File.open(output_path, "wb") do |file| file.write(doc) end end