aboutsummaryrefslogtreecommitdiff
path: root/lib/pleroma/docs/markdown.ex
diff options
context:
space:
mode:
authorkPherox <admin@mail.kr-kp.com>2019-10-01 01:39:22 +0900
committerkPherox <admin@mail.kr-kp.com>2019-10-01 01:40:33 +0900
commita0f101ee806af06bcd4271cd8d57d11ff85ea11a (patch)
tree2cd3c5d1a645be1395c57ec5616f31afb4b68da7 /lib/pleroma/docs/markdown.ex
parent8ca4f145a51e92c9f3a6c374ceddfac22ea300d9 (diff)
parent7c9b023a918c84b60ae6547289a083c671a3659b (diff)
downloadpleroma-a0f101ee806af06bcd4271cd8d57d11ff85ea11a.tar.gz
Merge remote-tracking branch 'upstream/develop' into fix-prameter-name-of-accounts-update-credentials
Diffstat (limited to 'lib/pleroma/docs/markdown.ex')
-rw-r--r--lib/pleroma/docs/markdown.ex88
1 files changed, 88 insertions, 0 deletions
diff --git a/lib/pleroma/docs/markdown.ex b/lib/pleroma/docs/markdown.ex
new file mode 100644
index 000000000..68b106499
--- /dev/null
+++ b/lib/pleroma/docs/markdown.ex
@@ -0,0 +1,88 @@
+defmodule Pleroma.Docs.Markdown do
+ @behaviour Pleroma.Docs.Generator
+
+ @spec process(keyword()) :: {:ok, String.t()}
+ def process(descriptions) do
+ config_path = "docs/generated_config.md"
+ {:ok, file} = File.open(config_path, [:utf8, :write])
+ IO.write(file, "# Generated configuration\n")
+ IO.write(file, "Date of generation: #{Date.utc_today()}\n\n")
+
+ IO.write(
+ file,
+ "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" <>
+ "If you run Pleroma with ``MIX_ENV=prod`` the file is ``prod.secret.exs``, otherwise it is ``dev.secret.exs``.\n\n"
+ )
+
+ for group <- descriptions do
+ if is_nil(group[:key]) do
+ IO.write(file, "## #{inspect(group[:group])}\n")
+ else
+ IO.write(file, "## #{inspect(group[:key])}\n")
+ end
+
+ IO.write(file, "#{group[:description]}\n")
+
+ for child <- group[:children] || [] do
+ print_child_header(file, child)
+
+ print_suggestions(file, child[:suggestions])
+
+ if child[:children] do
+ for subchild <- child[:children] do
+ print_child_header(file, subchild)
+
+ print_suggestions(file, subchild[:suggestions])
+ end
+ end
+ end
+
+ IO.write(file, "\n")
+ end
+
+ :ok = File.close(file)
+ {:ok, config_path}
+ end
+
+ defp print_child_header(file, %{key: key, type: type, description: description} = _child) do
+ IO.write(
+ file,
+ "- `#{inspect(key)}` (`#{inspect(type)}`): #{description} \n"
+ )
+ end
+
+ defp print_child_header(file, %{key: key, type: type} = _child) do
+ IO.write(file, "- `#{inspect(key)}` (`#{inspect(type)}`) \n")
+ end
+
+ defp print_suggestion(file, suggestion) when is_list(suggestion) do
+ IO.write(file, " `#{inspect(suggestion)}`\n")
+ end
+
+ defp print_suggestion(file, suggestion) when is_function(suggestion) do
+ IO.write(file, " `#{inspect(suggestion.())}`\n")
+ end
+
+ defp print_suggestion(file, suggestion, as_list \\ false) do
+ list_mark = if as_list, do: "- ", else: ""
+ IO.write(file, " #{list_mark}`#{inspect(suggestion)}`\n")
+ end
+
+ defp print_suggestions(_file, nil), do: nil
+
+ defp print_suggestions(_file, ""), do: nil
+
+ defp print_suggestions(file, suggestions) do
+ if length(suggestions) > 1 do
+ IO.write(file, "Suggestions:\n")
+
+ for suggestion <- suggestions do
+ print_suggestion(file, suggestion, true)
+ end
+ else
+ IO.write(file, " Suggestion: ")
+
+ print_suggestion(file, List.first(suggestions))
+ end
+ end
+end