1 defmodule Pleroma.Docs.Markdown do
2 @behaviour Pleroma.Docs.Generator
4 @spec process(keyword()) :: {:ok, String.t()}
5 def process(descriptions) do
6 config_path = "docs/config.md"
7 {:ok, file} = File.open(config_path, [:utf8, :write])
8 IO.write(file, "# Configuration\n")
9 IO.write(file, "Date of generation: #{Date.utc_today()}\n\n")
13 "This file describe the configuration, it is recommended to edit the relevant `*.secret.exs` file instead of the others founds in the ``config`` directory.\n\n" <>
14 "If you run Pleroma with ``MIX_ENV=prod`` the file is ``prod.secret.exs``, otherwise it is ``dev.secret.exs``.\n\n"
17 for group <- descriptions do
18 if is_nil(group[:key]) do
19 IO.write(file, "## #{inspect(group[:group])}\n")
21 IO.write(file, "## #{inspect(group[:key])}\n")
24 IO.write(file, "#{group[:description]}\n")
26 for child <- group[:children] do
27 print_child_header(file, child)
29 print_suggestions(file, child[:suggestions])
31 if child[:children] do
32 for subchild <- child[:children] do
33 print_child_header(file, subchild)
35 print_suggestions(file, subchild[:suggestions])
43 :ok = File.close(file)
47 defp print_suggestion(file, suggestion) when is_list(suggestion) do
48 IO.write(file, " `#{inspect(suggestion)}`\n")
51 defp print_suggestion(file, suggestion) when is_function(suggestion) do
52 IO.write(file, " `#{inspect(suggestion.())}`\n")
55 defp print_suggestion(file, suggestion, as_list \\ false) do
56 list_mark = if as_list, do: "- ", else: ""
57 IO.write(file, " #{list_mark}`#{inspect(suggestion)}`\n")
60 defp print_suggestions(_file, nil), do: nil
62 defp print_suggestions(file, suggestions) do
63 IO.write(file, "Suggestions:\n")
65 if length(suggestions) > 1 do
66 for suggestion <- suggestions do
67 print_suggestion(file, suggestion, true)
70 print_suggestion(file, List.first(suggestions))
74 defp print_child_header(file, child) do
75 IO.write(file, "- `#{inspect(child[:key])}` -`#{inspect(child[:type])}` \n")
76 IO.write(file, "#{child[:description]} \n")