From d0af1024d008113347183024df41c739d7644c02 Mon Sep 17 00:00:00 2001 From: Nick McAvoy Date: Tue, 16 Sep 2014 22:20:11 -0400 Subject: matchMetadata for examining metadata when defining rules --- src/Hakyll/Core/Rules.hs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src') diff --git a/src/Hakyll/Core/Rules.hs b/src/Hakyll/Core/Rules.hs index c248a9b..1c8b93c 100644 --- a/src/Hakyll/Core/Rules.hs +++ b/src/Hakyll/Core/Rules.hs @@ -19,6 +19,7 @@ module Hakyll.Core.Rules ( Rules , match + , matchMetadata , create , version , compile @@ -131,6 +132,19 @@ match pattern rules = do setMatches ids env = env {rulesMatches = ids} +-------------------------------------------------------------------------------- +matchMetadata :: Pattern -> (Metadata -> Bool) -> Rules () -> Rules () +matchMetadata pattern metadataPred rules = do + tellPattern pattern + flush + idsAndMetadata <- getAllMetadata pattern + let ids = map fst . filter (metadataPred . snd) $ idsAndMetadata + tellResources ids + Rules $ local (setMatches ids) $ unRules $ rules >> flush + where + setMatches ids env = env {rulesMatches = ids} + + -------------------------------------------------------------------------------- create :: [Identifier] -> Rules () -> Rules () create ids rules = do -- cgit v1.2.3 From b36232e05ebe7fbde708364a2587ba91287010cd Mon Sep 17 00:00:00 2001 From: "Daniel P. Wright" Date: Sat, 3 Jan 2015 22:55:51 +0900 Subject: Refactor match and matchMetadata code into matchInternal As per jaspervdj's request in #300, refactor the common code from match and matchMetadata into a single, unexported function. --- src/Hakyll/Core/Rules.hs | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/Hakyll/Core/Rules.hs b/src/Hakyll/Core/Rules.hs index 1c8b93c..0766e58 100644 --- a/src/Hakyll/Core/Rules.hs +++ b/src/Hakyll/Core/Rules.hs @@ -121,28 +121,25 @@ flush = Rules $ do -------------------------------------------------------------------------------- -match :: Pattern -> Rules () -> Rules () -match pattern rules = do +matchInternal :: Pattern -> Rules [Identifier] -> Rules () -> Rules () +matchInternal pattern getIDs rules = do tellPattern pattern flush - ids <- getMatches pattern + ids <- getIDs tellResources ids Rules $ local (setMatches ids) $ unRules $ rules >> flush where setMatches ids env = env {rulesMatches = ids} +-------------------------------------------------------------------------------- +match :: Pattern -> Rules () -> Rules () +match pattern = matchInternal pattern $ getMatches pattern + -------------------------------------------------------------------------------- matchMetadata :: Pattern -> (Metadata -> Bool) -> Rules () -> Rules () -matchMetadata pattern metadataPred rules = do - tellPattern pattern - flush - idsAndMetadata <- getAllMetadata pattern - let ids = map fst . filter (metadataPred . snd) $ idsAndMetadata - tellResources ids - Rules $ local (setMatches ids) $ unRules $ rules >> flush - where - setMatches ids env = env {rulesMatches = ids} +matchMetadata pattern metadataPred = matchInternal pattern $ + map fst . filter (metadataPred . snd) <$> getAllMetadata pattern -------------------------------------------------------------------------------- -- cgit v1.2.3