class DataStory::MarkdownRenderer

Public Instance Methods

block_code(code, language) click to toggle source
# File lib/datastory/markdown_renderer.rb, line 7
    def block_code(code, language)
      output = ""
      
      unless language == "ruby-datastory-erb"
        output += <<-EOF
          <pre><code class="#{language}">#{CGI.escapeHTML(code)}</code></pre>
        EOF
      end
        
      if language == "ruby-datastory"
        eval_output = EvalContext.evaluate(code)
        
        if eval_output.length > 0
          output += "<p>Output:</p><pre>#{CGI.escapeHTML(eval_output)}</pre>"
        end
      elsif language == "ruby-datastory-erb"
        output += EvalContext.evaluate_erb(code)
      end
      
      output
    end
image(link, title, alt_text) click to toggle source

Inserts an image. If the image is relative to the current path it'll load it as a data URI to make the resulting report self contained.

# File lib/datastory/markdown_renderer.rb, line 31
    def image(link, title, alt_text)
      if link.start_with?("http")
        <<-EOF
          <img src="#{link}" alt="#{alt_text}" title="#{title}">
        EOF
      else
        src = DataURI.from_file(link)
        <<-EOF
          <img src="#{src}" alt="#{alt_text}" title="#{title}">
        EOF
      end
    end