Class: RTFDoc::Renderer
- Inherits:
-
Redcarpet::Render::Base
- Object
- Redcarpet::Render::Base
- RTFDoc::Renderer
- Defined in:
- lib/rtfdoc.rb
Instance Attribute Summary collapse
-
#rouge_formatter ⇒ Object
readonly
Returns the value of attribute rouge_formatter.
-
#rouge_lexer ⇒ Object
readonly
Returns the value of attribute rouge_lexer.
Instance Method Summary collapse
- #block_code(code, language) ⇒ Object
- #block_html(raw_html) ⇒ Object
- #codespan(code) ⇒ Object
- #double_emphasis(text) ⇒ Object
- #emphasis(text) ⇒ Object
- #header(text, level) ⇒ Object
-
#initialize(*args) ⇒ Renderer
constructor
A new instance of Renderer.
- #paragraph(text) ⇒ Object
- #table(header, body) ⇒ Object
- #table_cell(content, alignment) ⇒ Object
- #table_row(content) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Renderer
Returns a new instance of Renderer.
22 23 24 25 26 |
# File 'lib/rtfdoc.rb', line 22 def initialize(*args) super @rouge_formatter = Rouge::Formatters::HTML.new @rouge_lexer = Rouge::Lexers::JSON.new end |
Instance Attribute Details
#rouge_formatter ⇒ Object (readonly)
Returns the value of attribute rouge_formatter.
20 21 22 |
# File 'lib/rtfdoc.rb', line 20 def rouge_formatter @rouge_formatter end |
#rouge_lexer ⇒ Object (readonly)
Returns the value of attribute rouge_lexer.
20 21 22 |
# File 'lib/rtfdoc.rb', line 20 def rouge_lexer @rouge_lexer end |
Instance Method Details
#block_code(code, language) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/rtfdoc.rb', line 88 def block_code(code, language) if language == 'attributes' || language == 'parameters' AttributesComponent.new(code, language).output elsif language == 'response' <<-HTML <div class="section-response"> <div class="response-topbar">RESPONSE</div> <pre><code>#{rouge_formatter.format(rouge_lexer.lex(code.strip))}</code></pre> </div> HTML end end |
#block_html(raw_html) ⇒ Object
80 81 82 |
# File 'lib/rtfdoc.rb', line 80 def block_html(raw_html) raw_html end |
#codespan(code) ⇒ Object
84 85 86 |
# File 'lib/rtfdoc.rb', line 84 def codespan(code) "<code>#{code}</code>" end |
#double_emphasis(text) ⇒ Object
32 33 34 |
# File 'lib/rtfdoc.rb', line 32 def double_emphasis(text) "<strong>#{text}</strong>" end |
#emphasis(text) ⇒ Object
28 29 30 |
# File 'lib/rtfdoc.rb', line 28 def emphasis(text) "<em>#{text}</em>" end |
#header(text, level) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/rtfdoc.rb', line 40 def header(text, level) if level == 4 %(<div class="header-table">#{text}</div>) else "<h#{level}>#{text}</h#{level}>" end end |
#paragraph(text) ⇒ Object
36 37 38 |
# File 'lib/rtfdoc.rb', line 36 def paragraph(text) "<p>#{text}</p>" end |
#table(header, body) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/rtfdoc.rb', line 48 def table(header, body) <<-HTML <div class="table-wrapper"> <div class="header-table">#{@table_title}</div> <table> <thead></thead> <tbody>#{body}</tbody> </table> </div> HTML ensure @table_title = nil end |
#table_cell(content, alignment) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/rtfdoc.rb', line 66 def table_cell(content, alignment) if !alignment @table_title = content unless content.empty? return end c = case alignment when 'left' then 'definition'.freeze when 'right' then 'property'.freeze end "<td class=\"cell-#{c}\">#{content}</td>" end |
#table_row(content) ⇒ Object
62 63 64 |
# File 'lib/rtfdoc.rb', line 62 def table_row(content) content.empty? ? nil : "<tr>#{content}</tr>" end |