1-- | A Compiler manages targets and dependencies between targets.
3{-# LANGUAGE GeneralizedNewtypeDeriving #-}
4module Hakyll.Core.Compiler
14import Control.Arrow (second)
15import Control.Applicative (Applicative, (<$>))
16import Control.Monad.State (State, modify, runState)
17import Control.Monad.Reader (ReaderT, ask, runReaderT)
19import qualified Data.Set as S
21import Hakyll.Core.Identifier
22import Hakyll.Core.Target
23import Hakyll.Core.Target.Internal
25-- | A set of dependencies
27type Dependencies = Set Identifier
29-- | Add one dependency
31addDependency :: Identifier -> CompilerM a ()
32addDependency dependency = CompilerM $ modify $ addDependency'
35 { compilerDependencies = S.insert dependency $ compilerDependencies x
38-- | Environment in which a compiler runs
40data CompilerEnvironment a = CompilerEnvironment
41 { compilerIdentifier :: Identifier -- ^ Target identifier
44-- | State carried along by a compiler
46data CompilerState = CompilerState
47 { compilerDependencies :: Dependencies
50-- | The compiler monad
52newtype CompilerM a b = CompilerM
53 { unCompilerM :: ReaderT (CompilerEnvironment a) (State CompilerState) b
54 } deriving (Monad, Functor, Applicative)
56-- | Simplified type for a compiler generating a target (which covers most
59type Compiler a = CompilerM a (TargetM a a)
61-- | Run a compiler, yielding the resulting target and it's dependencies
63runCompiler :: Compiler a -> Identifier -> (TargetM a a, Dependencies)
64runCompiler compiler identifier = second compilerDependencies $
65 runState (runReaderT (unCompilerM compiler) env) state
67 env = CompilerEnvironment {compilerIdentifier = identifier}
68 state = CompilerState S.empty
70-- | Require another target. Using this function ensures automatic handling of
75require identifier = do
76 addDependency identifier
77 return $ TargetM $ flip targetDependencyLookup identifier <$> ask
79-- | Construct a target inside a compiler
81target :: TargetM a a -> Compiler a
84-- | Construct a target from a string, this string being the content of the
87targetFromString :: (String -> TargetM a a) -- ^ Function to create the target
88 -> Compiler a -- ^ Resulting compiler
89targetFromString = target . (getResourceString >>=)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list