mirror of
https://github.com/nix-community/nixvim.git
synced 2025-12-18 06:51:12 +01:00
docs/lib: generalise menu impl using module system
Move the mdbook menu rendering code into the module system and generalise it to apply to multiple "categories" (mdbook parts) and "types" of category (prefix, suffix, etc).
This commit is contained in:
parent
2f952af4a7
commit
4f03ca05d9
8 changed files with 228 additions and 60 deletions
43
docs/modules/menu.nix
Normal file
43
docs/modules/menu.nix
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
{
|
||||
lib,
|
||||
config,
|
||||
options,
|
||||
...
|
||||
}:
|
||||
let
|
||||
categoryType = lib.types.submoduleWith {
|
||||
modules = [ ./category.nix ];
|
||||
};
|
||||
|
||||
categories = builtins.removeAttrs config (builtins.attrNames options);
|
||||
in
|
||||
{
|
||||
freeformType = lib.types.attrsOf categoryType;
|
||||
|
||||
options._menu = {
|
||||
text = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
description = "The rendered menu.";
|
||||
readOnly = true;
|
||||
};
|
||||
};
|
||||
|
||||
config._menu = {
|
||||
text = lib.pipe categories [
|
||||
builtins.attrValues
|
||||
(map (x: x._category))
|
||||
(lib.sortOn (x: x.order))
|
||||
(builtins.groupBy (x: x.type))
|
||||
(
|
||||
{
|
||||
prefix ? [ ],
|
||||
normal ? [ ],
|
||||
suffix ? [ ],
|
||||
}:
|
||||
prefix ++ normal ++ suffix
|
||||
)
|
||||
(map (x: x.text))
|
||||
(builtins.concatStringsSep "\n\n")
|
||||
];
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue