summaryrefslogtreecommitdiff
path: root/src/Hakyll/Core/Compiler
diff options
context:
space:
mode:
Diffstat (limited to 'src/Hakyll/Core/Compiler')
-rw-r--r--src/Hakyll/Core/Compiler/Internal.hs28
1 files changed, 23 insertions, 5 deletions
diff --git a/src/Hakyll/Core/Compiler/Internal.hs b/src/Hakyll/Core/Compiler/Internal.hs
index 30a391f..d37c7ef 100644
--- a/src/Hakyll/Core/Compiler/Internal.hs
+++ b/src/Hakyll/Core/Compiler/Internal.hs
@@ -32,6 +32,15 @@ import Hakyll.Core.Logger
--
type Dependencies = Set Identifier
+-- | Environment in which the dependency analyzer runs
+--
+data DependencyEnvironment = DependencyEnvironment
+ { -- | Target identifier
+ dependencyIdentifier :: Identifier
+ , -- | Resource provider
+ dependencyResourceProvider :: ResourceProvider
+ }
+
-- | Environment in which a compiler runs
--
data CompilerEnvironment = CompilerEnvironment
@@ -58,7 +67,7 @@ newtype CompilerM a = CompilerM
-- | The compiler arrow
--
data Compiler a b = Compiler
- { compilerDependencies :: Reader ResourceProvider Dependencies
+ { compilerDependencies :: Reader DependencyEnvironment Dependencies
, compilerJob :: a -> CompilerM b
}
@@ -109,19 +118,28 @@ runCompilerJob compiler identifier provider route store modified logger =
}
runCompilerDependencies :: Compiler () a
+ -> Identifier
-> ResourceProvider
-> Dependencies
-runCompilerDependencies compiler = runReader (compilerDependencies compiler)
+runCompilerDependencies compiler identifier provider =
+ runReader (compilerDependencies compiler) env
+ where
+ env = DependencyEnvironment
+ { dependencyIdentifier = identifier
+ , dependencyResourceProvider = provider
+ }
fromJob :: (a -> CompilerM b)
-> Compiler a b
fromJob = Compiler (return S.empty)
-fromDependencies :: (ResourceProvider -> [Identifier])
+fromDependencies :: (Identifier -> ResourceProvider -> [Identifier])
-> Compiler b b
-fromDependencies deps = Compiler (S.fromList . deps <$> ask) return
+fromDependencies collectDeps = flip Compiler return $ do
+ DependencyEnvironment identifier provider <- ask
+ return $ S.fromList $ collectDeps identifier provider
-- | Wait until another compiler has finished before running this compiler
--
fromDependency :: Identifier -> Compiler a a
-fromDependency = fromDependencies . const . return
+fromDependency = fromDependencies . const . const . return