diff options
author | Jasper Van der Jeugt <m@jaspervdj.be> | 2014-10-28 10:53:35 +0100 |
---|---|---|
committer | Jasper Van der Jeugt <m@jaspervdj.be> | 2014-10-28 10:53:35 +0100 |
commit | 3c15d0fd34e6fd8b2a2c2c9185f5554fc266efbc (patch) | |
tree | bf432a6b50d14dded357bce08c68a0a3cdb20563 /src | |
parent | 24e0c1a91858832ad8d37feaabf3b30dc1027230 (diff) | |
download | hakyll-3c15d0fd34e6fd8b2a2c2c9185f5554fc266efbc.tar.gz |
Improve rulesExtraDependencies usage
Diffstat (limited to 'src')
-rw-r--r-- | src/Hakyll/Core/Rules.hs | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/src/Hakyll/Core/Rules.hs b/src/Hakyll/Core/Rules.hs index c248a9b..1b1e4ae 100644 --- a/src/Hakyll/Core/Rules.hs +++ b/src/Hakyll/Core/Rules.hs @@ -181,10 +181,32 @@ preprocess = Rules . liftIO -- -- A useful utility for this purpose is 'makePatternDependency'. rulesExtraDependencies :: [Dependency] -> Rules a -> Rules a -rulesExtraDependencies deps = Rules . censor addDependencies . unRules +rulesExtraDependencies deps rules = + -- Note that we add the dependencies seemingly twice here. However, this is + -- done so that 'rulesExtraDependencies' works both if we have something + -- like: + -- + -- > match "*.css" $ rulesExtraDependencies [foo] $ ... + -- + -- and something like: + -- + -- > rulesExtraDependencies [foo] $ match "*.css" $ ... + -- + -- (1) takes care of the latter and (2) of the former. + Rules $ censor fixRuleSet $ do + x <- unRules rules + fixCompiler + return x where - -- Adds the dependencies to the compilers in the ruleset - addDependencies ruleSet = ruleSet + -- (1) Adds the dependencies to the compilers we are yet to create + fixCompiler = modify $ \s -> case rulesCompiler s of + Nothing -> s + Just c -> s + { rulesCompiler = Just $ compilerTellDependencies deps >> c + } + + -- (2) Adds the dependencies to the compilers that are already in the ruleset + fixRuleSet ruleSet = ruleSet { rulesCompilers = [ (i, compilerTellDependencies deps >> c) | (i, c) <- rulesCompilers ruleSet |