alejandra
This commit is contained in:
parent
b1426fb1ca
commit
dc33fdf093
14 changed files with 1029 additions and 976 deletions
|
@ -1,70 +1,78 @@
|
|||
let
|
||||
keyvalue = key: value:
|
||||
assert builtins.isString key;
|
||||
if builtins.isAttrs value then
|
||||
builtins.trace "Skipping ${key} as it is a set" ""
|
||||
else if value == "" || value == [ ] || value == false then
|
||||
""
|
||||
else if value == true then
|
||||
key
|
||||
else
|
||||
''${key}="${toString value}"'';
|
||||
if builtins.isAttrs value
|
||||
then builtins.trace "Skipping ${key} as it is a set" ""
|
||||
else if value == "" || value == [] || value == false
|
||||
then ""
|
||||
else if value == true
|
||||
then key
|
||||
else ''${key}="${toString value}"'';
|
||||
in rec {
|
||||
toHTML = elem:
|
||||
if builtins.isString elem then
|
||||
elem
|
||||
else if builtins.isList elem then
|
||||
builtins.toString (map toHTML elem)
|
||||
else
|
||||
"<${elem.tag} ${writeAttrs elem.attrs or { }}>${
|
||||
toHTML elem.child or ""
|
||||
}</${elem.tag}>";
|
||||
if builtins.isString elem
|
||||
then elem
|
||||
else if builtins.isList elem
|
||||
then builtins.toString (map toHTML elem)
|
||||
else "<${elem.tag} ${writeAttrs elem.attrs or {}}>${
|
||||
toHTML elem.child or ""
|
||||
}</${elem.tag}>";
|
||||
|
||||
writeAttrs = attrs:
|
||||
toString (builtins.filter (value: value != "") (builtins.attrValues
|
||||
(builtins.mapAttrs (key: value:
|
||||
if (builtins.isPath value) then
|
||||
keyvalue key (baseNameOf value)
|
||||
else if (builtins.substring 0 2 key) == "__" then
|
||||
""
|
||||
else
|
||||
keyvalue key value) attrs)));
|
||||
if (builtins.isPath value)
|
||||
then keyvalue key (baseNameOf value)
|
||||
else if (builtins.substring 0 2 key) == "__"
|
||||
then ""
|
||||
else keyvalue key value)
|
||||
attrs)));
|
||||
|
||||
tag = t:
|
||||
({
|
||||
tag = t: ({
|
||||
tag = t;
|
||||
attrs = { };
|
||||
} // baseTag);
|
||||
attrs = {};
|
||||
}
|
||||
// baseTag);
|
||||
|
||||
baseTag = {
|
||||
__toString = self: toString (self "");
|
||||
__functor = self: child:
|
||||
(if !(isTag child) then
|
||||
(if isSet child then
|
||||
incorporateAttrs self child
|
||||
else
|
||||
throw "tag child must be tag, list, or string, got ${
|
||||
builtins.typeOf child
|
||||
}")
|
||||
__functor = self: child: (
|
||||
if !(isTag child)
|
||||
then
|
||||
(
|
||||
if isSet child
|
||||
then incorporateAttrs self child
|
||||
else
|
||||
throw "tag child must be tag, list, or string, got ${
|
||||
builtins.typeOf child
|
||||
}"
|
||||
)
|
||||
else
|
||||
self // {
|
||||
self
|
||||
// {
|
||||
inherit child;
|
||||
__toString = toHTML;
|
||||
});
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
incorporateAttrs = self: attrs: self // ({ attrs = self.attrs // attrs; });
|
||||
incorporateAttrs = self: attrs: self // {attrs = self.attrs // attrs;};
|
||||
|
||||
isSet = a: builtins.isAttrs a && !a ? __toString;
|
||||
|
||||
isTag = tag:
|
||||
(builtins.isString tag || builtins.isList tag
|
||||
|| (tag ? __toString && builtins.isFunction tag.__toString));
|
||||
isTag = tag: (builtins.isString tag
|
||||
|| builtins.isList tag
|
||||
|| (tag ? __toString && builtins.isFunction tag.__toString));
|
||||
|
||||
addToHead = page: heads:
|
||||
page // {
|
||||
child = map
|
||||
(e: if e.tag == "head" then e // { child = e.child ++ heads; } else e)
|
||||
page
|
||||
// {
|
||||
child =
|
||||
map
|
||||
(e:
|
||||
if e.tag == "head"
|
||||
then e // {child = e.child ++ heads;}
|
||||
else e)
|
||||
page.child;
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue