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.
24 25 26 27 28 |
# File 'lib/rtfdoc.rb', line 24 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.
22 23 24 |
# File 'lib/rtfdoc.rb', line 22 def rouge_formatter @rouge_formatter end |
#rouge_lexer ⇒ Object (readonly)
Returns the value of attribute rouge_lexer.
22 23 24 |
# File 'lib/rtfdoc.rb', line 22 def rouge_lexer @rouge_lexer end |
Instance Method Details
#block_code(code, language) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/rtfdoc.rb', line 90 def block_code(code, language) if language == 'attributes' || language == 'parameters' AttributesComponent.new(code, language).output elsif language == 'response' format_code('RESPONSE', code) elsif language == 'title_and_code' title, _code = code.split("\n", 2) title ||= 'RESPONSE' format_code(title, _code) end end |
#block_html(raw_html) ⇒ Object
82 83 84 |
# File 'lib/rtfdoc.rb', line 82 def block_html(raw_html) raw_html end |
#codespan(code) ⇒ Object
86 87 88 |
# File 'lib/rtfdoc.rb', line 86 def codespan(code) "<code>#{code}</code>" end |
#double_emphasis(text) ⇒ Object
34 35 36 |
# File 'lib/rtfdoc.rb', line 34 def double_emphasis(text) "<strong>#{text}</strong>" end |
#emphasis(text) ⇒ Object
30 31 32 |
# File 'lib/rtfdoc.rb', line 30 def emphasis(text) "<em>#{text}</em>" end |
#header(text, level) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/rtfdoc.rb', line 42 def header(text, level) if level == 4 %(<div class="header-table">#{text}</div>) else "<h#{level}>#{text}</h#{level}>" end end |
#paragraph(text) ⇒ Object
38 39 40 |
# File 'lib/rtfdoc.rb', line 38 def paragraph(text) "<p>#{text}</p>" end |
#table(header, body) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/rtfdoc.rb', line 50 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
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/rtfdoc.rb', line 68 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
64 65 66 |
# File 'lib/rtfdoc.rb', line 64 def table_row(content) content.empty? ? nil : "<tr>#{content}</tr>" end |