on master help sign in
Rules DSL tracks resources used
commit5a591ee24c50ed25702c06f8f811189984e443ea authorJasper Van der Jeugt <jaspervdj@gmail.com> dateTue 15 Feb 2011, 18:32 (16 years ago) parentabfb4c1
2 files changed+27−12
src/Hakyll/Core/Rules.hs+17−7 src/Hakyll/Core/Rules/Internal.hs+10−5
src/Hakyll/Core/Rules.hs+17−7
@@ -27,6 +27,7 @@ import Control.Monad.Reader (ask)
2727import Control.Arrow (second, (>>>), arr, (>>^))
2828import Control.Monad.State (get, put)
2929import Data.Monoid (mempty)
30+import qualified Data.Set as S
3031
3132import Data.Typeable (Typeable)
3233import Data.Binary (Binary)
@@ -44,18 +45,24 @@ import Hakyll.Core.Util.Arrow
4445-- | Add a route
4546--
4647tellRoute :: Routes -> Rules
47−tellRoute route' = RulesM $ tell $ RuleSet route' mempty
48+tellRoute route' = RulesM $ tell $ RuleSet route' mempty mempty
4849
4950-- | Add a number of compilers
5051--
5152tellCompilers :: (Binary a, Typeable a, Writable a)
5253 => [(Identifier, Compiler () a)]
5354 -> Rules
54−tellCompilers compilers = RulesM $ tell $ RuleSet mempty $
55− map (second boxCompiler) compilers
55+tellCompilers compilers = RulesM $ tell $ RuleSet mempty compilers' mempty
5656 where
57+ compilers' = map (second boxCompiler) compilers
5758 boxCompiler = (>>> arr compiledItem >>> arr CompileRule)
5859
60+-- | Add resources
61+--
62+tellResources :: [Resource]
63+ -> Rules
64+tellResources resources = RulesM $ tell $ RuleSet mempty mempty $ S.fromList resources
65+
5966-- | Add a compilation rule to the rules.
6067--
6168-- This instructs all resources matching the given pattern to be compiled using
@@ -66,8 +73,10 @@ compile :: (Binary a, Typeable a, Writable a)
6673 => Pattern -> Compiler Resource a -> Rules
6774compile pattern compiler = RulesM $ do
6875 identifiers <- matches pattern . map unResource . resourceList <$> ask
69− unRulesM $ tellCompilers $ flip map identifiers $ \identifier ->
70− (identifier, constA (Resource identifier) >>> compiler)
76+ unRulesM $ do
77+ tellCompilers $ flip map identifiers $ \identifier ->
78+ (identifier, constA (Resource identifier) >>> compiler)
79+ tellResources $ map Resource identifiers
7180
7281-- | Add a compilation rule
7382--
@@ -125,8 +134,9 @@ metaCompileWith :: (Binary a, Typeable a, Writable a)
125134 -- ^ Compiler generating the other compilers
126135 -> Rules
127136 -- ^ Resulting rules
128−metaCompileWith identifier compiler = RulesM $ tell $ RuleSet mempty
129− [(identifier, compiler >>> arr makeRule )]
137+metaCompileWith identifier compiler = RulesM $ tell $
138+ RuleSet mempty compilers mempty
130139 where
131140 makeRule = MetaCompileRule . map (second box)
141+ compilers = [(identifier, compiler >>> arr makeRule )]
132142 box = (>>> fromDependency identifier >>^ CompileRule . compiledItem)
src/Hakyll/Core/Rules/Internal.hs+10−5
@@ -15,6 +15,7 @@ import Control.Monad.Writer (WriterT, execWriterT)
1515import Control.Monad.Reader (ReaderT, runReaderT)
1616import Control.Monad.State (State, evalState)
1717import Data.Monoid (Monoid, mempty, mappend)
18+import Data.Set (Set)
1819
1920import Hakyll.Core.ResourceProvider
2021import Hakyll.Core.Identifier
@@ -35,14 +36,18 @@ data CompileRule = CompileRule CompiledItem
3536-- | A collection of rules for the compilation process
3637--
3738data RuleSet = RuleSet
38− { rulesRoutes :: Routes
39− , rulesCompilers :: [(Identifier, Compiler () CompileRule)]
39+ { -- | Routes used in the compilation structure
40+ rulesRoutes :: Routes
41+ , -- | Compilation rules
42+ rulesCompilers :: [(Identifier, Compiler () CompileRule)]
43+ , -- | A list of the used resources
44+ rulesResources :: Set Resource
4045 }
4146
4247instance Monoid RuleSet where
43− mempty = RuleSet mempty mempty
44− mappend (RuleSet r1 c1) (RuleSet r2 c2) =
45− RuleSet (mappend r1 r2) (mappend c1 c2)
48+ mempty = RuleSet mempty mempty mempty
49+ mappend (RuleSet r1 c1 s1) (RuleSet r2 c2 s2) =
50+ RuleSet (mappend r1 r2) (mappend c1 c2) (mappend s1 s2)
4651
4752-- | Rule state
4853--