2021-05-15 19:42:16 +03:00
|
|
|
{ utils }:
|
2021-05-15 02:51:50 +03:00
|
|
|
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);
|
|
|
|
evalChildren = children: if isList children then concatStrings children else children;
|
|
|
|
tag = name: maybeAttrs:
|
|
|
|
if isAttrs maybeAttrs
|
2021-05-15 19:42:16 +03:00
|
|
|
then (children: "<${name}${evalAttrs maybeAttrs}>\n ${evalChildren children}\n</${name}>\n")
|
2021-05-15 02:30:42 +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
|
|
|
|
2021-05-15 21:52:25 +03:00
|
|
|
tagsToGen = [ "html" "head" "body" "div" "p" "a" "title" "code" "pre" ] ++ (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
|
|
|
|
|
|
|
noChildrenTagsToGen = [ "link" "meta" ];
|
|
|
|
noChildrenTags = genAttrs noChildrenTag noChildrenTagsToGen;
|
2021-05-15 02:30:42 +03:00
|
|
|
in
|
2021-05-15 21:52:25 +03:00
|
|
|
tags // noChildrenTags // {
|
2021-05-15 02:30:42 +03:00
|
|
|
inherit tag;
|
2021-05-15 21:29:30 +03:00
|
|
|
mkLink = url: tags.a { href = url; };
|
2021-05-15 21:52:25 +03:00
|
|
|
mkStylesheet = url: noChildrenTags.link { rel = "stylesheet"; href = url; };
|
2021-05-15 02:30:42 +03:00
|
|
|
}
|