chore: init
This commit is contained in:
commit
d7671bf1ba
19
flake.nix
Normal file
19
flake.nix
Normal 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
8
lib.nix
Normal 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
17
tags.nix
Normal 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; };
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user