Class: HTMLRenderer::ANSI

Inherits:
Base
  • Object
show all
Defined in:
lib/html-renderer/ansi.rb

Instance Method Summary collapse

Methods inherited from Base

render, #render

Instance Method Details

#anchor(name, title = nil, content = nil) ⇒ Object



75
76
77
78
79
80
81
# File 'lib/html-renderer/ansi.rb', line 75

def anchor(name, title=nil, content=nil)
  result = "Anchor: ##{name}"
  result << " (#{title})" if title
  result << "\n"
  result << "#{content}\n" if content
  result
end

#block_code(code, language) ⇒ Object



91
92
93
# File 'lib/html-renderer/ansi.rb', line 91

def block_code(code, language)
  code.bold.cyan + "\n"
end

#block_quote(text) ⇒ Object



95
96
97
# File 'lib/html-renderer/ansi.rb', line 95

def block_quote(text)
  indent paragraph(text)
end

#codespan(code) ⇒ Object



99
100
101
# File 'lib/html-renderer/ansi.rb', line 99

def codespan(code)
  code.cyan
end

#definition_list(defs) ⇒ Object



159
160
161
162
163
164
165
# File 'lib/html-renderer/ansi.rb', line 159

def definition_list(defs)
  defs.each do |dt, dd|
    puts "<15>#{dt}<7>:".colorize
    puts "  #{dd}"
    puts
  end
end

#div(text) ⇒ Object



132
133
134
# File 'lib/html-renderer/ansi.rb', line 132

def div(text)
  "#{indented?(text) ? text : unwrap(text)}\n"
end

#double_emphasis(text) ⇒ Object



116
117
118
# File 'lib/html-renderer/ansi.rb', line 116

def double_emphasis(text)
  text.bold.green
end

#emphasis(text) ⇒ Object



120
121
122
# File 'lib/html-renderer/ansi.rb', line 120

def emphasis(text)
  text.green
end

#header(title, level, anchor = nil) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/html-renderer/ansi.rb', line 103

def header(title, level, anchor=nil)
  bar = ("-"*(title.size+4)).grey

  title = case level
    when 1 then title.bold.yellow
    when 2 then title.bold.cyan
    when 3 then title.bold.blue
    else title.magenta
  end

  "#{bar}\n  #{title}\n#{bar}\n\n"
end

#image(link, title, content) ⇒ Object



83
84
85
# File 'lib/html-renderer/ansi.rb', line 83

def image(link, title, content)
  link(link, nil, title)
end

#italic(text) ⇒ Object



87
88
89
# File 'lib/html-renderer/ansi.rb', line 87

def italic(text)
  text.yellow.bold
end

#linebreakObject



124
125
126
# File 'lib/html-renderer/ansi.rb', line 124

def linebreak
  "\n"
end


61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/html-renderer/ansi.rb', line 61

def link(link, title, content)
  unless content&.[] /^Back /
    str = ""
    # str += "<15>#{content}</15>" if content
    str += content.white.bold if content
    if smash(link) != smash(content)
      # str += " <8>(</8><11>#{link}</11><8>)</8>"
      str += " #{"(".grey}#{link.cyan.bold}#{")".grey}"
    end

    str
  end
end

#list(content, list_type) ⇒ Object



136
137
138
139
140
141
142
143
144
# File 'lib/html-renderer/ansi.rb', line 136

def list(content, list_type)
  case list_type
  when :ordered
    @counter = 0
    "#{content}\n"
  when :unordered
    "#{content}\n"
  end
end

#list_item(content, list_type) ⇒ Object



146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/html-renderer/ansi.rb', line 146

def list_item(content, list_type)
  case list_type
  when :ordered
    @counter ||= 0
    @counter += 1
    # "  <8>#{@counter}.</8> #{content.strip}\n".colorize
    "  #{@counter.to_s.grey}. #{content.strip}\n"
  when :unordered
    # "  <8>*</8> #{content.strip}\n".colorize
    "  #{"*".grey} #{content.strip}\n"
  end
end

#normal_text(text) ⇒ Object



49
50
51
# File 'lib/html-renderer/ansi.rb', line 49

def normal_text(text)
  text
end

#paragraph(text) ⇒ Object



128
129
130
# File 'lib/html-renderer/ansi.rb', line 128

def paragraph(text)
  div(text) + "\n"
end

#separatorObject



176
177
178
# File 'lib/html-renderer/ansi.rb', line 176

def separator
  "_____________________________\n\n"
end

#superscript(content) ⇒ Object



57
58
59
# File 'lib/html-renderer/ansi.rb', line 57

def superscript(content)
  "^(#{content})"
end

#table(header, rows) ⇒ Object



167
168
169
170
171
172
173
174
# File 'lib/html-renderer/ansi.rb', line 167

def table(header, rows)
  if header
    table = Terminal::Table.new(headings: header, rows: rows)
  else
    table = Terminal::Table.new(rows: rows)
  end
  "#{table}\n\n"
end

#underline(content) ⇒ Object



53
54
55
# File 'lib/html-renderer/ansi.rb', line 53

def underline(content)
  content.magenta.bold
end