commit 0baf2243c2b14359bfed72047dd82b3416eb47a0
parent ffa1e6888b087d03a7053ab86114da362fcab83e
Author: figsoda <figsoda@pm.me>
Date: Fri, 26 May 2023 16:10:50 -0400
parent ffa1e6888b087d03a7053ab86114da362fcab83e
Author: figsoda <figsoda@pm.me>
Date: Fri, 26 May 2023 16:10:50 -0400
matchers.extension: init
4 files changed, 33 insertions(+), 16 deletions(-)
diff --git a/default.nix b/default.nix @@ -10,7 +10,9 @@ let }; }; matchers.nix = import ./src/matchers/nix.nix { - inherit lib; + super.extension = import ./src/matchers/extension.nix { + inherit lib; + }; }; parsePath = import ./src/__parsePath.nix { inherit lib;
diff --git a/docs/src/api/matchers.md b/docs/src/api/matchers.md @@ -32,13 +32,24 @@ Type: `({ self, super, root, ... } -> Path -> a }) -> Matcher` Matches any file name. This can be used as the last matcher as a catch-all. +## `matchers.extension` + +Source: [`src/matchers/extension.nix`](https://github.com/nix-community/haumea/blob/main/src/matchers/extension.nix) + +Type: `String -> ({ self, super, root, ... } -> Path -> a }) -> Matcher` + +Matches files with the given extension. +`matchers.extension "foo"` matches `a.foo` and `a.b.foo`, but not `.foo`. + ## `matchers.nix` Source: [`src/matchers/nix.nix`](https://github.com/nix-community/haumea/blob/main/src/matchers/nix.nix) Type: `({ self, super, root, ... } -> Path -> a }) -> Matcher` -Matches files that end in `.nix`. This is the default matcher if no matchers are defined. +Matches files that end in `.nix`. This is equivalent to `matchers.extension "nix"`. + +This is the default matcher if no matchers are defined. ## `matchers.regex`
diff --git a/src/matchers/extension.nix b/src/matchers/extension.nix @@ -0,0 +1,16 @@ +{ lib }: + +let + inherit (builtins) + stringLength + ; + inherit (lib) + hasSuffix + ; +in + +ext: f: { + matches = file: hasSuffix ".${ext}" file + && stringLength file > (stringLength ext + 1); + loader = f; +}
diff --git a/src/matchers/nix.nix b/src/matchers/nix.nix @@ -1,15 +1,3 @@ -{ lib }: +{ super }: -let - inherit (builtins) - stringLength - ; - inherit (lib) - hasSuffix - ; -in - -f: { - matches = file: hasSuffix ".nix" file && stringLength file > 4; - loader = f; -} +super.extension "nix"