Class: DataStory::MarkdownRenderer

Inherits:
Redcarpet::Render::HTML
  • Object
show all
Defined in:
lib/datastory/markdown_renderer.rb

Instance Method Summary collapse

Instance Method Details

#block_code(code, language) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 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) ⇒ Object

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.



31
32
33
34
35
36
37
38
39
40
41
42
# 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