@@ -25,15 +25,13 @@ module Hakyll.Core.Rules
2525 , create
2626 , route
2727 , resources
28− , metaCompile
29− , metaCompileWith
3028 , freshIdentifier
3129 ) where
3230
3331
3432--------------------------------------------------------------------------------
3533import Control.Applicative ((<$>))
36−import Control.Arrow (arr, (***), (>>>), (>>^))
34+import Control.Arrow (arr, (***), (>>>))
3735import Control.Monad.Reader (ask, local)
3836import Control.Monad.State (get, put)
3937import Control.Monad.Writer (tell)
@@ -73,7 +71,7 @@ tellCompilers compilers = RulesM $ do
7371 let compilers' = map (castIdentifier *** boxCompiler) compilers
7472 tell $ RuleSet mempty compilers' mempty
7573 where
76− boxCompiler = (>>> arr compiledItem >>> arr CompileRule)
74+ boxCompiler = (>>> arr compiledItem)
7775
7876
7977--------------------------------------------------------------------------------
@@ -187,73 +185,9 @@ resources = RulesM $ do
187185 return $ filterMatches pattern $ map (setGroup g) $ resourceList provider
188186
189187
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.
194−--
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.
198−--
199−-- Every post has a collection of tags. For example,
200−--
201−-- > post1: code, haskell
202−-- > post2: code, random
203−--
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.
208−--
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.
211−--
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.
216−--
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
223− -> Rules
224− -- ^ Resulting rules
225−metaCompile compiler = do
226− id' <- freshIdentifier "Hakyll.Core.Rules.metaCompile"
227− metaCompileWith id' compiler
228−
229−
230−--------------------------------------------------------------------------------
231−-- | Version of 'metaCompile' that allows you to specify a custom identifier for
232−-- the metacompiler.
233−metaCompileWith :: (Binary a, Typeable a, Writable a)
234− => Identifier ()
235− -- ^ Identifier for this compiler
236− -> Compiler () [(Identifier a, Compiler () a)]
237− -- ^ Compiler generating the other compilers
238− -> Rules
239− -- ^ Resulting rules
240−metaCompileWith identifier compiler = RulesM $ do
241− group' <- rulesGroup <$> ask
242−
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 )]
251−
252− tell $ RuleSet mempty compilers mempty
253−
254−
255188--------------------------------------------------------------------------------
256189-- | Generate a fresh Identifier with a given prefix
190+-- TODO: remove?
257191freshIdentifier :: String -- ^ Prefix
258192 -> RulesM (Identifier a) -- ^ Fresh identifier
259193freshIdentifier prefix = RulesM $ do