From 999d0af502f37232ba9c9b3ed09855a89c9cc097 Mon Sep 17 00:00:00 2001 From: Badlop Date: Wed, 5 May 2021 11:41:06 +0200 Subject: [PATCH] New 'note' field in commands and options documentation --- include/ejabberd_commands.hrl | 1 + src/ejabberd_commands_doc.erl | 11 +++++++++-- src/ejabberd_doc.erl | 4 ++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/include/ejabberd_commands.hrl b/include/ejabberd_commands.hrl index 5d565193a..bfef47080 100644 --- a/include/ejabberd_commands.hrl +++ b/include/ejabberd_commands.hrl @@ -51,6 +51,7 @@ desc = "" :: string() | '_' | '$3', longdesc = "" :: string() | '_', version = 0 :: integer(), + note = "" :: string(), weight = 1 :: integer(), module :: atom() | '_', function :: atom() | '_', diff --git a/src/ejabberd_commands_doc.erl b/src/ejabberd_commands_doc.erl index 49fb27aee..ffc8ff597 100644 --- a/src/ejabberd_commands_doc.erl +++ b/src/ejabberd_commands_doc.erl @@ -83,6 +83,8 @@ md_tag(h2, V) -> [<<"\n__">>, V, <<"__\n\n">>]; md_tag(strong, V) -> [<<"*">>, V, <<"*">>]; +md_tag('div', V) -> + [<<"
">>, V, <<"
">>]; md_tag(_, V) -> V. @@ -359,7 +361,7 @@ gen_param(Name, Type, Desc, HTMLOutput) -> ?TAG(dd, ?RAW(Desc))]. gen_doc(#ejabberd_commands{name=Name, tags=_Tags, desc=Desc, longdesc=LongDesc, - args=Args, args_desc=ArgsDesc, + args=Args, args_desc=ArgsDesc, note=Note, result=Result, result_desc=ResultDesc}=Cmd, HTMLOutput, Langs) -> try ArgsText = case ArgsDesc of @@ -387,8 +389,13 @@ gen_doc(#ejabberd_commands{name=Name, tags=_Tags, desc=Desc, longdesc=LongDesc, [?TAG(dl, [gen_param(RName, Type, ResultDesc, HTMLOutput)])] end end, + NoteEl = case Note of + "" -> []; + _ -> ?TAG('div', "note-down", ?RAW(Note)) + end, - [?TAG(h1, atom_to_list(Name)), + [NoteEl, + ?TAG(h1, atom_to_list(Name)), ?TAG(p, ?RAW(Desc)), case LongDesc of "" -> []; diff --git a/src/ejabberd_doc.erl b/src/ejabberd_doc.erl index 89f1be11b..77f9fab48 100644 --- a/src/ejabberd_doc.erl +++ b/src/ejabberd_doc.erl @@ -159,6 +159,10 @@ opt_to_man(Lang, {Option, Options, Children}, Level) -> lists:keysort(1, Children))]) ++ [io_lib:nl()|format_example(Level, Lang, Options)]. +format_option(Lang, Option, #{note := Note, value := Val}) -> + "\n\n_Note_ about the next option: " ++ Note ++ ":\n\n"++ + "*" ++ atom_to_list(Option) ++ "*: 'pass:[" ++ + tr(Lang, Val) ++ "]'::"; format_option(Lang, Option, #{value := Val}) -> "*" ++ atom_to_list(Option) ++ "*: 'pass:[" ++ tr(Lang, Val) ++ "]'::";