summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJasper Van der Jeugt <m@jaspervdj.be>2012-02-19 20:29:26 +0100
committerJasper Van der Jeugt <m@jaspervdj.be>2012-02-19 20:39:23 +0100
commit1996052b110b8528e90d76c06e13c0b7e4a2e93a (patch)
tree306aa351fb307feecfc504b9593e6507e38353fb
parent2416c76faa0dadb330c74dc0f3ddefdf4f889659 (diff)
downloadhakyll-1996052b110b8528e90d76c06e13c0b7e4a2e93a.tar.gz
Add complement function for patterns
-rw-r--r--src/Hakyll/Core/Identifier/Pattern.hs17
-rw-r--r--tests/Hakyll/Core/Identifier/Tests.hs8
2 files changed, 21 insertions, 4 deletions
diff --git a/src/Hakyll/Core/Identifier/Pattern.hs b/src/Hakyll/Core/Identifier/Pattern.hs
index e770d13..5f97215 100644
--- a/src/Hakyll/Core/Identifier/Pattern.hs
+++ b/src/Hakyll/Core/Identifier/Pattern.hs
@@ -36,13 +36,19 @@
-- function.
--
module Hakyll.Core.Identifier.Pattern
- ( Pattern
+ ( -- * The pattern type
+ Pattern
, castPattern
+
+ -- * Creating patterns
, parseGlob
, predicate
, list
, regex
, inGroup
+ , complement
+
+ -- * Applying patterns
, matches
, filterMatches
, capture
@@ -131,6 +137,15 @@ regex str = predicate $ fromMaybe False . (=~~ str) . toFilePath
inGroup :: Maybe String -> Pattern a
inGroup group = predicate $ (== group) . identifierGroup
+-- | Inverts a pattern, e.g.
+--
+-- > complement "foo/bar.html"
+--
+-- will match /anything/ except @\"foo\/bar.html\"@
+--
+complement :: Pattern a -> Pattern a
+complement p = predicate (not . matches p)
+
-- | Check if an identifier matches a pattern
--
matches :: Pattern a -> Identifier a -> Bool
diff --git a/tests/Hakyll/Core/Identifier/Tests.hs b/tests/Hakyll/Core/Identifier/Tests.hs
index 4060b1f..c496a98 100644
--- a/tests/Hakyll/Core/Identifier/Tests.hs
+++ b/tests/Hakyll/Core/Identifier/Tests.hs
@@ -37,8 +37,10 @@ captureTests = fromAssertions "capture"
matchesTests :: [Test]
matchesTests = fromAssertions "matches"
- [ True @=? matches (regex "^foo/[^x]*$") "foo/bar"
- , False @=? matches (regex "^foo/[^x]*$") "foo/barx"
- , True @=? matches (list ["foo.markdown"]) "foo.markdown"
+ [ True @=? matches (list ["foo.markdown"]) "foo.markdown"
, False @=? matches (list ["foo"]) (Identifier (Just "foo") "foo")
+ , True @=? matches (regex "^foo/[^x]*$") "foo/bar"
+ , False @=? matches (regex "^foo/[^x]*$") "foo/barx"
+ , True @=? matches (complement "foo.markdown") "bar.markdown"
+ , False @=? matches (complement "foo.markdown") "foo.markdown"
]