]> granicus.if.org Git - ejabberd/commitdiff
Improve formatting of documented API parameters
authorChristophe Romain <christophe.romain@process-one.net>
Tue, 18 Jul 2017 13:01:01 +0000 (15:01 +0200)
committerChristophe Romain <christophe.romain@process-one.net>
Tue, 18 Jul 2017 13:01:01 +0000 (15:01 +0200)
src/ejabberd_commands_doc.erl

index 46e7f5ccf0df861b3a86b1dfd80957bcfbc1d55d..8cab8c1076bce46215dbc9221dfa6f8573ffae18 100644 (file)
@@ -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,