2019-08-30 04:21:48 -06:00
defmodule Pleroma.Docs.Markdown do
2019-08-30 10:14:01 -06:00
@behaviour Pleroma.Docs.Generator
2019-08-30 04:21:48 -06:00
2019-08-30 10:14:01 -06:00
@spec process ( keyword ( ) ) :: { :ok , String . t ( ) }
2019-08-30 04:21:48 -06:00
def process ( descriptions ) do
config_path = " docs/config.md "
{ :ok , file } = File . open ( config_path , [ :write ] )
2019-08-30 10:14:01 -06:00
IO . write ( file , " # Configuration \r \n \r \n " )
2019-08-30 04:21:48 -06:00
IO . write ( file , " Date of generation: #{ Date . utc_today ( ) } \r \n \r \n " )
IO . write (
file ,
2019-08-30 10:14:01 -06:00
" This file describe the configuration, it is recommended to edit the relevant `*.secret.exs` file instead of the others founds in the ``config`` directory. \r \n
If you run Pleroma with ` ` MIX_ENV = prod ` ` the file is ` ` prod . secret . exs ` ` , otherwise it is ` ` dev . secret . exs ` ` . \ r \ n \ r \ n "
2019-08-30 04:21:48 -06:00
)
for group <- descriptions do
if is_nil ( group [ :key ] ) do
IO . write ( file , " # # #{ inspect ( group [ :group ] ) } \r \n \r \n " )
else
IO . write ( file , " # # #{ inspect ( group [ :key ] ) } \r \n \r \n " )
end
IO . write ( file , " #{ group [ :description ] } \r \n \r \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 , " \r \n " )
end
:ok = File . close ( file )
{ :ok , config_path }
end
2019-08-30 10:14:01 -06:00
defp print_suggestion ( file , suggestion ) when is_list ( suggestion ) do
IO . write ( file , " ` #{ inspect ( suggestion ) } ` \r \n " )
end
2019-08-30 04:21:48 -06:00
defp print_suggestion ( file , suggestion ) when is_function ( suggestion ) do
IO . write ( file , " ` #{ inspect ( suggestion . ( ) ) } ` \r \n " )
end
2019-08-30 10:14:01 -06:00
defp print_suggestion ( file , suggestion , as_list \\ false ) do
list_mark = if as_list , do : " * " , else : " "
IO . write ( file , " #{ list_mark } ` #{ inspect ( suggestion ) } ` \r \n " )
2019-08-30 04:21:48 -06:00
end
2019-08-30 10:14:01 -06:00
defp print_suggestions ( _file , nil ) , do : nil
2019-08-30 04:21:48 -06:00
defp print_suggestions ( file , suggestions ) do
2019-08-30 10:14:01 -06:00
IO . write ( file , " Suggestions: \r \n " )
2019-08-30 04:21:48 -06:00
2019-08-30 10:14:01 -06:00
if length ( suggestions ) > 1 do
for suggestion <- suggestions do
print_suggestion ( file , suggestion , true )
end
else
print_suggestion ( file , List . first ( suggestions ) )
2019-08-30 04:21:48 -06:00
end
end
defp print_child_header ( file , child ) do
2019-08-30 10:14:01 -06:00
IO . write ( file , " * ` #{ inspect ( child [ :key ] ) } ` \r \n " )
IO . write ( file , " #{ child [ :description ] } \r \n " )
IO . write ( file , " Type: ` #{ inspect ( child [ :type ] ) } ` \r \n " )
2019-08-30 04:21:48 -06:00
end
end