From 82d5210f25d560e9488ab14f243a2cad9ad906a9 Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Thu, 22 Nov 2012 13:38:28 +0100 Subject: Add MonadMetadata and instances --- src/Hakyll/Core/Rules/Internal.hs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/Hakyll/Core/Rules') diff --git a/src/Hakyll/Core/Rules/Internal.hs b/src/Hakyll/Core/Rules/Internal.hs index a067b02..249ae3b 100644 --- a/src/Hakyll/Core/Rules/Internal.hs +++ b/src/Hakyll/Core/Rules/Internal.hs @@ -12,8 +12,10 @@ module Hakyll.Core.Rules.Internal -------------------------------------------------------------------------------- -import Control.Applicative (Applicative) +import Control.Applicative (Applicative, (<$>)) +import Control.Monad.Reader (ask) import Control.Monad.RWS (RWST, runRWST) +import Control.Monad.Trans (liftIO) import qualified Data.Map as M import Data.Monoid (Monoid, mappend, mempty) import Data.Set (Set) @@ -24,6 +26,7 @@ import Hakyll.Core.Compiler.Internal import Hakyll.Core.Identifier import Hakyll.Core.Identifier.Pattern import Hakyll.Core.Item.SomeItem +import Hakyll.Core.Metadata import Hakyll.Core.Provider import Hakyll.Core.Routes @@ -70,6 +73,17 @@ newtype Rules a = Rules } deriving (Monad, Functor, Applicative) +-------------------------------------------------------------------------------- +instance MonadMetadata Rules where + getMetadata identifier = Rules $ do + provider <- rulesProvider <$> ask + liftIO $ resourceMetadata provider identifier + + getMatches pattern = Rules $ do + provider <- rulesProvider <$> ask + return $ filterMatches pattern $ resourceList provider + + -------------------------------------------------------------------------------- -- | Run a Rules monad, resulting in a 'RuleSet' runRules :: Rules a -> Provider -> IO RuleSet -- cgit v1.2.3