1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Docs.Markdown do
6 @behaviour Pleroma.Docs.Generator
8 @spec process(keyword()) :: {:ok, String.t()}
9 def process(descriptions) do
10 config_path = "docs/generated_config.md"
11 {:ok, file} = File.open(config_path, [:utf8, :write])
12 IO.write(file, "# Generated configuration\n")
13 IO.write(file, "Date of generation: #{Date.utc_today()}\n\n")
17 "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" <>
18 "If you run Pleroma with ``MIX_ENV=prod`` the file is ``prod.secret.exs``, otherwise it is ``dev.secret.exs``.\n\n"
21 for group <- descriptions do
22 if is_nil(group[:key]) do
23 IO.write(file, "## #{inspect(group[:group])}\n")
25 IO.write(file, "## #{inspect(group[:key])}\n")
28 IO.write(file, "#{group[:description]}\n")
30 for child <- group[:children] || [] do
31 print_child_header(file, child)
33 print_suggestions(file, child[:suggestions])
35 if child[:children] do
36 for subchild <- child[:children] do
37 print_child_header(file, subchild)
39 print_suggestions(file, subchild[:suggestions])
47 :ok = File.close(file)
51 defp print_child_header(file, %{key: key, type: type, description: description} = _child) do
54 "- `#{inspect(key)}` (`#{inspect(type)}`): #{description} \n"
58 defp print_child_header(file, %{key: key, type: type} = _child) do
59 IO.write(file, "- `#{inspect(key)}` (`#{inspect(type)}`) \n")
62 defp print_suggestion(file, suggestion) when is_list(suggestion) do
63 IO.write(file, " `#{inspect(suggestion)}`\n")
66 defp print_suggestion(file, suggestion) when is_function(suggestion) do
67 IO.write(file, " `#{inspect(suggestion.())}`\n")
70 defp print_suggestion(file, suggestion, as_list \\ false) do
71 list_mark = if as_list, do: "- ", else: ""
72 IO.write(file, " #{list_mark}`#{inspect(suggestion)}`\n")
75 defp print_suggestions(file, {:list_behaviour_implementations, behaviour}) do
76 suggestions = Pleroma.Docs.Generator.list_behaviour_implementations(behaviour)
77 print_suggestions(file, suggestions)
80 defp print_suggestions(_file, nil), do: nil
82 defp print_suggestions(_file, ""), do: nil
84 defp print_suggestions(file, suggestions) do
85 if length(suggestions) > 1 do
86 IO.write(file, "Suggestions:\n")
88 for suggestion <- suggestions do
89 print_suggestion(file, suggestion, true)
92 IO.write(file, " Suggestion: ")
94 print_suggestion(file, List.first(suggestions))