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

This commit is contained in:
Mohammad Rafiq 2025-07-05 05:28:02 +08:00
parent a160c6d5dd
commit 5f1536d44b
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,10 +59,13 @@ let
] ]
(optional (value.description != "") value.description) (optional (value.description != "") value.description)
(map (mkListFromAttrs (prefix + 1)) ( (map (mkListFromAttrs (prefix + 1)) (
map (x: { if value.order == [ ] then
name = x; mapAttrsToList (name: value: { inherit name value; }) value.parts
value = flip getAttr value.parts x; else
}) value.order map (x: {
name = x;
value = flip getAttr value.parts x;
}) value.order
)) ))
]; ];
in in