html.nix/css.nix

44 lines
855 B
Nix
Raw Normal View History

2023-04-06 01:43:12 +03:00
{lib, ...}: let
l = lib // builtins;
t = l.types;
2021-05-16 02:56:54 +03:00
2022-07-30 12:42:09 +03:00
evalCssValue = value:
2023-04-06 01:43:12 +03:00
if l.isList value
then l.concatStringsSep ", " (l.map toString value)
else l.toString value;
evalInner = inner:
l.concatStringsSep
" "
(
l.mapAttrsToList
(name: value: "${name}: ${evalCssValue value};")
inner
);
eval = maybeAttrs:
if l.isList maybeAttrs
then l.concatStringsSep " " maybeAttrs
else
l.concatStringsSep
" "
(
l.mapAttrsToList
(name: inner: "${name} { ${evalInner inner} }")
maybeAttrs
);
css = {
__functor = self: arg: eval arg;
media = rule: inner: ''
@media (${rule}) { ${eval inner} }
'';
};
2022-07-30 12:42:09 +03:00
in {
2023-04-06 01:43:12 +03:00
options = {
html-nix.lib.css = l.mkOption {
2023-04-06 05:43:25 +03:00
type = t.raw;
2023-04-06 01:43:12 +03:00
};
};
config = {
html-nix.lib.css = css;
};
2021-05-16 02:56:54 +03:00
}