Module: ExecutableStories::DocEntry

Defined in:
lib/executable_stories/doc_entry.rb

Class Method Summary collapse

Class Method Details

.apply_children(entry, children) ⇒ Object



67
68
69
70
71
72
# File 'lib/executable_stories/doc_entry.rb', line 67

def apply_children(entry, children)
  return entry unless children && !children.empty?

  entry["children"] = children.map { |c| c.is_a?(Hash) ? c : c.to_h }
  entry
end

.code(label, content, lang: nil, children: nil) ⇒ Object



29
30
31
32
33
# File 'lib/executable_stories/doc_entry.rb', line 29

def code(label, content, lang: nil, children: nil)
  entry = { "kind" => "code", "label" => label, "content" => content, "phase" => "runtime" }
  entry["lang"] = lang if lang
  apply_children(entry, children)
end

.custom(type, data, children: nil) ⇒ Object



62
63
64
65
# File 'lib/executable_stories/doc_entry.rb', line 62

def custom(type, data, children: nil)
  entry = { "kind" => "custom", "type" => type, "data" => data, "phase" => "runtime" }
  apply_children(entry, children)
end

.json_doc(label, value, children: nil) ⇒ Object



22
23
24
25
26
27
# File 'lib/executable_stories/doc_entry.rb', line 22

def json_doc(label, value, children: nil)
  require "json"
  content = JSON.pretty_generate(value)
  entry = { "kind" => "code", "label" => label, "content" => content, "lang" => "json", "phase" => "runtime" }
  apply_children(entry, children)
end

.kv(label, value, children: nil) ⇒ Object



17
18
19
20
# File 'lib/executable_stories/doc_entry.rb', line 17

def kv(label, value, children: nil)
  entry = { "kind" => "kv", "label" => label, "value" => value, "phase" => "runtime" }
  apply_children(entry, children)
end


40
41
42
43
# File 'lib/executable_stories/doc_entry.rb', line 40

def link(label, url, children: nil)
  entry = { "kind" => "link", "label" => label, "url" => url, "phase" => "runtime" }
  apply_children(entry, children)
end

.mermaid(code, title: nil, children: nil) ⇒ Object



50
51
52
53
54
# File 'lib/executable_stories/doc_entry.rb', line 50

def mermaid(code, title: nil, children: nil)
  entry = { "kind" => "mermaid", "code" => code, "phase" => "runtime" }
  entry["title"] = title if title
  apply_children(entry, children)
end

.note(text, children: nil) ⇒ Object



7
8
9
10
# File 'lib/executable_stories/doc_entry.rb', line 7

def note(text, children: nil)
  entry = { "kind" => "note", "text" => text, "phase" => "runtime" }
  apply_children(entry, children)
end

.screenshot(path, alt: nil, children: nil) ⇒ Object



56
57
58
59
60
# File 'lib/executable_stories/doc_entry.rb', line 56

def screenshot(path, alt: nil, children: nil)
  entry = { "kind" => "screenshot", "path" => path, "phase" => "runtime" }
  entry["alt"] = alt if alt
  apply_children(entry, children)
end

.section(title, markdown, children: nil) ⇒ Object



45
46
47
48
# File 'lib/executable_stories/doc_entry.rb', line 45

def section(title, markdown, children: nil)
  entry = { "kind" => "section", "title" => title, "markdown" => markdown, "phase" => "runtime" }
  apply_children(entry, children)
end

.table(label, columns, rows, children: nil) ⇒ Object



35
36
37
38
# File 'lib/executable_stories/doc_entry.rb', line 35

def table(label, columns, rows, children: nil)
  entry = { "kind" => "table", "label" => label, "columns" => columns, "rows" => rows, "phase" => "runtime" }
  apply_children(entry, children)
end

.tag(*names, children: nil) ⇒ Object



12
13
14
15
# File 'lib/executable_stories/doc_entry.rb', line 12

def tag(*names, children: nil)
  entry = { "kind" => "tag", "names" => names.flatten, "phase" => "runtime" }
  apply_children(entry, children)
end