WIP inheritance

This commit is contained in:
tristan 2024-01-01 03:20:59 +00:00
parent b734310051
commit 35b8cf7472
6 changed files with 169 additions and 84 deletions

View file

@ -1,7 +1,9 @@
let
keyvalue = key: value:
assert builtins.isString key;
if value == "" || value == [ ] || value == { } then
if builtins.isAttrs value then
builtins.trace "Skipping ${key} as it is a set" "" else
if value == "" || value == [ ] then
""
else
''${key}="${toString value}"'';
@ -26,11 +28,27 @@ in rec {
else
keyvalue key value) attrs)));
tag = tag: attrs: child: {
inherit tag attrs child;
__toString = toHTML;
tag = tag: {
inherit tag;
__functor = self: attrs:
if !(builtins.isAttrs attrs) then
throw "HTML tag requires attribute set"
else {
inherit attrs;
__functor = self: child:
if !(isTag child) then
throw "tag child must be tag, list, or string"
else {
inherit tag attrs child;
__toString = toHTML;
};
};
};
isTag = tag:
(builtins.isString tag || builtins.isList tag
|| (tag ? toString && builtins.isFunction tag.toString));
addToHead = page: heads:
page // {
child = map