@@ -8,8 +8,10 @@ module Hakyll.Core.Compiler
9 , getResourceString
9 , getResourceString
10 , fromDependency
10 , fromDependency
12 , requireA
13 , requireA
13 , requireAll
15 , requireAll
14 , requireAllA
16 , requireAllA
@@ -17,11 +19,11 @@ module Hakyll.Core.Compiler
19import Prelude hiding ((.), id)
21import Prelude hiding ((.), id)
20−import Control.Arrow ((>>>))
22+import Control.Arrow ((>>>), (&&&), arr)
21import Control.Applicative ((<$>))
23import Control.Applicative ((<$>))
22import Control.Monad.Reader (ask)
24import Control.Monad.Reader (ask)
23import Control.Monad.Trans (liftIO)
25import Control.Monad.Trans (liftIO)
24−import Control.Category (Category, (.))
26+import Control.Category (Category, (.), id)
25import Data.Maybe (fromMaybe)
27import Data.Maybe (fromMaybe)
27import Data.Binary (Binary)
29import Data.Binary (Binary)
@@ -85,7 +87,7 @@ getResourceString = getIdentifier >>> getResourceString'
85-- | Auxiliary: get a dependency
87-- | Auxiliary: get a dependency
87getDependency :: (Binary a, Writable a, Typeable a)
89getDependency :: (Binary a, Writable a, Typeable a)
88− => Identifier -> CompilerM a
90+ => Identifier -> CompilerM a
89getDependency identifier = CompilerM $ do
91getDependency identifier = CompilerM $ do
90 store <- compilerStore <$> ask
92 store <- compilerStore <$> ask
91 fmap (fromMaybe error') $ liftIO $
93 fmap (fromMaybe error') $ liftIO $
@@ -96,6 +98,15 @@ getDependency identifier = CompilerM $ do
96 ++ " not found in the cache, the cache might be corrupted or"
98 ++ " not found in the cache, the cache might be corrupted or"
97 ++ " the item you are referring to might not exist"
99 ++ " the item you are referring to might not exist"
102+-- | Variant of 'require' which drops the current value
104+require_ :: (Binary a, Typeable a, Writable a)
107+require_ identifier =
108+ fromDependency identifier >>> fromJob (const $ getDependency identifier)
99-- | Require another target. Using this function ensures automatic handling of
110-- | Require another target. Using this function ensures automatic handling of
100-- dependencies
111-- dependencies
@@ -103,12 +114,7 @@ require :: (Binary a, Typeable a, Writable a)
103 => Identifier
114 => Identifier
104 -> (b -> a -> c)
115 -> (b -> a -> c)
105 -> Compiler b c
116 -> Compiler b c
106−require identifier f =
117+require identifier = requireA identifier . arr . uncurry
107− fromDependency identifier >>> fromJob require'
110− y <- getDependency identifier
113-- | Arrow-based variant of 'require'
119-- | Arrow-based variant of 'require'
@@ -116,7 +122,19 @@ requireA :: (Binary a, Typeable a, Writable a)
116 => Identifier
122 => Identifier
117 -> Compiler (b, a) c
123 -> Compiler (b, a) c
118 -> Compiler b c
124 -> Compiler b c
119−requireA identifier = (require identifier (,) >>>)
125+requireA identifier = (id &&& require_ identifier >>>)
127+-- | Variant of 'requireAll' which drops the current value
129+requireAll_ :: (Binary a, Typeable a, Writable a)
132+requireAll_ pattern = fromDependencies getDeps >>> fromJob requireAll_'
134+ getDeps = matches pattern . resourceList
135+ requireAll_' = const $ CompilerM $ do
136+ deps <- getDeps . compilerResourceProvider <$> ask
137+ mapM (unCompilerM . getDependency) deps
121-- | Require a number of targets. Using this function ensures automatic handling
139-- | Require a number of targets. Using this function ensures automatic handling
122-- of dependencies
140-- of dependencies
@@ -125,14 +143,7 @@ requireAll :: (Binary a, Typeable a, Writable a)
125 => Pattern
143 => Pattern
126 -> (b -> [a] -> c)
144 -> (b -> [a] -> c)
127 -> Compiler b c
145 -> Compiler b c
128−requireAll pattern f =
146+requireAll pattern = requireAllA pattern . arr . uncurry
129− fromDependencies getDeps >>> fromJob requireAll'
131− getDeps = matches pattern . resourceList
132− requireAll' x = CompilerM $ do
133− deps <- getDeps . compilerResourceProvider <$> ask
134− items <- mapM (unCompilerM . getDependency) deps
137-- | Arrow-based variant of 'requireAll'
148-- | Arrow-based variant of 'requireAll'
@@ -140,7 +151,7 @@ requireAllA :: (Binary a, Typeable a, Writable a)
140 => Pattern
151 => Pattern
141 -> Compiler (b, [a]) c
152 -> Compiler (b, [a]) c
142 -> Compiler b c
153 -> Compiler b c
143−requireAllA pattern = (requireAll pattern (,) >>>)
154+requireAllA pattern = (id &&& requireAll_ pattern >>>)
145cached :: (Binary a, Typeable a, Writable a)
156cached :: (Binary a, Typeable a, Writable a)
146 => String
157 => String