diff options
author | Pouriya <pouriya.jahanbakhsh@gmail.com> | 2021-09-18 16:09:11 +0430 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-18 16:09:11 +0430 |
commit | 3eb795357ff2278fa641608f442c9800d74c9c0a (patch) | |
tree | 9592f786ad76e91b442fcf9a83cdd609ede3a9c2 /src/ejabberd_commands_doc.erl | |
parent | ref: fix WS typos (diff) | |
parent | Fix previous commit: add forgotten endline blankspaces (diff) |
Merge branch 'processone:master' into master
Diffstat (limited to 'src/ejabberd_commands_doc.erl')
-rw-r--r-- | src/ejabberd_commands_doc.erl | 45 |
1 files changed, 39 insertions, 6 deletions
diff --git a/src/ejabberd_commands_doc.erl b/src/ejabberd_commands_doc.erl index 4981577b6..eec334d04 100644 --- a/src/ejabberd_commands_doc.erl +++ b/src/ejabberd_commands_doc.erl @@ -28,6 +28,7 @@ -export([generate_html_output/3]). -export([generate_md_output/3]). +-export([generate_tags_md/1]). -include("ejabberd_commands.hrl"). @@ -360,8 +361,16 @@ gen_param(Name, Type, Desc, HTMLOutput) -> [?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, - args=Args, args_desc=ArgsDesc, note=Note, +make_tags(HTMLOutput) -> + TagsList = ejabberd_commands:get_tags_commands(1000000), + lists:map(fun(T) -> gen_tags(T, HTMLOutput) end, TagsList). + +-dialyzer({no_match, gen_tags/2}). +gen_tags({TagName, Commands}, HTMLOutput) -> + [?TAG(h1, TagName) | [?TAG(p, ?RAW("* *`"++C++"`*")) || C <- Commands]]. + +gen_doc(#ejabberd_commands{name=Name, tags=Tags, desc=Desc, longdesc=LongDesc, + args=Args, args_desc=ArgsDesc, note=Note, definer=Definer, result=Result, result_desc=ResultDesc}=Cmd, HTMLOutput, Langs) -> try ArgsText = case ArgsDesc of @@ -389,6 +398,17 @@ gen_doc(#ejabberd_commands{name=Name, tags=_Tags, desc=Desc, longdesc=LongDesc, [?TAG(dl, [gen_param(RName, Type, ResultDesc, HTMLOutput)])] end end, + TagsText = [?RAW("*`"++atom_to_list(Tag)++"`* ") || Tag <- Tags], + IsDefinerMod = case Definer of + unknown -> true; + _ -> lists:member(gen_mod, proplists:get_value(behaviour, Definer:module_info(attributes))) + end, + ModuleText = case IsDefinerMod of + true -> + [?TAG(h2, <<"Module:">>), ?TAG(p, ?RAW("*`"++atom_to_list(Definer)++"`*"))]; + false -> + [] + end, NoteEl = case Note of "" -> []; _ -> ?TAG('div', "note-down", ?RAW(Note)) @@ -403,6 +423,8 @@ gen_doc(#ejabberd_commands{name=Name, tags=_Tags, desc=Desc, longdesc=LongDesc, end, ?TAG(h2, <<"Arguments:">>), ArgsText, ?TAG(h2, <<"Result:">>), ResultText, + ?TAG(h2, <<"Tags:">>), ?TAG(p, TagsText)] + ++ ModuleText ++ [ ?TAG(h2, <<"Examples:">>), gen_calls(Cmd, HTMLOutput, Langs)] catch _:Ex -> @@ -421,12 +443,13 @@ find_commands_definitions() -> lists:flatmap(fun(P) -> Mod = list_to_atom(filename:rootname(P)), code:ensure_loaded(Mod), - case erlang:function_exported(Mod, get_commands_spec, 0) of + Cs = case erlang:function_exported(Mod, get_commands_spec, 0) of true -> apply(Mod, get_commands_spec, []); _ -> [] - end + end, + [C#ejabberd_commands{definer = Mod} || C <- Cs] end, filelib:wildcard("*.beam", Path)) end. @@ -466,15 +489,25 @@ generate_md_output(File, RegExp, Languages) -> end, Cmds2), Cmds4 = [maybe_add_policy_arguments(Cmd) || Cmd <- Cmds3], Langs = binary:split(Languages, <<",">>, [global]), - Header = <<"---\ntitle: Administration API reference\ntoc: true\nmenu: Administration API\norder: 40\n" + Header = <<"---\ntitle: Administration API reference\ntoc: true\nmenu: API Reference\norder: 1\n" "// Autogenerated with 'ejabberdctl gen_markdown_doc_for_commands'\n---\n\n" - "This section describes API of ejabberd.">>, + "This section describes API of ejabberd.\n">>, Out = lists:map(fun(C) -> gen_doc(C, false, Langs) end, Cmds4), {ok, Fh} = file:open(File, [write]), io:format(Fh, "~ts~ts", [Header, Out]), file:close(Fh), ok. +generate_tags_md(File) -> + Header = <<"---\ntitle: API Tags\ntoc: true\nmenu: API Tags\norder: 2\n" + "// Autogenerated with 'ejabberdctl gen_markdown_doc_for_tags'\n---\n\n" + "This section enumerates the tags and their associated API.\n">>, + Tags = make_tags(false), + {ok, Fh} = file:open(File, [write]), + io:format(Fh, "~ts~ts", [Header, Tags]), + file:close(Fh), + ok. + html_pre() -> "<!DOCTYPE> <html> |