description formatters
[akkoma] / lib / pleroma / docs / markdown.ex
1 defmodule Pleroma.Docs.Markdown do
2 @behaviour Pleroma.Docs.Formatter
3
4 def process(descriptions) do
5 config_path = "docs/config.md"
6 {:ok, file} = File.open(config_path, [:write])
7 IO.write(file, "# Generated configuration\r\n\r\n")
8 IO.write(file, "Date of generation: #{Date.utc_today()}\r\n\r\n")
9
10 IO.write(
11 file,
12 "This file describe the configuration, it is recommended to edit the relevant *.secret.exs file instead of the others founds in the ``config`` directory.
13 If you run Pleroma with ``MIX_ENV=prod`` the file is ``prod.secret.exs``, otherwise it is ``dev.secret.exs``.\r\n\r\n"
14 )
15
16 for group <- descriptions do
17 if is_nil(group[:key]) do
18 IO.write(file, "## #{inspect(group[:group])}\r\n\r\n")
19 else
20 IO.write(file, "## #{inspect(group[:key])}\r\n\r\n")
21 end
22
23 IO.write(file, "Type: `#{group[:type]}` \r\n")
24 IO.write(file, "#{group[:description]} \r\n\r\n")
25
26 for child <- group[:children] do
27 print_child_header(file, child)
28
29 print_suggestions(file, child[:suggestions])
30
31 if child[:children] do
32 for subchild <- child[:children] do
33 print_child_header(file, subchild)
34
35 print_suggestions(file, subchild[:suggestions])
36 end
37 end
38 end
39
40 IO.write(file, "\r\n")
41 end
42
43 :ok = File.close(file)
44 {:ok, config_path}
45 end
46
47 defp print_suggestion(file, suggestion) when is_function(suggestion) do
48 IO.write(file, " `#{inspect(suggestion.())}`\r\n")
49 end
50
51 defp print_suggestion(file, suggestion) do
52 IO.write(file, " `#{inspect(suggestion)}`\r\n")
53 end
54
55 defp print_suggestions(file, suggestions) do
56 IO.write(file, "Suggestions: \r\n")
57
58 for suggestion <- suggestions do
59 print_suggestion(file, suggestion)
60 end
61 end
62
63 defp print_child_header(file, child) do
64 IO.write(file, "* `#{inspect(child[:key])}`: #{child[:description]} \r\n")
65 IO.write(file, "Type: `#{inspect(child[:type])}` \r\n")
66 end
67 end