chore: init

This commit is contained in:
dusk 2021-05-15 02:30:42 +03:00
commit d7671bf1ba
Signed by: dusk
GPG Key ID: 1D8F8FAF2294D6EA
3 changed files with 44 additions and 0 deletions

19
flake.nix Normal file
View File

@ -0,0 +1,19 @@
{
inputs = { };
outputs = { self }:
let
tagsPath = ./tags.nix;
libPath = ./lib.nix;
lib = import libPath;
in
{
lib = {
inherit tagsPath libPath;
tags = import tagsPath { format = true; inherit lib; };
core = lib;
};
};
}

8
lib.nix Normal file
View File

@ -0,0 +1,8 @@
let
inherit (builtins) isAttrs isList map;
in
{
mapAttrsToList = f: attrs: map (name: f name attrs.${name}) (builtins.attrNames attrs);
concatStrings = builtins.concatStringsSep "";
genAttrs = f: names: builtins.listToAttrs (map (n: { name = n; value = (f n); }) names);
} // builtins

17
tags.nix Normal file
View File

@ -0,0 +1,17 @@
{ 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; };
}