@@ -25,15 +25,13 @@ module Hakyll.Core.Rules
27 , resources
27 , resources
30 , freshIdentifier
28 , freshIdentifier
34--------------------------------------------------------------------------------
32--------------------------------------------------------------------------------
35import Control.Applicative ((<$>))
33import Control.Applicative ((<$>))
36−import Control.Arrow (arr, (***), (>>>), (>>^))
34+import Control.Arrow (arr, (***), (>>>))
37import Control.Monad.Reader (ask, local)
35import Control.Monad.Reader (ask, local)
38import Control.Monad.State (get, put)
36import Control.Monad.State (get, put)
39import Control.Monad.Writer (tell)
37import Control.Monad.Writer (tell)
@@ -73,7 +71,7 @@ tellCompilers compilers = RulesM $ do
73 let compilers' = map (castIdentifier *** boxCompiler) compilers
71 let compilers' = map (castIdentifier *** boxCompiler) compilers
74 tell $ RuleSet mempty compilers' mempty
72 tell $ RuleSet mempty compilers' mempty
76− boxCompiler = (>>> arr compiledItem >>> arr CompileRule)
74+ boxCompiler = (>>> arr compiledItem)
79--------------------------------------------------------------------------------
77--------------------------------------------------------------------------------
@@ -187,73 +185,9 @@ resources = RulesM $ do
187 return $ filterMatches pattern $ map (setGroup g) $ resourceList provider
185 return $ filterMatches pattern $ map (setGroup g) $ resourceList provider
190−--------------------------------------------------------------------------------
191−-- | Apart from regular compilers, one is also able to specify metacompilers.
192−-- Metacompilers are a special class of compilers: they are compilers which
193−-- produce other compilers.
195−-- This is needed when the list of compilers depends on something we cannot know
196−-- before actually running other compilers. The most typical example is if we
197−-- have a blogpost using tags.
199−-- Every post has a collection of tags. For example,
201−-- > post1: code, haskell
202−-- > post2: code, random
204−-- Now, we want to create a list of posts for every tag. We cannot write this
205−-- down in our 'Rules' DSL directly, since we don't know what tags the different
206−-- posts will have -- we depend on information that will only be available when
207−-- we are actually compiling the pages.
209−-- The solution is simple, using 'metaCompile', we can add a compiler that will
210−-- parse the pages and produce the compilers needed for the different tag pages.
212−-- And indeed, we can see that the first argument to 'metaCompile' is a
213−-- 'Compiler' which produces a list of ('Identifier', 'Compiler') pairs. The
214−-- idea is simple: 'metaCompile' produces a list of compilers, and the
215−-- corresponding identifiers.
217−-- For simple hakyll systems, it is no need for this construction. More
218−-- formally, it is only needed when the content of one or more items determines
219−-- which items must be rendered.
220−metaCompile :: (Binary a, Typeable a, Writable a)
221− => Compiler () [(Identifier a, Compiler () a)]
222− -- ^ Compiler generating the other compilers
224− -- ^ Resulting rules
225−metaCompile compiler = do
226− id' <- freshIdentifier "Hakyll.Core.Rules.metaCompile"
227− metaCompileWith id' compiler
230−--------------------------------------------------------------------------------
231−-- | Version of 'metaCompile' that allows you to specify a custom identifier for
233−metaCompileWith :: (Binary a, Typeable a, Writable a)
235− -- ^ Identifier for this compiler
236− -> Compiler () [(Identifier a, Compiler () a)]
237− -- ^ Compiler generating the other compilers
239− -- ^ Resulting rules
240−metaCompileWith identifier compiler = RulesM $ do
241− group' <- rulesGroup <$> ask
243− let -- Set the correct group on the identifier
244− id' = setGroup group' identifier
245− -- Function to box an item into a rule
246− makeRule = MetaCompileRule . map (castIdentifier *** box)
247− -- Entire boxing function
248− box = (>>> fromDependency id' >>^ CompileRule . compiledItem)
249− -- Resulting compiler list
250− compilers = [(id', compiler >>> arr makeRule )]
252− tell $ RuleSet mempty compilers mempty
255--------------------------------------------------------------------------------
188--------------------------------------------------------------------------------
256-- | Generate a fresh Identifier with a given prefix
189-- | Generate a fresh Identifier with a given prefix
257freshIdentifier :: String -- ^ Prefix
191freshIdentifier :: String -- ^ Prefix
258 -> RulesM (Identifier a) -- ^ Fresh identifier
192 -> RulesM (Identifier a) -- ^ Fresh identifier
259freshIdentifier prefix = RulesM $ do
193freshIdentifier prefix = RulesM $ do