logo

pleroma

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

json.ex (1293B)


  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.JSON do
  5. @behaviour Pleroma.Docs.Generator
  6. @external_resource "config/description.exs"
  7. @raw_config Pleroma.Config.Loader.read("config/description.exs")
  8. @raw_descriptions @raw_config[:pleroma][:config_description]
  9. @term __MODULE__.Compiled
  10. @spec compile :: :ok
  11. def compile do
  12. descriptions =
  13. Pleroma.Web.ActivityPub.MRF.config_descriptions()
  14. |> Enum.reduce(@raw_descriptions, fn description, acc -> [description | acc] end)
  15. :persistent_term.put(@term, Pleroma.Docs.Generator.convert_to_strings(descriptions))
  16. end
  17. @spec compiled_descriptions :: map()
  18. def compiled_descriptions do
  19. :persistent_term.get(@term)
  20. end
  21. @spec process(keyword()) :: {:ok, String.t()}
  22. def process(descriptions) do
  23. with path <- "docs/generated_config.json",
  24. {:ok, file} <- File.open(path, [:write, :utf8]),
  25. formatted_descriptions <-
  26. Pleroma.Docs.Generator.convert_to_strings(descriptions),
  27. json <- Jason.encode!(formatted_descriptions),
  28. :ok <- IO.write(file, json),
  29. :ok <- File.close(file) do
  30. {:ok, path}
  31. end
  32. end
  33. end