From e07014b5bd51fba81710d6b454df40ea62b6581a Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Mon, 27 Dec 2010 17:40:55 +0100 Subject: Targets have access to the store --- src/Hakyll/Core/Run.hs | 13 +++++++------ src/Hakyll/Core/Target/Internal.hs | 6 +++++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Hakyll/Core/Run.hs b/src/Hakyll/Core/Run.hs index 4683768..b5d6012 100644 --- a/src/Hakyll/Core/Run.hs +++ b/src/Hakyll/Core/Run.hs @@ -3,7 +3,7 @@ module Hakyll.Core.Run where import Control.Arrow ((&&&)) -import Control.Monad (msum, foldM, forM, forM_) +import Control.Monad (foldM, forM_) import qualified Data.Map as M import Hakyll.Core.Route @@ -12,18 +12,19 @@ import Hakyll.Core.ResourceProvider import Hakyll.Core.ResourceProvider.FileResourceProvider import Hakyll.Core.Rules import Hakyll.Core.Target -import Hakyll.Core.Identifier import Hakyll.Core.DirectedGraph import Hakyll.Core.DirectedGraph.DependencySolver import Hakyll.Core.Writable +import Hakyll.Core.Store hakyll :: Writable a => Rules a -> IO () hakyll rules = do + store <- makeStore "_store" provider <- fileResourceProvider - hakyllWith rules provider + hakyllWith rules provider store -hakyllWith :: Writable a => Rules a -> ResourceProvider -> IO () -hakyllWith rules provider = do +hakyllWith :: Writable a => Rules a -> ResourceProvider -> Store -> IO () +hakyllWith rules provider store = do let -- Get the rule set ruleSet = runRules rules provider @@ -63,6 +64,6 @@ hakyllWith rules provider = do putStrLn "DONE." where addTarget map' (id', targ) = do - result <- runTarget targ id' (map' M.!) provider + result <- runTarget targ id' (map' M.!) provider store putStrLn $ "Generated target: " ++ show id' return $ M.insert id' result map' diff --git a/src/Hakyll/Core/Target/Internal.hs b/src/Hakyll/Core/Target/Internal.hs index f40c798..dce4bfe 100644 --- a/src/Hakyll/Core/Target/Internal.hs +++ b/src/Hakyll/Core/Target/Internal.hs @@ -15,6 +15,7 @@ import Control.Monad.Reader (ReaderT, runReaderT) import Hakyll.Core.Identifier import Hakyll.Core.ResourceProvider +import Hakyll.Core.Store -- | A lookup with which we can get dependencies -- @@ -26,6 +27,7 @@ data TargetEnvironment a = TargetEnvironment { targetIdentifier :: Identifier -- ^ Identifier , targetDependencyLookup :: DependencyLookup a -- ^ Dependency lookup , targetResourceProvider :: ResourceProvider -- ^ To get resources + , targetStore :: Store -- ^ Store for caching } -- | Monad for targets. In this monad, the user can compose targets and describe @@ -45,11 +47,13 @@ runTarget :: Target a -> Identifier -> DependencyLookup a -> ResourceProvider + -> Store -> IO a -runTarget target id' lookup' provider = runReaderT (unTargetM target) env +runTarget target id' lookup' provider store = runReaderT (unTargetM target) env where env = TargetEnvironment { targetIdentifier = id' , targetDependencyLookup = lookup' , targetResourceProvider = provider + , targetStore = store } -- cgit v1.2.3