summaryrefslogtreecommitdiff
path: root/src/Hakyll/Core/Rules.hs
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2011-02-15 18:32:55 +0100
committerJasper Van der Jeugt <jaspervdj@gmail.com>2011-02-15 18:32:55 +0100
commit5a591ee24c50ed25702c06f8f811189984e443ea (patch)
tree3f112517c7042e11e3bd475fb4849c515d789835 /src/Hakyll/Core/Rules.hs
parentabfb4c19195cf305637f1a9acd7f6dd70d59b831 (diff)
downloadhakyll-5a591ee24c50ed25702c06f8f811189984e443ea.tar.gz
Rules DSL tracks resources used
Diffstat (limited to 'src/Hakyll/Core/Rules.hs')
-rw-r--r--src/Hakyll/Core/Rules.hs24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/Hakyll/Core/Rules.hs b/src/Hakyll/Core/Rules.hs
index 137dc2c..1aa3ad3 100644
--- a/src/Hakyll/Core/Rules.hs
+++ b/src/Hakyll/Core/Rules.hs
@@ -27,6 +27,7 @@ import Control.Monad.Reader (ask)
import Control.Arrow (second, (>>>), arr, (>>^))
import Control.Monad.State (get, put)
import Data.Monoid (mempty)
+import qualified Data.Set as S
import Data.Typeable (Typeable)
import Data.Binary (Binary)
@@ -44,18 +45,24 @@ import Hakyll.Core.Util.Arrow
-- | Add a route
--
tellRoute :: Routes -> Rules
-tellRoute route' = RulesM $ tell $ RuleSet route' mempty
+tellRoute route' = RulesM $ tell $ RuleSet route' mempty mempty
-- | Add a number of compilers
--
tellCompilers :: (Binary a, Typeable a, Writable a)
=> [(Identifier, Compiler () a)]
-> Rules
-tellCompilers compilers = RulesM $ tell $ RuleSet mempty $
- map (second boxCompiler) compilers
+tellCompilers compilers = RulesM $ tell $ RuleSet mempty compilers' mempty
where
+ compilers' = map (second boxCompiler) compilers
boxCompiler = (>>> arr compiledItem >>> arr CompileRule)
+-- | Add resources
+--
+tellResources :: [Resource]
+ -> Rules
+tellResources resources = RulesM $ tell $ RuleSet mempty mempty $ S.fromList resources
+
-- | Add a compilation rule to the rules.
--
-- This instructs all resources matching the given pattern to be compiled using
@@ -66,8 +73,10 @@ compile :: (Binary a, Typeable a, Writable a)
=> Pattern -> Compiler Resource a -> Rules
compile pattern compiler = RulesM $ do
identifiers <- matches pattern . map unResource . resourceList <$> ask
- unRulesM $ tellCompilers $ flip map identifiers $ \identifier ->
- (identifier, constA (Resource identifier) >>> compiler)
+ unRulesM $ do
+ tellCompilers $ flip map identifiers $ \identifier ->
+ (identifier, constA (Resource identifier) >>> compiler)
+ tellResources $ map Resource identifiers
-- | Add a compilation rule
--
@@ -125,8 +134,9 @@ metaCompileWith :: (Binary a, Typeable a, Writable a)
-- ^ Compiler generating the other compilers
-> Rules
-- ^ Resulting rules
-metaCompileWith identifier compiler = RulesM $ tell $ RuleSet mempty
- [(identifier, compiler >>> arr makeRule )]
+metaCompileWith identifier compiler = RulesM $ tell $
+ RuleSet mempty compilers mempty
where
makeRule = MetaCompileRule . map (second box)
+ compilers = [(identifier, compiler >>> arr makeRule )]
box = (>>> fromDependency identifier >>^ CompileRule . compiledItem)