Class: HTMLRenderer::ANSI
Instance Method Summary collapse
- #anchor(name, title = nil, content = nil) ⇒ Object
- #block_code(code, language) ⇒ Object
- #block_quote(text) ⇒ Object
- #codespan(code) ⇒ Object
- #definition_list(defs) ⇒ Object
- #div(text) ⇒ Object
- #double_emphasis(text) ⇒ Object
- #emphasis(text) ⇒ Object
- #header(title, level, anchor = nil) ⇒ Object
- #image(link, title, content) ⇒ Object
- #italic(text) ⇒ Object
- #linebreak ⇒ Object
- #link(link, title, content) ⇒ Object
- #list(content, list_type) ⇒ Object
- #list_item(content, list_type) ⇒ Object
- #normal_text(text) ⇒ Object
- #paragraph(text) ⇒ Object
- #separator ⇒ Object
- #superscript(content) ⇒ Object
- #table(header, rows) ⇒ Object
- #underline(content) ⇒ Object
Methods inherited from Base
Instance Method Details
#anchor(name, title = nil, content = nil) ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/html-renderer/ansi.rb', line 66 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
82 83 84 85 86 87 88 89 90 |
# File 'lib/html-renderer/ansi.rb', line 82 def block_code(code, language) language ||= :ruby language = language[1..-1] if language[0] == "." # strip leading "." language = :cpp if language == "C++" require 'coderay' "#{indent CodeRay.scan(code, language).term, 4}\n" end |
#block_quote(text) ⇒ Object
92 93 94 |
# File 'lib/html-renderer/ansi.rb', line 92 def block_quote(text) indent paragraph(text) end |
#codespan(code) ⇒ Object
96 97 98 |
# File 'lib/html-renderer/ansi.rb', line 96 def codespan(code) code.cyan end |
#definition_list(defs) ⇒ Object
156 157 158 159 160 161 162 |
# File 'lib/html-renderer/ansi.rb', line 156 def definition_list(defs) defs.each do |dt, dd| puts "<15>#{dt}<7>:".colorize puts " #{dd}" puts end end |
#div(text) ⇒ Object
129 130 131 |
# File 'lib/html-renderer/ansi.rb', line 129 def div(text) "#{indented?(text) ? text : unwrap(text)}\n" end |
#double_emphasis(text) ⇒ Object
113 114 115 |
# File 'lib/html-renderer/ansi.rb', line 113 def double_emphasis(text) text.bold.green end |
#emphasis(text) ⇒ Object
117 118 119 |
# File 'lib/html-renderer/ansi.rb', line 117 def emphasis(text) text.green end |
#header(title, level, anchor = nil) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/html-renderer/ansi.rb', line 100 def header(title, level, anchor=nil) = ("-"*(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 "#{}\n #{title}\n#{}\n\n" end |
#image(link, title, content) ⇒ Object
74 75 76 |
# File 'lib/html-renderer/ansi.rb', line 74 def image(link, title, content) link(link, nil, title) end |
#italic(text) ⇒ Object
78 79 80 |
# File 'lib/html-renderer/ansi.rb', line 78 def italic(text) text.yellow.bold end |
#linebreak ⇒ Object
121 122 123 |
# File 'lib/html-renderer/ansi.rb', line 121 def linebreak "\n" end |
#link(link, title, content) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/html-renderer/ansi.rb', line 52 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
133 134 135 136 137 138 139 140 141 |
# File 'lib/html-renderer/ansi.rb', line 133 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
143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/html-renderer/ansi.rb', line 143 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
40 41 42 |
# File 'lib/html-renderer/ansi.rb', line 40 def normal_text(text) text end |
#paragraph(text) ⇒ Object
125 126 127 |
# File 'lib/html-renderer/ansi.rb', line 125 def paragraph(text) div(text) + "\n" end |
#separator ⇒ Object
173 174 175 |
# File 'lib/html-renderer/ansi.rb', line 173 def separator "_____________________________\n\n" end |
#superscript(content) ⇒ Object
48 49 50 |
# File 'lib/html-renderer/ansi.rb', line 48 def superscript(content) "^(#{content})" end |
#table(header, rows) ⇒ Object
164 165 166 167 168 169 170 171 |
# File 'lib/html-renderer/ansi.rb', line 164 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
44 45 46 |
# File 'lib/html-renderer/ansi.rb', line 44 def underline(content) content.magenta.bold end |