@@ -19,6 +19,7 @@ module Hakyll.Core.Rules
1919 ( RulesM
2020 , Rules
2121 , match
22+ , group
2223 , compile
2324 , create
2425 , route
@@ -29,7 +30,7 @@ module Hakyll.Core.Rules
2930import Control.Applicative ((<$>))
3031import Control.Monad.Writer (tell)
3132import Control.Monad.Reader (ask, local)
32−import Control.Arrow (second, (>>>), arr, (>>^))
33+import Control.Arrow (second, (>>>), arr, (>>^), (***))
3334import Control.Monad.State (get, put)
3435import Data.Monoid (mempty, mappend)
3536import qualified Data.Set as S
@@ -58,16 +59,21 @@ tellRoute route' = RulesM $ tell $ RuleSet route' mempty mempty
5859tellCompilers :: (Binary a, Typeable a, Writable a)
5960 => [(Identifier, Compiler () a)]
6061 -> Rules
61−tellCompilers compilers = RulesM $ tell $ RuleSet mempty compilers' mempty
62+tellCompilers compilers = RulesM $ do
63+ -- We box the compilers so they have a more simple type, and we apply the
64+ -- current group to the corresponding identifiers
65+ group' <- rulesGroup <$> ask
66+ let compilers' = map (setGroup group' *** boxCompiler) compilers
67+ tell $ RuleSet mempty compilers' mempty
6268 where
63− compilers' = map (second boxCompiler) compilers
6469 boxCompiler = (>>> arr compiledItem >>> arr CompileRule)
6570
6671-- | Add resources
6772--
6873tellResources :: [Resource]
6974 -> Rules
70−tellResources resources = RulesM $ tell $ RuleSet mempty mempty $ S.fromList resources
75+tellResources resources = RulesM $ tell $
76+ RuleSet mempty mempty $ S.fromList resources
7177
7278-- | Only compile/route items satisfying the given predicate
7379--
@@ -78,6 +84,13 @@ match pattern = RulesM . local addPredicate . unRulesM
7884 { rulesPattern = rulesPattern env `mappend` pattern
7985 }
8086
87+-- | Greate a group of compilers
88+--
89+group :: String -> Rules -> Rules
90+group g = RulesM . local setGroup' . unRulesM
91+ where
92+ setGroup' env = env { rulesGroup = Just g }
93+
8194-- | Add a compilation rule to the rules.
8295--
8396-- This instructs all resources to be compiled using the given compiler. When
@@ -112,8 +125,11 @@ create identifier compiler = tellCompilers [(identifier, compiler)]
112125--
113126route :: Routes -> Rules
114127route route' = RulesM $ do
128+ -- We want the route only to be applied if we match the current pattern and
129+ -- group
115130 pattern <- rulesPattern <$> ask
116− unRulesM $ tellRoute $ matchRoute pattern route'
131+ group' <- rulesGroup <$> ask
132+ unRulesM $ tellRoute $ matchRoute (pattern `mappend` inGroup group') route'
117133
118134-- | Apart from regular compilers, one is also able to specify metacompilers.
119135-- Metacompilers are a special class of compilers: they are compilers which
@@ -154,7 +170,7 @@ metaCompile compiler = RulesM $ do
154170 -- Create an identifier from the state
155171 state <- get
156172 let index = rulesMetaCompilerIndex state
157− id' = fromCaptureString "Hakyll.Core.Rules.metaCompile/*" (show index)
173+ id' = fromCapture "Hakyll.Core.Rules.metaCompile/*" (show index)
158174
159175 -- Update the state with a new identifier
160176 put $ state {rulesMetaCompilerIndex = index + 1}
@@ -172,9 +188,16 @@ metaCompileWith :: (Binary a, Typeable a, Writable a)
172188 -- ^ Compiler generating the other compilers
173189 -> Rules
174190 -- ^ Resulting rules
175−metaCompileWith identifier compiler = RulesM $ tell $
176− RuleSet mempty compilers mempty
177− where
178− makeRule = MetaCompileRule . map (second box)
179− compilers = [(identifier, compiler >>> arr makeRule )]
180− box = (>>> fromDependency identifier >>^ CompileRule . compiledItem)
191+metaCompileWith identifier compiler = RulesM $ do
192+ group' <- rulesGroup <$> ask
193+
194+ let -- Set the correct group on the identifier
195+ id' = setGroup group' identifier
196+ -- Function to box an item into a rule
197+ makeRule = MetaCompileRule . map (second box)
198+ -- Entire boxing function
199+ box = (>>> fromDependency id' >>^ CompileRule . compiledItem)
200+ -- Resulting compiler list
201+ compilers = [(id', compiler >>> arr makeRule )]
202+
203+ tell $ RuleSet mempty compilers mempty