logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

markdown.ex (2994B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Docs.Markdown do
  5. @behaviour Pleroma.Docs.Generator
  6. @spec process(keyword()) :: {:ok, String.t()}
  7. def process(descriptions) do
  8. config_path = "docs/generated_config.md"
  9. {:ok, file} = File.open(config_path, [:utf8, :write])
  10. IO.write(file, "# Generated configuration\n")
  11. IO.write(file, "Date of generation: #{Date.utc_today()}\n\n")
  12. IO.write(
  13. file,
  14. "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" <>
  15. "If you run Pleroma with ``MIX_ENV=prod`` the file is ``prod.secret.exs``, otherwise it is ``dev.secret.exs``.\n\n"
  16. )
  17. for group <- descriptions do
  18. if is_nil(group[:key]) do
  19. IO.write(file, "## #{inspect(group[:group])}\n")
  20. else
  21. IO.write(file, "## #{inspect(group[:key])}\n")
  22. end
  23. IO.write(file, "#{group[:description]}\n")
  24. for child <- group[:children] || [] do
  25. print_child_header(file, child)
  26. print_suggestions(file, child[:suggestions])
  27. if child[:children] do
  28. for subchild <- child[:children] do
  29. print_child_header(file, subchild)
  30. print_suggestions(file, subchild[:suggestions])
  31. end
  32. end
  33. end
  34. IO.write(file, "\n")
  35. end
  36. :ok = File.close(file)
  37. {:ok, config_path}
  38. end
  39. defp print_child_header(file, %{key: key, type: type, description: description} = _child) do
  40. IO.write(
  41. file,
  42. "- `#{inspect(key)}` (`#{inspect(type)}`): #{description} \n"
  43. )
  44. end
  45. defp print_child_header(file, %{key: key, type: type} = _child) do
  46. IO.write(file, "- `#{inspect(key)}` (`#{inspect(type)}`) \n")
  47. end
  48. defp print_suggestion(file, suggestion) when is_list(suggestion) do
  49. IO.write(file, " `#{inspect(suggestion)}`\n")
  50. end
  51. defp print_suggestion(file, suggestion) when is_function(suggestion) do
  52. IO.write(file, " `#{inspect(suggestion.())}`\n")
  53. end
  54. defp print_suggestion(file, suggestion, as_list \\ false) do
  55. list_mark = if as_list, do: "- ", else: ""
  56. IO.write(file, " #{list_mark}`#{inspect(suggestion)}`\n")
  57. end
  58. defp print_suggestions(file, {:list_behaviour_implementations, behaviour}) do
  59. suggestions = Pleroma.Docs.Generator.list_behaviour_implementations(behaviour)
  60. print_suggestions(file, suggestions)
  61. end
  62. defp print_suggestions(_file, nil), do: nil
  63. defp print_suggestions(_file, ""), do: nil
  64. defp print_suggestions(file, suggestions) do
  65. if length(suggestions) > 1 do
  66. IO.write(file, "Suggestions:\n")
  67. for suggestion <- suggestions do
  68. print_suggestion(file, suggestion, true)
  69. end
  70. else
  71. IO.write(file, " Suggestion: ")
  72. print_suggestion(file, List.first(suggestions))
  73. end
  74. end
  75. end