1
Fork 0
mirror of https://github.com/RGBCube/HTMNIX synced 2025-07-26 23:47:43 +00:00

Prefer lib. instead of builtins.

This commit is contained in:
RGBCube 2024-02-28 14:09:09 +03:00
parent 8f1e184a29
commit 22ae8f21cd
No known key found for this signature in database
2 changed files with 10 additions and 11 deletions

View file

@ -10,7 +10,7 @@ lib: let
yeet = string: builtins.unsafeDiscardStringContext (builtins.unsafeDiscardOutputDependency string); yeet = string: builtins.unsafeDiscardStringContext (builtins.unsafeDiscardOutputDependency string);
getContent = drvPath: let getContent = drvPath: let
drv = builtins.readFile drvPath; drv = lib.readFile drvPath;
isValid = builtins.match ".*${lib.escapeRegex startMarker}.*${lib.escapeRegex endMarker}.*" drv != null; isValid = builtins.match ".*${lib.escapeRegex startMarker}.*${lib.escapeRegex endMarker}.*" drv != null;
content = lib.pipe drv [ content = lib.pipe drv [
(lib.splitString startMarker) (lib.splitString startMarker)
@ -40,7 +40,7 @@ lib: let
final = recurseSubDrv ctxNames [ string ]; final = recurseSubDrv ctxNames [ string ];
final' = assert (lib.length final == 1); lib.head final; final' = assert (lib.length final == 1); lib.head final;
in if builtins.hasContext string then in if builtins.hasContext string then
builtins.replaceStrings [ ''\"'' ''\n'' ] [ ''"'' "\n" ] (yeet final') lib.replaceStrings [ ''\"'' ''\n'' ] [ ''"'' "\n" ] (yeet final')
else else
lib.strings.escapeXML string; lib.strings.escapeXML string;

View file

@ -6,19 +6,18 @@
outputs = { self, nixpkgslib }: let outputs = { self, nixpkgslib }: let
inherit (nixpkgslib) lib; inherit (nixpkgslib) lib;
first = n: builtins.substring 0 n; first = n: lib.substring 0 n;
dropFirst = n: string: builtins.substring n (builtins.stringLength string - n) string; dropFirst = n: string: lib.substring n (lib.stringLength string - n) string;
last = n: string: builtins.substring (builtins.stringLength string - n) n string; last = n: string: lib.substring (lib.stringLength string - n) n string;
dropLast = n: string: builtins.substring 0 (builtins.stringLength string - n) string; dropLast = n: string: lib.substring 0 (lib.stringLength string - n) string;
escapix = import ./escape.nix lib; escapix = import ./escape.nix lib;
inherit (escapix) escape; inherit (escapix) escape;
attrsetToHtmlAttrs = attrs: attrsetToHtmlAttrs = attrs:
builtins.concatStringsSep " " lib.concatStringsSep " "
(builtins.attrValues (lib.mapAttrsToList (k: v: ''${k}="${escape (toString v)}"'') attrs);
(builtins.mapAttrs (k: v: ''${k}="${escape (toString v)}"'') attrs));
dottedNameToTag = name: dottedNameToTag = name:
if first 1 name == "." if first 1 name == "."
@ -44,7 +43,7 @@
__functor = this: next: __functor = this: next:
# Not an attrset. Just add it onto the HTML. # Not an attrset. Just add it onto the HTML.
if !builtins.isAttrs next if !lib.isAttrs next
then this // { then this // {
outPath = (toString this) + escape (toString next); outPath = (toString this) + escape (toString next);
} }
@ -61,7 +60,7 @@
# This will output the following HTML: # This will output the following HTML:
# #
# <foo bar="baz" fizz="fuzz"> # <foo bar="baz" fizz="fuzz">
else if builtins.isAttrs next && !(next ? outPath) else if lib.isAttrs next && !(next ? outPath)
then let then let
lastElementIsTag = last 1 (toString this) == ">"; lastElementIsTag = last 1 (toString this) == ">";
lastElementIsSelfClosing = last 2 (toString this) == "/>"; lastElementIsSelfClosing = last 2 (toString this) == "/>";