Merge branch 'develop' of git.pleroma.social:pleroma/pleroma into stats-genserver-fix
[akkoma] / lib / pleroma / docs / json.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Docs.JSON do
6 @behaviour Pleroma.Docs.Generator
7 @external_resource "config/description.exs"
8 @raw_config Pleroma.Config.Loader.read("config/description.exs")
9 @raw_descriptions @raw_config[:pleroma][:config_description]
10 @term __MODULE__.Compiled
11
12 @spec compile :: :ok
13 def compile do
14 :persistent_term.put(@term, Pleroma.Docs.Generator.convert_to_strings(@raw_descriptions))
15 end
16
17 @spec compiled_descriptions :: Map.t()
18 def compiled_descriptions do
19 :persistent_term.get(@term)
20 end
21
22 @spec process(keyword()) :: {:ok, String.t()}
23 def process(descriptions) do
24 with path <- "docs/generated_config.json",
25 {:ok, file} <- File.open(path, [:write, :utf8]),
26 formatted_descriptions <-
27 Pleroma.Docs.Generator.convert_to_strings(descriptions),
28 json <- Jason.encode!(formatted_descriptions),
29 :ok <- IO.write(file, json),
30 :ok <- File.close(file) do
31 {:ok, path}
32 end
33 end
34 end