From b8d56a7c11ed8ecec44bdd2836a8754e3df804d2 Mon Sep 17 00:00:00 2001 From: Christophe Romain Date: Tue, 18 Jul 2017 15:01:01 +0200 Subject: [PATCH] Improve formatting of documented API parameters --- src/ejabberd_commands_doc.erl | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/ejabberd_commands_doc.erl b/src/ejabberd_commands_doc.erl index 46e7f5ccf..8cab8c107 100644 --- a/src/ejabberd_commands_doc.erl +++ b/src/ejabberd_commands_doc.erl @@ -87,9 +87,6 @@ md_tag(strong, V) -> md_tag(_, V) -> V. -unbinarize(binary) -> string; -unbinarize(Other) -> Other. - perl_gen({Name, integer}, Int, _Indent, HTMLOutput) -> [?ARG(Name), ?OP_L(" => "), ?NUM(Int)]; perl_gen({Name, string}, Str, _Indent, HTMLOutput) -> @@ -340,12 +337,26 @@ gen_calls(#ejabberd_commands{args_example=Values, args=ArgsDesc, end end. +format_type({list, {_, {tuple, Els}}}) -> + io_lib:format("[~s]", [format_type({tuple, Els})]); +format_type({list, El}) -> + io_lib:format("[~s]", [format_type(El)]); +format_type({tuple, Els}) -> + Args = [format_type(El) || El <- Els], + io_lib:format("{~s}", [lists:flatten(lists:join(", ", Args))]); +format_type({Name, Type}) -> + io_lib:format("~s::~s", [Name, format_type(Type)]); +format_type(binary) -> + "string"; +format_type(atom) -> + "string"; +format_type(Type) -> + io_lib:format("~p", [Type]). + gen_param(Name, Type, undefined, HTMLOutput) -> - [?TAG(li, [?TAG_R(strong, atom_to_list(Name)), <<" :: ">>, - ?RAW(io_lib:format("~p", [unbinarize(Type)]))])]; + [?TAG(li, [?TAG_R(strong, atom_to_list(Name)), <<" :: ">>, ?RAW(format_type(Type))])]; gen_param(Name, Type, Desc, HTMLOutput) -> - [?TAG(dt, [?TAG_R(strong, atom_to_list(Name)), <<" :: ">>, - ?RAW(io_lib:format("~p", [unbinarize(Type)]))]), + [?TAG(dt, [?TAG_R(strong, atom_to_list(Name)), <<" :: ">>, ?RAW(format_type(Type))]), ?TAG(dd, ?RAW(Desc))]. gen_doc(#ejabberd_commands{name=Name, tags=_Tags, desc=Desc, longdesc=LongDesc,