Class: Cheatly::Renderer
- Inherits:
-
Redcarpet::Render::Base
- Object
- Redcarpet::Render::Base
- Cheatly::Renderer
- Defined in:
- lib/cheatly/renderer.rb
Instance Method Summary collapse
- #block_code(code, language = nil) ⇒ Object
- #codespan(code) ⇒ Object
- #double_emphasis(text) ⇒ Object
- #emphasis(text) ⇒ Object
- #header(title, level) ⇒ Object
- #image(color, bg_color, text) ⇒ Object
- #linebreak ⇒ Object
- #list(content, list_type) ⇒ Object
- #list_item(content, list_type) ⇒ Object
- #normal_text(text) ⇒ Object
- #paragraph(text) ⇒ Object
Instance Method Details
#block_code(code, language = nil) ⇒ Object
9 10 11 12 13 |
# File 'lib/cheatly/renderer.rb', line 9 def block_code(code, language = nil) code = code.each_line code = code.map { |l| " #{l}" } "\n#{code.join}\n" end |
#codespan(code) ⇒ Object
15 16 17 |
# File 'lib/cheatly/renderer.rb', line 15 def codespan(code) "`#{code}`" end |
#double_emphasis(text) ⇒ Object
29 30 31 |
# File 'lib/cheatly/renderer.rb', line 29 def double_emphasis(text) text.bold end |
#emphasis(text) ⇒ Object
33 34 35 |
# File 'lib/cheatly/renderer.rb', line 33 def emphasis(text) text.underline end |
#header(title, level) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/cheatly/renderer.rb', line 19 def header(title, level) sep = case level when 1 then '=' when 2 then '+' when 3 then '-' end "\n#{title.bold}\n#{(sep * title.length).bold}\n" end |
#image(color, bg_color, text) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/cheatly/renderer.rb', line 55 def image(color, bg_color, text) text = text.colorize(color: color.to_sym) text = text.colorize(background: bg_color.to_sym) if bg_color text end |
#linebreak ⇒ Object
41 42 43 |
# File 'lib/cheatly/renderer.rb', line 41 def linebreak "\n" end |
#list(content, list_type) ⇒ Object
45 46 47 |
# File 'lib/cheatly/renderer.rb', line 45 def list(content, list_type) content end |
#list_item(content, list_type) ⇒ Object
49 50 51 52 53 |
# File 'lib/cheatly/renderer.rb', line 49 def list_item(content, list_type) lines = content.each_line lines = lines.map { |l| " #{l}" } " - #{lines.join.strip}\n" end |
#normal_text(text) ⇒ Object
5 6 7 |
# File 'lib/cheatly/renderer.rb', line 5 def normal_text(text) text end |
#paragraph(text) ⇒ Object
37 38 39 |
# File 'lib/cheatly/renderer.rb', line 37 def paragraph(text) "#{text}\n" end |