forked from lix-project/lix
refactor rendering documentation of options
this makes more obvious what the code produces, and the structure of the output easier to change
This commit is contained in:
parent
16b03f03af
commit
dfa27e6b2f
|
@ -1,29 +1,41 @@
|
||||||
with builtins;
|
let
|
||||||
with import ./utils.nix;
|
inherit (builtins) attrNames concatStringsSep isAttrs isBool;
|
||||||
|
inherit (import ./utils.nix) concatStrings squash splitLines;
|
||||||
|
in
|
||||||
|
|
||||||
options:
|
optionsInfo:
|
||||||
|
let
|
||||||
|
showOption = name:
|
||||||
|
let
|
||||||
|
inherit (optionsInfo.${name}) description documentDefault defaultValue aliases;
|
||||||
|
result = squash ''
|
||||||
|
- [`${name}`]{#conf-${name}}
|
||||||
|
|
||||||
concatStrings (map
|
${indent " " body}
|
||||||
(name:
|
'';
|
||||||
let option = options.${name}; in
|
# separate body to cleanly handle indentation
|
||||||
" - [`${name}`](#conf-${name})"
|
body = ''
|
||||||
+ "<p id=\"conf-${name}\"></p>\n\n"
|
${description}
|
||||||
+ concatStrings (map (s: " ${s}\n") (splitLines option.description)) + "\n\n"
|
|
||||||
+ (if option.documentDefault
|
**Default:** ${showDefault documentDefault defaultValue}
|
||||||
then " **Default:** " + (
|
|
||||||
if option.defaultValue == "" || option.defaultValue == []
|
${showAliases aliases}
|
||||||
then "*empty*"
|
'';
|
||||||
else if isBool option.defaultValue
|
showDefault = documentDefault: defaultValue:
|
||||||
then (if option.defaultValue then "`true`" else "`false`")
|
if documentDefault then
|
||||||
else
|
# a StringMap value type is specified as a string, but
|
||||||
# n.b. a StringMap value type is specified as a string, but
|
# this shows the value type. The empty stringmap is `null` in
|
||||||
# this shows the value type. The empty stringmap is "null" in
|
# JSON, but that converts to `{ }` here.
|
||||||
# JSON, but that converts to "{ }" here.
|
if defaultValue == "" || defaultValue == [] || isAttrs defaultValue
|
||||||
(if isAttrs option.defaultValue then "`\"\"`"
|
then "*empty*"
|
||||||
else "`" + toString option.defaultValue + "`")) + "\n\n"
|
else if isBool defaultValue then
|
||||||
else " **Default:** *machine-specific*\n")
|
if defaultValue then "`true`" else "`false`"
|
||||||
+ (if option.aliases != []
|
else "`${toString defaultValue}`"
|
||||||
then " **Deprecated alias:** " + (concatStringsSep ", " (map (s: "`${s}`") option.aliases)) + "\n\n"
|
else "*machine-specific*";
|
||||||
else "")
|
showAliases = aliases:
|
||||||
)
|
if aliases == [] then "" else
|
||||||
(attrNames options))
|
"**Deprecated alias:** ${(concatStringsSep ", " (map (s: "`${s}`") aliases))}";
|
||||||
|
indent = prefix: s:
|
||||||
|
concatStringsSep "\n" (map (x: if x == "" then x else "${prefix}${x}") (splitLines s));
|
||||||
|
in result;
|
||||||
|
in concatStrings (map showOption (attrNames optionsInfo))
|
||||||
|
|
Loading…
Reference in a new issue