@@ -26,6 +26,7 @@ module Hakyll.Core.Rules
26 , resources
26 , resources
27 , metaCompile
27 , metaCompile
28 , metaCompileWith
28 , metaCompileWith
31import Control.Applicative ((<$>))
32import Control.Applicative ((<$>))
@@ -208,17 +209,9 @@ metaCompile :: (Binary a, Typeable a, Writable a)
208 -- ^ Compiler generating the other compilers
209 -- ^ Compiler generating the other compilers
210 -- ^ Resulting rules
211 -- ^ Resulting rules
211−metaCompile compiler = RulesM $ do
212+metaCompile compiler = do
212− -- Create an identifier from the state
214− let index = rulesMetaCompilerIndex state
215− id' = fromCapture "Hakyll.Core.Rules.metaCompile/*" (show index)
213+ id' <- freshIdentifier "Hakyll.Core.Rules.metaCompile"
217− -- Update the state with a new identifier
218− put $ state {rulesMetaCompilerIndex = index + 1}
220− -- Fallback to 'metaCompileWith' with now known identifier
221− unRulesM $ metaCompileWith id' compiler
214+ metaCompileWith id' compiler
223-- | Version of 'metaCompile' that allows you to specify a custom identifier for
216-- | Version of 'metaCompile' that allows you to specify a custom identifier for
224-- the metacompiler.
217-- the metacompiler.
@@ -243,3 +236,13 @@ metaCompileWith identifier compiler = RulesM $ do
243 compilers = [(id', compiler >>> arr makeRule )]
236 compilers = [(id', compiler >>> arr makeRule )]
245 tell $ RuleSet mempty compilers mempty
238 tell $ RuleSet mempty compilers mempty
240+-- | Generate a fresh Identifier with a given prefix
241+freshIdentifier :: String -- ^ Prefix
242+ -> RulesM (Identifier a) -- ^ Fresh identifier
243+freshIdentifier prefix = RulesM $ do
245+ let index = rulesNextIdentifier state
246+ id' = parseIdentifier $ prefix ++ "/" ++ show index
247+ put $ state {rulesNextIdentifier = index + 1}