@@ -19,6 +19,7 @@ module Hakyll.Core.Rules
@@ -29,7 +30,7 @@ module Hakyll.Core.Rules
29import Control.Applicative ((<$>))
30import Control.Applicative ((<$>))
30import Control.Monad.Writer (tell)
31import Control.Monad.Writer (tell)
31import Control.Monad.Reader (ask, local)
32import Control.Monad.Reader (ask, local)
32−import Control.Arrow (second, (>>>), arr, (>>^))
33+import Control.Arrow (second, (>>>), arr, (>>^), (***))
33import Control.Monad.State (get, put)
34import Control.Monad.State (get, put)
34import Data.Monoid (mempty, mappend)
35import Data.Monoid (mempty, mappend)
35import qualified Data.Set as S
36import qualified Data.Set as S
@@ -58,16 +59,21 @@ tellRoute route' = RulesM $ tell $ RuleSet route' mempty mempty
58tellCompilers :: (Binary a, Typeable a, Writable a)
59tellCompilers :: (Binary a, Typeable a, Writable a)
59 => [(Identifier, Compiler () a)]
60 => [(Identifier, Compiler () a)]
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
61−tellCompilers compilers = RulesM $ tell $ RuleSet mempty compilers' mempty
67+ tell $ RuleSet mempty compilers' mempty
63− compilers' = map (second boxCompiler) compilers
64 boxCompiler = (>>> arr compiledItem >>> arr CompileRule)
69 boxCompiler = (>>> arr compiledItem >>> arr CompileRule)
66-- | Add resources
71-- | Add resources
68tellResources :: [Resource]
73tellResources :: [Resource]
75+tellResources resources = RulesM $ tell $
70−tellResources resources = RulesM $ tell $ RuleSet mempty mempty $ S.fromList resources
76+ RuleSet mempty mempty $ S.fromList resources
72-- | Only compile/route items satisfying the given predicate
78-- | Only compile/route items satisfying the given predicate
@@ -78,6 +84,13 @@ match pattern = RulesM . local addPredicate . unRulesM
78 { rulesPattern = rulesPattern env `mappend` pattern
84 { rulesPattern = rulesPattern env `mappend` pattern
87+-- | Greate a group of compilers
89+group :: String -> Rules -> Rules
90+group g = RulesM . local setGroup' . unRulesM
92+ setGroup' env = env { rulesGroup = Just g }
81-- | Add a compilation rule to the rules.
94-- | Add a compilation rule to the rules.
83-- This instructs all resources to be compiled using the given compiler. When
96-- This instructs all resources to be compiled using the given compiler. When
@@ -112,8 +125,11 @@ create identifier compiler = tellCompilers [(identifier, compiler)]
113route :: Routes -> Rules
126route :: Routes -> Rules
114route route' = RulesM $ do
127route route' = RulesM $ do
128+ -- We want the route only to be applied if we match the current pattern and
115 pattern <- rulesPattern <$> ask
130 pattern <- rulesPattern <$> ask
131+ group' <- rulesGroup <$> ask
116− unRulesM $ tellRoute $ matchRoute pattern route'
132+ unRulesM $ tellRoute $ matchRoute (pattern `mappend` inGroup group') route'
118-- | Apart from regular compilers, one is also able to specify metacompilers.
134-- | Apart from regular compilers, one is also able to specify metacompilers.
119-- Metacompilers are a special class of compilers: they are compilers which
135-- Metacompilers are a special class of compilers: they are compilers which
@@ -154,7 +170,7 @@ metaCompile compiler = RulesM $ do
154 -- Create an identifier from the state
170 -- Create an identifier from the state
155 state <- get
171 state <- get
156 let index = rulesMetaCompilerIndex state
172 let index = rulesMetaCompilerIndex state
157− id' = fromCaptureString "Hakyll.Core.Rules.metaCompile/*" (show index)
173+ id' = fromCapture "Hakyll.Core.Rules.metaCompile/*" (show index)
159 -- Update the state with a new identifier
175 -- Update the state with a new identifier
160 put $ state {rulesMetaCompilerIndex = index + 1}
176 put $ state {rulesMetaCompilerIndex = index + 1}
@@ -172,9 +188,16 @@ metaCompileWith :: (Binary a, Typeable a, Writable a)
172 -- ^ Compiler generating the other compilers
188 -- ^ Compiler generating the other compilers
174 -- ^ Resulting rules
190 -- ^ Resulting rules
175−metaCompileWith identifier compiler = RulesM $ tell $
191+metaCompileWith identifier compiler = RulesM $ do
176− RuleSet mempty compilers mempty
192+ group' <- rulesGroup <$> ask
194+ let -- Set the correct group on the identifier
195+ id' = setGroup group' identifier
196+ -- Function to box an item into a rule
178− makeRule = MetaCompileRule . map (second box)
197+ makeRule = MetaCompileRule . map (second box)
198+ -- Entire boxing function
199+ box = (>>> fromDependency id' >>^ CompileRule . compiledItem)
200+ -- Resulting compiler list
179− compilers = [(identifier, compiler >>> arr makeRule )]
201+ compilers = [(id', compiler >>> arr makeRule )]
180− box = (>>> fromDependency identifier >>^ CompileRule . compiledItem)
202+
203+ tell $ RuleSet mempty compilers mempty