@@ -26,6 +26,7 @@ module Hakyll.Core.Rules
2626 , resources
2727 , metaCompile
2828 , metaCompileWith
29+ , freshIdentifier
2930 ) where
3031
3132import Control.Applicative ((<$>))
@@ -208,17 +209,9 @@ metaCompile :: (Binary a, Typeable a, Writable a)
208209 -- ^ Compiler generating the other compilers
209210 -> Rules
210211 -- ^ Resulting rules
211−metaCompile compiler = RulesM $ do
212− -- Create an identifier from the state
213− state <- get
214− let index = rulesMetaCompilerIndex state
215− id' = fromCapture "Hakyll.Core.Rules.metaCompile/*" (show index)
216−
217− -- Update the state with a new identifier
218− put $ state {rulesMetaCompilerIndex = index + 1}
219−
220− -- Fallback to 'metaCompileWith' with now known identifier
221− unRulesM $ metaCompileWith id' compiler
212+metaCompile compiler = do
213+ id' <- freshIdentifier "Hakyll.Core.Rules.metaCompile"
214+ metaCompileWith id' compiler
222215
223216-- | Version of 'metaCompile' that allows you to specify a custom identifier for
224217-- the metacompiler.
@@ -243,3 +236,13 @@ metaCompileWith identifier compiler = RulesM $ do
243236 compilers = [(id', compiler >>> arr makeRule )]
244237
245238 tell $ RuleSet mempty compilers mempty
239+
240+-- | Generate a fresh Identifier with a given prefix
241+freshIdentifier :: String -- ^ Prefix
242+ -> RulesM (Identifier a) -- ^ Fresh identifier
243+freshIdentifier prefix = RulesM $ do
244+ state <- get
245+ let index = rulesNextIdentifier state
246+ id' = parseIdentifier $ prefix ++ "/" ++ show index
247+ put $ state {rulesNextIdentifier = index + 1}
248+ return id'