2022-07-30 12:42:09 +03:00
|
|
|
{utils}: let
|
2021-05-15 19:42:16 +03:00
|
|
|
inherit (utils) concatStrings mapAttrsToList genAttrs isAttrs isList range toString;
|
2021-05-15 02:30:42 +03:00
|
|
|
|
|
|
|
evalAttrs = attrs: concatStrings (mapAttrsToList (name: value: " ${name}=\"${value}\"") attrs);
|
2022-07-30 12:42:09 +03:00
|
|
|
evalChildren = children:
|
|
|
|
if isList children
|
|
|
|
then concatStrings children
|
|
|
|
else children;
|
2021-05-15 02:30:42 +03:00
|
|
|
tag = name: maybeAttrs:
|
|
|
|
if isAttrs maybeAttrs
|
2021-05-17 18:41:37 +03:00
|
|
|
then (children: "<${name}${evalAttrs maybeAttrs}>${evalChildren children}</${name}>")
|
2022-07-30 12:42:09 +03:00
|
|
|
else tag name {} maybeAttrs;
|
2021-05-15 21:52:25 +03:00
|
|
|
noChildrenTag = name: attrs: "<${name} ${evalAttrs attrs}>";
|
2021-05-15 02:30:42 +03:00
|
|
|
|
2022-07-30 12:42:09 +03:00
|
|
|
tagsToGen = ["html" "head" "body" "div" "p" "a" "title" "code" "pre" "nav" "article"] ++ (map (n: "h${toString n}") (range 1 6));
|
2021-05-15 19:42:16 +03:00
|
|
|
tags = genAttrs tag tagsToGen;
|
2021-05-15 21:52:25 +03:00
|
|
|
|
2022-07-30 12:42:09 +03:00
|
|
|
noChildrenTagsToGen = ["link" "meta"];
|
2021-05-15 21:52:25 +03:00
|
|
|
noChildrenTags = genAttrs noChildrenTag noChildrenTagsToGen;
|
2021-05-15 02:30:42 +03:00
|
|
|
in
|
2022-07-30 12:42:09 +03:00
|
|
|
tags
|
|
|
|
// noChildrenTags
|
|
|
|
// {
|
|
|
|
inherit tag;
|
|
|
|
mkLink = url: tags.a {href = url;};
|
|
|
|
mkStylesheet = url:
|
|
|
|
noChildrenTags.link {
|
|
|
|
rel = "stylesheet";
|
|
|
|
href = url;
|
|
|
|
};
|
|
|
|
}
|