Class: Codegen::MarkdownGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/bkmrq/codegen/markdown_generator.rb

Overview

Generator for markdown

Class Method Summary collapse

Class Method Details

.blockquote(text) ⇒ Object



40
41
42
# File 'lib/bkmrq/codegen/markdown_generator.rb', line 40

def self.blockquote(text)
  "> #{text}"
end

.bold(text) ⇒ Object



36
37
38
# File 'lib/bkmrq/codegen/markdown_generator.rb', line 36

def self.bold(text)
  "**#{text}**"
end

.code(text) ⇒ Object



44
45
46
# File 'lib/bkmrq/codegen/markdown_generator.rb', line 44

def self.code(text)
  "`#{text}`"
end

.codeblock(text, source_lang = '') ⇒ Object



70
71
72
73
74
75
76
# File 'lib/bkmrq/codegen/markdown_generator.rb', line 70

def self.codeblock(text, source_lang = '')
  <<~CDB
    ```#{source_lang}
    #{text}
    ```
  CDB
end

.highlight(text) ⇒ Object



19
20
21
# File 'lib/bkmrq/codegen/markdown_generator.rb', line 19

def self.highlight(text)
  "==#{text}=="
end

.horizontal_ruleObject



52
53
54
# File 'lib/bkmrq/codegen/markdown_generator.rb', line 52

def self.horizontal_rule
  '---'
end

.image(url, alt_text) ⇒ Object



7
8
9
# File 'lib/bkmrq/codegen/markdown_generator.rb', line 7

def self.image(url, alt_text)
  "![#{alt_text}](#{url})"
end

.italic(text) ⇒ Object



48
49
50
# File 'lib/bkmrq/codegen/markdown_generator.rb', line 48

def self.italic(text)
  "*#{text}*"
end

.line(text) ⇒ Object



60
61
62
# File 'lib/bkmrq/codegen/markdown_generator.rb', line 60

def self.line(text)
  "#{text}  "
end


56
57
58
# File 'lib/bkmrq/codegen/markdown_generator.rb', line 56

def self.link(text, url)
  "[#{text}](#{url})"
end

.ordered_list(items) ⇒ Object



30
31
32
33
34
# File 'lib/bkmrq/codegen/markdown_generator.rb', line 30

def self.ordered_list(items)
  items
    .map.with_index { |item, index| "#{index.next}. #{item}" }
    .join("\n")
end

.strikethrough(text) ⇒ Object



15
16
17
# File 'lib/bkmrq/codegen/markdown_generator.rb', line 15

def self.strikethrough(text)
  "--#{text}--"
end

.tasklist(items, completed_indices = []) ⇒ Object



23
24
25
26
27
28
# File 'lib/bkmrq/codegen/markdown_generator.rb', line 23

def self.tasklist(items, completed_indices = [])
  items
    .map
    .with_index { |item, index| "- [#{completed_indices.include?(index) ? 'x' : ''}] #{item}" }
    .join("\n")
end

.title(text, level = 1, id = nil) ⇒ Object



11
12
13
# File 'lib/bkmrq/codegen/markdown_generator.rb', line 11

def self.title(text, level = 1, id = nil)
  (('#' * level) + " #{text}") + (id ? "{##{id}}" : '')
end

.unordered_list(items) ⇒ Object



64
65
66
67
68
# File 'lib/bkmrq/codegen/markdown_generator.rb', line 64

def self.unordered_list(items)
  items
    .map { |item| "- #{item}" }
    .join("\n")
end