diff options
author | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2010-12-24 16:55:20 +0100 |
---|---|---|
committer | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2010-12-24 16:55:20 +0100 |
commit | 12c446785c76130a65c46cc603e767893b4818b5 (patch) | |
tree | 45d07507e23ced12f315f16d51fad19a1c1138c9 | |
parent | 4b7c42d644a1fb2242ad79a2193edad4ba6b2b7e (diff) | |
download | hakyll-12c446785c76130a65c46cc603e767893b4818b5.tar.gz |
Add target module
-rw-r--r-- | src/Hakyll/Core/DirectedGraph/Internal.hs | 3 | ||||
-rw-r--r-- | src/Hakyll/Core/Target.hs | 11 | ||||
-rw-r--r-- | src/Hakyll/Core/Target/Internal.hs | 46 |
3 files changed, 59 insertions, 1 deletions
diff --git a/src/Hakyll/Core/DirectedGraph/Internal.hs b/src/Hakyll/Core/DirectedGraph/Internal.hs index 9890fc0..52a712d 100644 --- a/src/Hakyll/Core/DirectedGraph/Internal.hs +++ b/src/Hakyll/Core/DirectedGraph/Internal.hs @@ -1,4 +1,5 @@ --- | Internal structure of the DirectedGraph type. Not exported in the library. +-- | Internal structure of the DirectedGraph type. Not exported outside of the +-- library. -- module Hakyll.Core.DirectedGraph.Internal ( Node (..) diff --git a/src/Hakyll/Core/Target.hs b/src/Hakyll/Core/Target.hs new file mode 100644 index 0000000..1f783df --- /dev/null +++ b/src/Hakyll/Core/Target.hs @@ -0,0 +1,11 @@ +-- | A target represents one compilation unit, e.g. a blog post, a CSS file... +-- +{-# LANGUAGE GeneralizedNewtypeDeriving #-} +module Hakyll.Core.Target + ( DependencyLookup + , TargetM + , Target + , runTarget + ) where + +import Hakyll.Core.Target.Internal diff --git a/src/Hakyll/Core/Target/Internal.hs b/src/Hakyll/Core/Target/Internal.hs new file mode 100644 index 0000000..a58f736 --- /dev/null +++ b/src/Hakyll/Core/Target/Internal.hs @@ -0,0 +1,46 @@ +-- | Internal structure of a Target, not exported outside of the library +-- +{-# LANGUAGE GeneralizedNewtypeDeriving #-} +module Hakyll.Core.Target.Internal + ( DependencyLookup + , TargetM (..) + , Target + , runTarget + ) where + +import Control.Monad.Trans (MonadIO) +import Control.Monad.Reader (ReaderT, runReaderT) + +import Hakyll.Core.Identifier + +-- | A lookup with which we can get dependencies +-- +type DependencyLookup a = Identifier -> a + +-- | Environment for the target monad +-- +data TargetEnvironment a = TargetEnvironment + { targetIdentifier :: Identifier + , targetDependencyLookup :: DependencyLookup a -- ^ Dependency lookup + } + +-- | Monad for targets. In this monad, the user can compose targets and describe +-- how they should be created. +-- +newtype TargetM a b = TargetM {unTargetM :: ReaderT (TargetEnvironment a) IO b} + deriving (Monad, Functor, MonadIO) + +-- | Simplification of the 'TargetM' type for concrete cases: the type of the +-- returned item should equal the type of the dependencies. +-- +type Target a = TargetM a a + +-- | Run a target, yielding an actual result. +-- +runTarget :: Target a -> Identifier -> DependencyLookup a -> IO a +runTarget target id' lookup' = runReaderT (unTargetM target) env + where + env = TargetEnvironment + { targetIdentifier = id' + , targetDependencyLookup = lookup' + } |