@@ -7,6 +7,7 @@ module Hakyll.Core.Compiler
8 , runCompiler
8 , runCompiler
10 , compileFromString
11 , compileFromString
@@ -20,10 +21,12 @@ import Data.Typeable (Typeable)
20import Data.Binary (Binary)
21import Data.Binary (Binary)
22import Hakyll.Core.Identifier
23import Hakyll.Core.Identifier
24+import Hakyll.Core.Identifier.Pattern
23import Hakyll.Core.Target
25import Hakyll.Core.Target
24import Hakyll.Core.Target.Internal
26import Hakyll.Core.Target.Internal
25import Hakyll.Core.CompiledItem
27import Hakyll.Core.CompiledItem
26import Hakyll.Core.Writable
28import Hakyll.Core.Writable
29+import Hakyll.Core.ResourceProvider
28-- | A set of dependencies
31-- | A set of dependencies
@@ -41,7 +44,8 @@ addDependency dependency = CompilerM $ modify $ addDependency'
41-- | Environment in which a compiler runs
44-- | Environment in which a compiler runs
43data CompilerEnvironment = CompilerEnvironment
46data CompilerEnvironment = CompilerEnvironment
44− { compilerIdentifier :: Identifier -- ^ Target identifier
47+ { compilerIdentifier :: Identifier -- ^ Target identifier
48+ , compilerResourceProvider :: ResourceProvider -- ^ Resource provider
47-- | State carried along by a compiler
51-- | State carried along by a compiler
@@ -63,12 +67,17 @@ type Compiler a = CompilerM (TargetM a)
64-- | Run a compiler, yielding the resulting target and it's dependencies
68-- | Run a compiler, yielding the resulting target and it's dependencies
66−runCompiler :: Compiler a -> Identifier -> (TargetM a, Dependencies)
70+runCompiler :: Compiler a -> Identifier -> ResourceProvider
71+ -> (TargetM a, Dependencies)
67−runCompiler compiler identifier = second compilerDependencies $
72+runCompiler compiler identifier provider = second compilerDependencies $
68 runState (runReaderT (unCompilerM compiler) env) state
73 runState (runReaderT (unCompilerM compiler) env) state
70− env = CompilerEnvironment {compilerIdentifier = identifier}
71 state = CompilerState S.empty
75 state = CompilerState S.empty
76+ env = CompilerEnvironment
77+ { compilerIdentifier = identifier
78+ , compilerResourceProvider = provider
73-- | Require another target. Using this function ensures automatic handling of
82-- | Require another target. Using this function ensures automatic handling of
74-- dependencies
83-- dependencies
@@ -82,6 +91,17 @@ require identifier = do
82 lookup' <- targetDependencyLookup <$> ask
91 lookup' <- targetDependencyLookup <$> ask
83 return $ unCompiledItem $ lookup' identifier
92 return $ unCompiledItem $ lookup' identifier
94+-- | Require a number of targets. Using this function ensures automatic handling
97+requireAll :: (Binary a, Typeable a, Writable a)
100+requireAll pattern = CompilerM $ do
101+ provider <- compilerResourceProvider <$> ask
102+ r <- unCompilerM $ mapM require $ matches pattern $ resourceList provider
85-- | Construct a target from a string, this string being the content of the
105-- | Construct a target from a string, this string being the content of the
86-- resource.
106-- resource.