Merge remote-tracking branch 'upstream/develop' into restrict-domain
[akkoma] / lib / pleroma / docs / markdown.ex
index d7ca979572e0c57fee85f8a2feafd01815336d80..eac0789a6d4b53baebeeacecb967d8ac058586b7 100644 (file)
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
 defmodule Pleroma.Docs.Markdown do
   @behaviour Pleroma.Docs.Generator
 
@@ -23,7 +27,7 @@ defmodule Pleroma.Docs.Markdown do
 
       IO.write(file, "#{group[:description]}\n")
 
-      for child <- group[:children] do
+      for child <- group[:children] || [] do
         print_child_header(file, child)
 
         print_suggestions(file, child[:suggestions])
@@ -44,13 +48,17 @@ defmodule Pleroma.Docs.Markdown do
     {:ok, config_path}
   end
 
-  defp print_child_header(file, child) do
+  defp print_child_header(file, %{key: key, type: type, description: description} = _child) do
     IO.write(
       file,
-      "- `#{inspect(child[:key])}` (`#{inspect(child[:type])}`): #{child[:description]}\n"
+      "- `#{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
@@ -64,18 +72,25 @@ defmodule Pleroma.Docs.Markdown do
     IO.write(file, "  #{list_mark}`#{inspect(suggestion)}`\n")
   end
 
+  defp print_suggestions(file, {:list_behaviour_implementations, behaviour}) do
+    suggestions = Pleroma.Docs.Generator.list_behaviour_implementations(behaviour)
+    print_suggestions(file, suggestions)
+  end
+
   defp print_suggestions(_file, nil), do: nil
 
   defp print_suggestions(_file, ""), do: nil
 
   defp print_suggestions(file, suggestions) do
-    IO.write(file, "Suggestions:\n")
-
     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