mirror of
https://github.com/RGBCube/HTMNIX
synced 2025-07-25 23:17:44 +00:00
Prefer lib. instead of builtins.
This commit is contained in:
parent
8f1e184a29
commit
22ae8f21cd
2 changed files with 10 additions and 11 deletions
|
@ -10,7 +10,7 @@ lib: let
|
|||
yeet = string: builtins.unsafeDiscardStringContext (builtins.unsafeDiscardOutputDependency string);
|
||||
|
||||
getContent = drvPath: let
|
||||
drv = builtins.readFile drvPath;
|
||||
drv = lib.readFile drvPath;
|
||||
isValid = builtins.match ".*${lib.escapeRegex startMarker}.*${lib.escapeRegex endMarker}.*" drv != null;
|
||||
content = lib.pipe drv [
|
||||
(lib.splitString startMarker)
|
||||
|
@ -40,7 +40,7 @@ lib: let
|
|||
final = recurseSubDrv ctxNames [ string ];
|
||||
final' = assert (lib.length final == 1); lib.head final;
|
||||
in if builtins.hasContext string then
|
||||
builtins.replaceStrings [ ''\"'' ''\n'' ] [ ''"'' "\n" ] (yeet final')
|
||||
lib.replaceStrings [ ''\"'' ''\n'' ] [ ''"'' "\n" ] (yeet final')
|
||||
else
|
||||
lib.strings.escapeXML string;
|
||||
|
||||
|
|
17
flake.nix
17
flake.nix
|
@ -6,19 +6,18 @@
|
|||
outputs = { self, nixpkgslib }: let
|
||||
inherit (nixpkgslib) lib;
|
||||
|
||||
first = n: builtins.substring 0 n;
|
||||
dropFirst = n: string: builtins.substring n (builtins.stringLength string - n) string;
|
||||
first = n: lib.substring 0 n;
|
||||
dropFirst = n: string: lib.substring n (lib.stringLength string - n) string;
|
||||
|
||||
last = n: string: builtins.substring (builtins.stringLength string - n) n string;
|
||||
dropLast = n: string: builtins.substring 0 (builtins.stringLength string - n) string;
|
||||
last = n: string: lib.substring (lib.stringLength string - n) n string;
|
||||
dropLast = n: string: lib.substring 0 (lib.stringLength string - n) string;
|
||||
|
||||
escapix = import ./escape.nix lib;
|
||||
inherit (escapix) escape;
|
||||
|
||||
attrsetToHtmlAttrs = attrs:
|
||||
builtins.concatStringsSep " "
|
||||
(builtins.attrValues
|
||||
(builtins.mapAttrs (k: v: ''${k}="${escape (toString v)}"'') attrs));
|
||||
lib.concatStringsSep " "
|
||||
(lib.mapAttrsToList (k: v: ''${k}="${escape (toString v)}"'') attrs);
|
||||
|
||||
dottedNameToTag = name:
|
||||
if first 1 name == "."
|
||||
|
@ -44,7 +43,7 @@
|
|||
|
||||
__functor = this: next:
|
||||
# Not an attrset. Just add it onto the HTML.
|
||||
if !builtins.isAttrs next
|
||||
if !lib.isAttrs next
|
||||
then this // {
|
||||
outPath = (toString this) + escape (toString next);
|
||||
}
|
||||
|
@ -61,7 +60,7 @@
|
|||
# This will output the following HTML:
|
||||
#
|
||||
# <foo bar="baz" fizz="fuzz">
|
||||
else if builtins.isAttrs next && !(next ? outPath)
|
||||
else if lib.isAttrs next && !(next ? outPath)
|
||||
then let
|
||||
lastElementIsTag = last 1 (toString this) == ">";
|
||||
lastElementIsSelfClosing = last 2 (toString this) == "/>";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue