reusable, extendable tags
This commit is contained in:
parent
8e97ebe2ce
commit
e76305f71a
9 changed files with 85 additions and 76 deletions
|
@ -28,27 +28,29 @@ in rec {
|
|||
else
|
||||
keyvalue key value) attrs)));
|
||||
|
||||
tag = tag: {
|
||||
inherit tag;
|
||||
__toString = self: toString (self { } "");
|
||||
__functor = self: attrs:
|
||||
if !(builtins.isAttrs attrs) then
|
||||
throw "HTML tag requires attribute set"
|
||||
tag = t: {
|
||||
tag = t;
|
||||
attrs = {};
|
||||
__toString = self: toString (self "");
|
||||
__functor = self: child:
|
||||
(if !(isTag child) then
|
||||
(if isSet child then
|
||||
self // ({attrs = self.attrs // child;})
|
||||
else
|
||||
throw "tag child must be tag, list, or string, got ${
|
||||
builtins.typeOf child
|
||||
}"
|
||||
)
|
||||
else {
|
||||
inherit tag attrs;
|
||||
__toString = self: toString (self "");
|
||||
__functor = self: child:
|
||||
if !(isTag child) then
|
||||
throw "tag child must be tag, list, or string, got ${
|
||||
builtins.typeOf child
|
||||
}"
|
||||
else {
|
||||
inherit tag attrs child;
|
||||
__toString = toHTML;
|
||||
};
|
||||
};
|
||||
tag = t;
|
||||
attrs = self.attrs;
|
||||
inherit child;
|
||||
__toString = toHTML;
|
||||
});
|
||||
};
|
||||
|
||||
isSet = a: builtins.isAttrs a && !a ? __toString;
|
||||
|
||||
isTag = tag:
|
||||
(builtins.isString tag || builtins.isList tag
|
||||
|| (tag ? __toString && builtins.isFunction tag.__toString));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue