1-- | A Compiler manages targets and dependencies between targets.
3{-# LANGUAGE GeneralizedNewtypeDeriving #-}
4module Hakyll.Core.Compiler
13import Control.Arrow (second)
14import Control.Applicative (Applicative, (<$>))
15import Control.Monad.State (State, modify, runState)
16import Control.Monad.Reader (ReaderT, ask, runReaderT)
18import qualified Data.Set as S
20import Hakyll.Core.Identifier
21import Hakyll.Core.Target
22import Hakyll.Core.Target.Internal
24-- | A set of dependencies
26type Dependencies = Set Identifier
28-- | Add one dependency
30addDependency :: Identifier -> CompilerM a ()
31addDependency dependency = CompilerM $ modify $ addDependency'
34 { compilerDependencies = S.insert dependency $ compilerDependencies x
37-- | Environment in which a compiler runs
39data CompilerEnvironment a = CompilerEnvironment
40 { compilerIdentifier :: Identifier -- ^ Target identifier
43-- | State carried along by a compiler
45data CompilerState = CompilerState
46 { compilerDependencies :: Dependencies
49-- | The compiler monad
51newtype CompilerM a b = CompilerM
52 { unCompilerM :: ReaderT (CompilerEnvironment a) (State CompilerState) b
53 } deriving (Monad, Functor, Applicative)
55-- | Simplified type for a compiler generating a target (which covers most
58type Compiler a = CompilerM a (TargetM a a)
60-- | Run a compiler, yielding the resulting target and it's dependencies
62runCompiler :: Compiler a -> Identifier -> (TargetM a a, Dependencies)
63runCompiler compiler identifier = second compilerDependencies $
64 runState (runReaderT (unCompilerM compiler) env) state
66 env = CompilerEnvironment {compilerIdentifier = identifier}
67 state = CompilerState S.empty
69-- | Require another target. Using this function ensures automatic handling of
74require identifier = do
75 addDependency identifier
76 return $ TargetM $ flip targetDependencyLookup identifier <$> ask
78-- | Construct a target from a string, this string being the content of the
81compileFromString :: (String -> TargetM a a) -- ^ Function to create the target
82 -> Compiler a -- ^ Resulting compiler
83compileFromString = return . (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