diff options
author | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2011-04-14 10:17:08 +0200 |
---|---|---|
committer | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2011-04-14 10:17:08 +0200 |
commit | 5327e881609c882df17c82723d452950658b9e8f (patch) | |
tree | 525c007e0e210ed0f26757a4ee950c6bbef11b19 /src/Hakyll/Core | |
parent | 1dbe8945eb018d7773a4efdbb008f92c779e5555 (diff) | |
download | hakyll-5327e881609c882df17c82723d452950658b9e8f.tar.gz |
Add `resources` function to rules DSL
Diffstat (limited to 'src/Hakyll/Core')
-rw-r--r-- | src/Hakyll/Core/Rules.hs | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/src/Hakyll/Core/Rules.hs b/src/Hakyll/Core/Rules.hs index 155e032..fe2c59c 100644 --- a/src/Hakyll/Core/Rules.hs +++ b/src/Hakyll/Core/Rules.hs @@ -23,6 +23,7 @@ module Hakyll.Core.Rules , compile , create , route + , resources , metaCompile , metaCompileWith ) where @@ -72,8 +73,8 @@ tellCompilers compilers = RulesM $ do -- tellResources :: [Resource] -> Rules -tellResources resources = RulesM $ tell $ - RuleSet mempty mempty $ S.fromList resources +tellResources resources' = RulesM $ tell $ + RuleSet mempty mempty $ S.fromList resources' -- | Only compile/route items satisfying the given predicate -- @@ -128,14 +129,11 @@ group g = RulesM . local setGroup' . unRulesM -- compile :: (Binary a, Typeable a, Writable a) => Compiler Resource a -> Rules -compile compiler = RulesM $ do - pattern <- rulesPattern <$> ask - provider <- rulesResourceProvider <$> ask - let ids = filterMatches pattern $ map toIdentifier $ resourceList provider - unRulesM $ do - tellCompilers $ flip map ids $ \identifier -> - (identifier, constA (fromIdentifier identifier) >>> compiler) - tellResources $ map fromIdentifier ids +compile compiler = do + ids <- resources + tellCompilers $ flip map ids $ \identifier -> + (identifier, constA (fromIdentifier identifier) >>> compiler) + tellResources $ map fromIdentifier ids -- | Add a compilation rule -- @@ -160,6 +158,14 @@ route route' = RulesM $ do group' <- rulesGroup <$> ask unRulesM $ tellRoute $ matchRoute (pattern `mappend` inGroup group') route' +-- | Get a list of resources matching the current pattern +-- +resources :: RulesM [Identifier] +resources = RulesM $ do + pattern <- rulesPattern <$> ask + provider <- rulesResourceProvider <$> ask + return $ filterMatches pattern $ map toIdentifier $ resourceList provider + -- | Apart from regular compilers, one is also able to specify metacompilers. -- Metacompilers are a special class of compilers: they are compilers which -- produce other compilers. |