feat(helpers/text): add support for unordered parts

This commit is contained in:
Mohammad Rafiq 2025-07-05 05:28:02 +08:00
parent 2c77ff76ba
commit 9420f4b84c
No known key found for this signature in database

View file

@ -1,6 +1,7 @@
{ lib, ... }: { lib, ... }:
let let
inherit (lib) inherit (lib)
mapAttrsToList
optional optional
concatStrings concatStrings
flatten flatten
@ -31,7 +32,10 @@ let
type = str; type = str;
default = ""; default = "";
}; };
order = mkOption { type = listOf str; }; order = mkOption {
type = listOf str;
default = [ ];
};
parts = mkOption { type = lazyAttrsOf textType; }; parts = mkOption { type = lazyAttrsOf textType; };
}; };
}) })
@ -55,6 +59,9 @@ let
] ]
(optional (value.description != "") value.description) (optional (value.description != "") value.description)
(map (mkListFromAttrs (prefix + 1)) ( (map (mkListFromAttrs (prefix + 1)) (
if value.order == [ ] then
mapAttrsToList (name: value: { inherit name value; }) value.parts
else
map (x: { map (x: {
name = x; name = x;
value = flip getAttr value.parts x; value = flip getAttr value.parts x;