on master help sign in
Add requireAll function
bf31c55Jasper Van der Jeugt
src/Hakyll/Core/Compiler.hs+24−4
@@ -7,6 +7,7 @@ module Hakyll.Core.Compiler
7 , Compiler
7 , Compiler
8 , runCompiler
8 , runCompiler
9 , require
9 , require
10+ , requireAll
10 , compileFromString
11 , compileFromString
11 ) where
12 ) where
12
13
@@ -20,10 +21,12 @@ import Data.Typeable (Typeable)
20import Data.Binary (Binary)
21import Data.Binary (Binary)
21
22
22import Hakyll.Core.Identifier
23import Hakyll.Core.Identifier
24+import Hakyll.Core.Identifier.Pattern
23import Hakyll.Core.Target
25import Hakyll.Core.Target
24import Hakyll.Core.Target.Internal
26import Hakyll.Core.Target.Internal
25import Hakyll.Core.CompiledItem
27import Hakyll.Core.CompiledItem
26import Hakyll.Core.Writable
28import Hakyll.Core.Writable
29+import Hakyll.Core.ResourceProvider
27
30
28-- | A set of dependencies
31-- | A set of dependencies
29--
32--
@@ -41,7 +44,8 @@ addDependency dependency = CompilerM $ modify $ addDependency'
41-- | Environment in which a compiler runs
44-- | Environment in which a compiler runs
42--
45--
43data CompilerEnvironment = CompilerEnvironment
46data CompilerEnvironment = CompilerEnvironment
44− { compilerIdentifier :: Identifier -- ^ Target identifier
47+ { compilerIdentifier :: Identifier -- ^ Target identifier
48+ , compilerResourceProvider :: ResourceProvider -- ^ Resource provider
45 }
49 }
46
50
47-- | State carried along by a compiler
51-- | State carried along by a compiler
@@ -63,12 +67,17 @@ type Compiler a = CompilerM (TargetM a)
63
67
64-- | Run a compiler, yielding the resulting target and it's dependencies
68-- | Run a compiler, yielding the resulting target and it's dependencies
65--
69--
66−runCompiler :: Compiler a -> Identifier -> (TargetM a, Dependencies)
70+runCompiler :: Compiler a -> Identifier -> ResourceProvider
71+ -> (TargetM a, Dependencies)
67−runCompiler compiler identifier = second compilerDependencies $
72+runCompiler compiler identifier provider = second compilerDependencies $
68 runState (runReaderT (unCompilerM compiler) env) state
73 runState (runReaderT (unCompilerM compiler) env) state
69 where
74 where
70− env = CompilerEnvironment {compilerIdentifier = identifier}
71 state = CompilerState S.empty
75 state = CompilerState S.empty
76+ env = CompilerEnvironment
77+ { compilerIdentifier = identifier
78+ , compilerResourceProvider = provider
79+ }
80+
72
81
73-- | Require another target. Using this function ensures automatic handling of
82-- | Require another target. Using this function ensures automatic handling of
74-- dependencies
83-- dependencies
@@ -82,6 +91,17 @@ require identifier = do
82 lookup' <- targetDependencyLookup <$> ask
91 lookup' <- targetDependencyLookup <$> ask
83 return $ unCompiledItem $ lookup' identifier
92 return $ unCompiledItem $ lookup' identifier
84
93
94+-- | Require a number of targets. Using this function ensures automatic handling
95+-- of dependencies
96+--
97+requireAll :: (Binary a, Typeable a, Writable a)
98+ => Pattern
99+ -> Compiler [a]
100+requireAll pattern = CompilerM $ do
101+ provider <- compilerResourceProvider <$> ask
102+ r <- unCompilerM $ mapM require $ matches pattern $ resourceList provider
103+ return $ sequence r
104+
85-- | Construct a target from a string, this string being the content of the
105-- | Construct a target from a string, this string being the content of the
86-- resource.
106-- resource.
87--
107--
src/Hakyll/Core/Run.hs+10−2
@@ -8,14 +8,17 @@ import qualified Data.Map as M
8import Data.Monoid (mempty)
8import Data.Monoid (mempty)
9import Data.Typeable (Typeable)
9import Data.Typeable (Typeable)
10import Data.Binary (Binary)
10import Data.Binary (Binary)
11+import System.FilePath ((</>))
11
12
12import Hakyll.Core.Route
13import Hakyll.Core.Route
14+import Hakyll.Core.Util.File
13import Hakyll.Core.Compiler
15import Hakyll.Core.Compiler
14import Hakyll.Core.ResourceProvider
16import Hakyll.Core.ResourceProvider
15import Hakyll.Core.ResourceProvider.FileResourceProvider
17import Hakyll.Core.ResourceProvider.FileResourceProvider
16import Hakyll.Core.Rules
18import Hakyll.Core.Rules
17import Hakyll.Core.Target
19import Hakyll.Core.Target
18import Hakyll.Core.DirectedGraph
20import Hakyll.Core.DirectedGraph
21+import Hakyll.Core.DirectedGraph.Dot
19import Hakyll.Core.DirectedGraph.DependencySolver
22import Hakyll.Core.DirectedGraph.DependencySolver
20import Hakyll.Core.Writable
23import Hakyll.Core.Writable
21import Hakyll.Core.Store
24import Hakyll.Core.Store
@@ -37,7 +40,7 @@ hakyllWith rules provider store = do
37
40
38 -- Get all targets
41 -- Get all targets
39 targets = flip map compilers $ \(id', compiler) ->
42 targets = flip map compilers $ \(id', compiler) ->
40− let (targ, deps) = runCompiler compiler id'
43+ let (targ, deps) = runCompiler compiler id' provider
41 in (id', targ, deps)
44 in (id', targ, deps)
42
45
43 -- Map mapping every identifier to it's target
46 -- Map mapping every identifier to it's target
@@ -55,6 +58,9 @@ hakyllWith rules provider store = do
55 -- Fetch the routes
58 -- Fetch the routes
56 route' = rulesRoute ruleSet
59 route' = rulesRoute ruleSet
57
60
61+ putStrLn "Writing dependency graph to dependencies.dot..."
62+ writeDot "dependencies.dot" show graph
63+
58 -- Generate all the targets in order
64 -- Generate all the targets in order
59 _ <- foldM (addTarget route') M.empty orderedTargets
65 _ <- foldM (addTarget route') M.empty orderedTargets
60
66
@@ -68,7 +74,9 @@ hakyllWith rules provider store = do
68 Nothing -> return ()
74 Nothing -> return ()
69 Just r -> do
75 Just r -> do
70 putStrLn $ "Routing " ++ show id' ++ " to " ++ r
76 putStrLn $ "Routing " ++ show id' ++ " to " ++ r
77+ let path = "_site" </> r
78+ makeDirectories path
71− write r compiled
79+ write path compiled
72
80
73 return $ M.insert id' compiled map'
81 return $ M.insert id' compiled map'
74
82