Class: RTFDoc::Renderer

Inherits:
Redcarpet::Render::Base
  • Object
show all
Defined in:
lib/rtfdoc.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Renderer

Returns a new instance of Renderer.



38
39
40
41
42
# File 'lib/rtfdoc.rb', line 38

def initialize(*args)
  super
  @rouge_formatter  = Rouge::Formatters::HTML.new
  @rouge_lexer      = Rouge::Lexers::JSON.new
end

Instance Attribute Details

#rouge_formatterObject (readonly)

Returns the value of attribute rouge_formatter.



36
37
38
# File 'lib/rtfdoc.rb', line 36

def rouge_formatter
  @rouge_formatter
end

#rouge_lexerObject (readonly)

Returns the value of attribute rouge_lexer.



36
37
38
# File 'lib/rtfdoc.rb', line 36

def rouge_lexer
  @rouge_lexer
end

Instance Method Details

#block_code(code, language) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
# 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) ⇒ Object



100
101
102
# File 'lib/rtfdoc.rb', line 100

def block_html(raw_html)
  raw_html
end

#codespan(code) ⇒ Object



104
105
106
# File 'lib/rtfdoc.rb', line 104

def codespan(code)
  "<code>#{code}</code>"
end

#double_emphasis(text) ⇒ Object



48
49
50
# File 'lib/rtfdoc.rb', line 48

def double_emphasis(text)
  "<strong>#{text}</strong>"
end

#emphasis(text) ⇒ Object



44
45
46
# File 'lib/rtfdoc.rb', line 44

def emphasis(text)
  "<em>#{text}</em>"
end

#header(text, level) ⇒ Object



60
61
62
63
64
65
66
# 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


56
57
58
# File 'lib/rtfdoc.rb', line 56

def link(link, title, content)
  %(<a title="#{title}" href="#{link}">#{content}</a>)
end

#paragraph(text) ⇒ Object



52
53
54
# File 'lib/rtfdoc.rb', line 52

def paragraph(text)
  "<p>#{text}</p>"
end

#table(header, body) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/rtfdoc.rb', line 68

def table(header, body)
  "    <div class=\"table-wrapper\">\n      <div class=\"header-table\">\#{@table_title}</div>\n      <table>\n        <thead></thead>\n        <tbody>\#{body}</tbody>\n      </table>\n    </div>\n  HTML\nensure\n  @table_title = nil\nend\n"

#table_cell(content, alignment) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
# 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) ⇒ Object



82
83
84
# File 'lib/rtfdoc.rb', line 82

def table_row(content)
  content.empty? ? nil : "<tr>#{content}</tr>"
end