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
31 32 33 |
# File 'lib/cheatly/renderer.rb', line 31 def double_emphasis(text) text.bold end |
#emphasis(text) ⇒ Object
35 36 37 |
# File 'lib/cheatly/renderer.rb', line 35 def emphasis(text) text.underline end |
#header(title, level) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/cheatly/renderer.rb', line 19 def header(title, level) sep = case level when 1 then '=' when 2 then '+' when 3 then '-' else '' end "\n#{title.bold}\n#{(sep * title.length).bold}\n" end |
#image(color, bg_color, text) ⇒ Object
57 58 59 60 61 62 |
# File 'lib/cheatly/renderer.rb', line 57 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
43 44 45 |
# File 'lib/cheatly/renderer.rb', line 43 def linebreak "\n" end |
#list(content, list_type) ⇒ Object
47 48 49 |
# File 'lib/cheatly/renderer.rb', line 47 def list(content, list_type) content end |
#list_item(content, list_type) ⇒ Object
51 52 53 54 55 |
# File 'lib/cheatly/renderer.rb', line 51 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
39 40 41 |
# File 'lib/cheatly/renderer.rb', line 39 def paragraph(text) "#{text}\n" end |