html.nix/tags.nix

18 lines
606 B
Nix
Raw Normal View History

2021-05-15 02:30:42 +03:00
{ format ? false, lib ? import ./lib.nix }:
with lib; let
fmt = if format then "\n " else "";
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
then (children: "<${name}${evalAttrs maybeAttrs}>${fmt}${evalChildren children}${fmt}</${name}>")
else tag name { } maybeAttrs;
tags = (genAttrs tag [ "html" "head" "body" "div" "p" "a" ]);
in
tags // {
inherit tag;
link = url: tags.a { href = url; };
}