@@ -7,6 +7,7 @@ module Hakyll.Core.Compiler
77 , Compiler
88 , runCompiler
99 , require
10+ , requireAll
1011 , compileFromString
1112 ) where
1213
@@ -20,10 +21,12 @@ import Data.Typeable (Typeable)
2021import Data.Binary (Binary)
2122
2223import Hakyll.Core.Identifier
24+import Hakyll.Core.Identifier.Pattern
2325import Hakyll.Core.Target
2426import Hakyll.Core.Target.Internal
2527import Hakyll.Core.CompiledItem
2628import Hakyll.Core.Writable
29+import Hakyll.Core.ResourceProvider
2730
2831-- | A set of dependencies
2932--
@@ -41,7 +44,8 @@ addDependency dependency = CompilerM $ modify $ addDependency'
4144-- | Environment in which a compiler runs
4245--
4346data CompilerEnvironment = CompilerEnvironment
44− { compilerIdentifier :: Identifier -- ^ Target identifier
47+ { compilerIdentifier :: Identifier -- ^ Target identifier
48+ , compilerResourceProvider :: ResourceProvider -- ^ Resource provider
4549 }
4650
4751-- | State carried along by a compiler
@@ -63,12 +67,17 @@ type Compiler a = CompilerM (TargetM a)
6367
6468-- | Run a compiler, yielding the resulting target and it's dependencies
6569--
66−runCompiler :: Compiler a -> Identifier -> (TargetM a, Dependencies)
67−runCompiler compiler identifier = second compilerDependencies $
70+runCompiler :: Compiler a -> Identifier -> ResourceProvider
71+ -> (TargetM a, Dependencies)
72+runCompiler compiler identifier provider = second compilerDependencies $
6873 runState (runReaderT (unCompilerM compiler) env) state
6974 where
70− env = CompilerEnvironment {compilerIdentifier = identifier}
7175 state = CompilerState S.empty
76+ env = CompilerEnvironment
77+ { compilerIdentifier = identifier
78+ , compilerResourceProvider = provider
79+ }
80+
7281
7382-- | Require another target. Using this function ensures automatic handling of
7483-- dependencies
@@ -82,6 +91,17 @@ require identifier = do
8291 lookup' <- targetDependencyLookup <$> ask
8392 return $ unCompiledItem $ lookup' identifier
8493
94+-- | Require a number of targets. Using this function ensures automatic handling
95+-- of dependencies
96+--
97+requireAll :: (Binary a, Typeable a, Writable a)
98+ => Pattern
99+ -> Compiler [a]
100+requireAll pattern = CompilerM $ do
101+ provider <- compilerResourceProvider <$> ask
102+ r <- unCompilerM $ mapM require $ matches pattern $ resourceList provider
103+ return $ sequence r
104+
85105-- | Construct a target from a string, this string being the content of the
86106-- resource.
87107--