forked from lix-project/lix
doc rendering: add functions to scope explicitly (#7378)
* doc rendering: add functions to scope explicitly this especially helps beginners with code readability, since the origin of names is always immediately visible.
This commit is contained in:
parent
1540ab7628
commit
5d78dc4176
|
@ -1,8 +1,12 @@
|
||||||
builtinsDump:
|
let
|
||||||
|
inherit (builtins) concatStringsSep attrNames;
|
||||||
|
in
|
||||||
|
|
||||||
|
builtinsInfo:
|
||||||
let
|
let
|
||||||
showBuiltin = name:
|
showBuiltin = name:
|
||||||
let
|
let
|
||||||
inherit (builtinsDump.${name}) doc args;
|
inherit (builtinsInfo.${name}) doc args;
|
||||||
in
|
in
|
||||||
''
|
''
|
||||||
<dt id="builtins-${name}">
|
<dt id="builtins-${name}">
|
||||||
|
@ -14,7 +18,7 @@ let
|
||||||
|
|
||||||
</dd>
|
</dd>
|
||||||
'';
|
'';
|
||||||
listArgs = args: builtins.concatStringsSep " " (map (s: "<var>${s}</var>") args);
|
listArgs = args: concatStringsSep " " (map (s: "<var>${s}</var>") args);
|
||||||
in
|
in
|
||||||
with builtins; concatStringsSep "\n" (map showBuiltin (attrNames builtinsDump))
|
concatStringsSep "\n" (map showBuiltin (attrNames builtinsInfo))
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,16 @@
|
||||||
cliDumpStr:
|
let
|
||||||
|
inherit (builtins)
|
||||||
|
attrNames attrValues fromJSON listToAttrs mapAttrs
|
||||||
|
concatStringsSep concatMap length lessThan replaceStrings sort;
|
||||||
|
inherit (import ./utils.nix) concatStrings optionalString filterAttrs trim squash unique showSettings;
|
||||||
|
in
|
||||||
|
|
||||||
with builtins;
|
commandDump:
|
||||||
with import ./utils.nix;
|
|
||||||
|
|
||||||
let
|
let
|
||||||
|
|
||||||
|
commandInfo = fromJSON commandDump;
|
||||||
|
|
||||||
showCommand = { command, details, filename, toplevel }:
|
showCommand = { command, details, filename, toplevel }:
|
||||||
let
|
let
|
||||||
|
|
||||||
|
@ -96,7 +102,7 @@ let
|
||||||
|
|
||||||
${option.description}
|
${option.description}
|
||||||
'';
|
'';
|
||||||
categories = sort builtins.lessThan (unique (map (cmd: cmd.category) (attrValues allOptions)));
|
categories = sort lessThan (unique (map (cmd: cmd.category) (attrValues allOptions)));
|
||||||
in concatStrings (map showCategory categories);
|
in concatStrings (map showCategory categories);
|
||||||
in squash result;
|
in squash result;
|
||||||
|
|
||||||
|
@ -117,13 +123,11 @@ let
|
||||||
};
|
};
|
||||||
in [ cmd ] ++ concatMap subcommand (attrNames details.commands or {});
|
in [ cmd ] ++ concatMap subcommand (attrNames details.commands or {});
|
||||||
|
|
||||||
cliDump = builtins.fromJSON cliDumpStr;
|
|
||||||
|
|
||||||
manpages = processCommand {
|
manpages = processCommand {
|
||||||
command = "nix";
|
command = "nix";
|
||||||
details = cliDump.args;
|
details = commandInfo.args;
|
||||||
filename = "nix";
|
filename = "nix";
|
||||||
toplevel = cliDump.args;
|
toplevel = commandInfo.args;
|
||||||
};
|
};
|
||||||
|
|
||||||
tableOfContents = let
|
tableOfContents = let
|
||||||
|
@ -143,6 +147,6 @@ let
|
||||||
|
|
||||||
${showSettings { useAnchors = false; } settings}
|
${showSettings { useAnchors = false; } settings}
|
||||||
'';
|
'';
|
||||||
in concatStrings (attrValues (mapAttrs showStore cliDump.stores));
|
in concatStrings (attrValues (mapAttrs showStore commandInfo.stores));
|
||||||
|
|
||||||
in (listToAttrs manpages) // { "SUMMARY.md" = tableOfContents; }
|
in (listToAttrs manpages) // { "SUMMARY.md" = tableOfContents; }
|
||||||
|
|
Loading…
Reference in a new issue