class RTFDoc::Renderer
Attributes
rouge_formatter[R]
rouge_lexer[R]
Public Class Methods
new(*args)
click to toggle source
Calls superclass method
# File lib/rtfdoc.rb, line 38 def initialize(*args) super @rouge_formatter = Rouge::Formatters::HTML.new @rouge_lexer = Rouge::Lexers::JSON.new end
Public Instance Methods
block_code(code, language)
click to toggle source
# File lib/rtfdoc.rb, line 108 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)
click to toggle source
# File lib/rtfdoc.rb, line 100 def block_html(raw_html) raw_html end
codespan(code)
click to toggle source
# File lib/rtfdoc.rb, line 104 def codespan(code) "<code>#{code}</code>" end
double_emphasis(text)
click to toggle source
# File lib/rtfdoc.rb, line 48 def double_emphasis(text) "<strong>#{text}</strong>" end
emphasis(text)
click to toggle source
# File lib/rtfdoc.rb, line 44 def emphasis(text) "<em>#{text}</em>" end
header(text, level)
click to toggle source
# File lib/rtfdoc.rb, line 60 def header(text, level) if level == 4 %(<div class="header-table">#{text}</div>) else "<h#{level}>#{text}</h#{level}>" end end
link(link, title, content)
click to toggle source
# File lib/rtfdoc.rb, line 56 def link(link, title, content) %(<a title="#{title}" href="#{link}">#{content}</a>) end
paragraph(text)
click to toggle source
# File lib/rtfdoc.rb, line 52 def paragraph(text) "<p>#{text}</p>" end
table(header, body)
click to toggle source
# File lib/rtfdoc.rb, line 68 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)
click to toggle source
# File lib/rtfdoc.rb, line 86 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)
click to toggle source
# File lib/rtfdoc.rb, line 82 def table_row(content) content.empty? ? nil : "<tr>#{content}</tr>" end
Private Instance Methods
format_code(title, code)
click to toggle source
# File lib/rtfdoc.rb, line 120 def format_code(title, code) <<-HTML <div class="section-response"> <div class="response-topbar">#{title}</div> <pre><code>#{rouge_formatter.format(rouge_lexer.lex(code.strip))}</code></pre> </div> HTML end