Class: Documented::Renderer

Inherits:
Object
  • Object
show all
Defined in:
lib/renderer.rb

Instance Method Summary collapse

Constructor Details

#initialize(gem_path, output_path) ⇒ Renderer

Returns a new instance of Renderer.



3
4
5
6
# File 'lib/renderer.rb', line 3

def initialize(gem_path, output_path)
  @gem_path = gem_path
  @output_path = output_path
end

Instance Method Details

#render(file_path) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/renderer.rb', line 8

def render(file_path)
  # file_names = [
  #   "README.md",
  # ]
  # file_names.each do |file_name|
  #   file = File.read(File.join(@gem_path, "output", file_name))
  #   File.open(File.join(@output_path, file_name), 'w+') do |f|
  #     f.write file
  #   end
  # end

  Documented.sequences.each do |sequence|
    file_name = File.basename(file_path, File.extname(file_path)) + '.md'
    directory = File.join(@output_path, file_name)

    output = <<~TEXT
      ```mermaid
      sequenceDiagram;
      #{sequence.map { |step| "  #{step}" }.join("\n")}
      ````
    TEXT

    File.write(directory, output)
  end
end