html.nix/tags.nix

19 lines
701 B
Nix
Raw Normal View History

2021-05-15 19:42:16 +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);
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 19:42:16 +03:00
tagsToGen = [ "html" "head" "body" "div" "p" "a" "title" "meta" "code" "pre" ] ++ (map (n: "h${toString n}") (range 1 6));
tags = genAttrs tag tagsToGen;
2021-05-15 02:30:42 +03:00
in
tags // {
inherit tag;
link = url: tags.a { href = url; };
}