@@ -2,7 +2,7 @@
2-- | This module provides a declarative DSL in which the user can specify the
2-- | This module provides a declarative DSL in which the user can specify the
3-- different rules used to run the compilers.
3-- different rules used to run the compilers.
5−-- The convention is to just list all items in the 'RulesM' monad, routes and
5+-- The convention is to just list all items in the 'Rules' monad, routes and
6-- compilation rules.
6-- compilation rules.
8-- A typical usage example would be:
8-- A typical usage example would be:
@@ -17,8 +17,7 @@
17{-# LANGUAGE GeneralizedNewtypeDeriving #-}
17{-# LANGUAGE GeneralizedNewtypeDeriving #-}
18{-# LANGUAGE OverloadedStrings #-}
18{-# LANGUAGE OverloadedStrings #-}
19module Hakyll.Core.Rules
19module Hakyll.Core.Rules
@@ -31,7 +30,7 @@ module Hakyll.Core.Rules
32--------------------------------------------------------------------------------
31--------------------------------------------------------------------------------
33import Control.Applicative ((<$>))
32import Control.Applicative ((<$>))
34−import Control.Arrow ((***))
33+import Control.Arrow (second)
35import Control.Monad.Reader (ask, local)
34import Control.Monad.Reader (ask, local)
36import Control.Monad.State (get, put)
35import Control.Monad.State (get, put)
37import Control.Monad.Writer (tell)
36import Control.Monad.Writer (tell)
@@ -57,36 +56,36 @@ import Hakyll.Core.Writable
58--------------------------------------------------------------------------------
57--------------------------------------------------------------------------------
59-- | Add a route
58-- | Add a route
60−tellRoute :: Routes -> Rules
59+tellRoute :: Routes -> Rules ()
61−tellRoute route' = RulesM $ tell $ RuleSet route' mempty mempty
60+tellRoute route' = Rules $ tell $ RuleSet route' mempty mempty
64--------------------------------------------------------------------------------
63--------------------------------------------------------------------------------
65-- | Add a number of compilers
64-- | Add a number of compilers
66tellCompilers :: (Binary a, Typeable a, Writable a)
65tellCompilers :: (Binary a, Typeable a, Writable a)
67− => [(Identifier a, Compiler a)]
66+ => [(Identifier, Compiler a)]
68− -> Rules
67+ -> Rules ()
69−tellCompilers compilers = RulesM $ do
68+tellCompilers compilers = Rules $ do
70 -- We box the compilers so they have a more simple type
69 -- We box the compilers so they have a more simple type
71− let compilers' = map (castIdentifier *** fmap compiledItem) compilers
70+ let compilers' = map (second $ fmap compiledItem) compilers
72 tell $ RuleSet mempty compilers' mempty
71 tell $ RuleSet mempty compilers' mempty
75--------------------------------------------------------------------------------
74--------------------------------------------------------------------------------
76-- | Add resources
75-- | Add resources
77−tellResources :: [Identifier a]
76+tellResources :: [Identifier]
78− -> Rules
77+ -> Rules ()
79−tellResources resources' = RulesM $ tell $
78+tellResources resources' = Rules $ tell $
80− RuleSet mempty mempty $ S.fromList $ map castIdentifier resources'
79+ RuleSet mempty mempty $ S.fromList resources'
83--------------------------------------------------------------------------------
82--------------------------------------------------------------------------------
84-- | Only compile/route items satisfying the given predicate
83-- | Only compile/route items satisfying the given predicate
85−match :: Pattern a -> RulesM b -> RulesM b
84+match :: Pattern -> Rules b -> Rules b
86−match pattern = RulesM . local addPredicate . unRulesM
85+match pattern = Rules . local addPredicate . unRules
88 addPredicate env = env
87 addPredicate env = env
89− { rulesPattern = rulesPattern env `mappend` castPattern pattern
88+ { rulesPattern = rulesPattern env `mappend` pattern
@@ -120,8 +119,8 @@ match pattern = RulesM . local addPredicate . unRulesM
121-- This will put the compiler for the raw content in a separate group
120-- This will put the compiler for the raw content in a separate group
122-- (@\"raw\"@), which causes it to be compiled as well.
121-- (@\"raw\"@), which causes it to be compiled as well.
123−group :: String -> RulesM a -> RulesM a
122+group :: String -> Rules a -> Rules a
124−group g = RulesM . local setVersion' . unRulesM
123+group g = Rules . local setVersion' . unRules
126 setVersion' env = env {rulesVersion = Just g}
125 setVersion' env = env {rulesVersion = Just g}
@@ -133,12 +132,11 @@ group g = RulesM . local setVersion' . unRulesM
133-- no resources match the current selection, nothing will happen. In this case,
132-- no resources match the current selection, nothing will happen. In this case,
134-- you might want to have a look at 'create'.
133-- you might want to have a look at 'create'.
135compile :: (Binary a, Typeable a, Writable a)
134compile :: (Binary a, Typeable a, Writable a)
136− => Compiler a -> RulesM (Pattern a)
135+ => Compiler a -> Rules ()
137compile compiler = do
136compile compiler = do
138 ids <- resources
137 ids <- resources
139− tellCompilers [(castIdentifier id', compiler) | id' <- ids]
138+ tellCompilers [(id', compiler) | id' <- ids]
140 tellResources ids
139 tellResources ids
141− return $ fromList $ map castIdentifier ids
144--------------------------------------------------------------------------------
142--------------------------------------------------------------------------------
@@ -151,33 +149,32 @@ compile compiler = do
151-- replaced by the group set via 'group' (or 'Nothing', if 'group' has not been
149-- replaced by the group set via 'group' (or 'Nothing', if 'group' has not been
153create :: (Binary a, Typeable a, Writable a)
151create :: (Binary a, Typeable a, Writable a)
154− => Identifier a -> Compiler a -> RulesM (Identifier a)
152+ => Identifier -> Compiler a -> Rules ()
155−create id' compiler = RulesM $ do
153+create id' compiler = Rules $ do
156 version' <- rulesVersion <$> ask
154 version' <- rulesVersion <$> ask
157 let id'' = setVersion version' id'
155 let id'' = setVersion version' id'
158− unRulesM $ tellCompilers [(id'', compiler)]
156+ unRules $ tellCompilers [(id'', compiler)]
162--------------------------------------------------------------------------------
159--------------------------------------------------------------------------------
163-- | Add a route.
160-- | Add a route.
165-- This adds a route for all items matching the current pattern.
162-- This adds a route for all items matching the current pattern.
166−route :: Routes -> Rules
163+route :: Routes -> Rules ()
167−route route' = RulesM $ do
164+route route' = Rules $ do
168 -- We want the route only to be applied if we match the current pattern and
165 -- We want the route only to be applied if we match the current pattern and
169 -- version
166 -- version
170 pattern <- rulesPattern <$> ask
167 pattern <- rulesPattern <$> ask
171 version' <- rulesVersion <$> ask
168 version' <- rulesVersion <$> ask
172− unRulesM $ tellRoute $ matchRoute
169+ unRules $ tellRoute $ matchRoute
173 (pattern `mappend` fromVersion version') route'
170 (pattern `mappend` fromVersion version') route'
176--------------------------------------------------------------------------------
173--------------------------------------------------------------------------------
177-- | Get a list of resources matching the current pattern. This will also set
174-- | Get a list of resources matching the current pattern. This will also set
178-- the correct group to the identifiers.
175-- the correct group to the identifiers.
179−resources :: RulesM [Identifier ()]
176+resources :: Rules [Identifier]
180−resources = RulesM $ do
177+resources = Rules $ do
181 pattern <- rulesPattern <$> ask
178 pattern <- rulesPattern <$> ask
182 provider <- rulesResourceProvider <$> ask
179 provider <- rulesResourceProvider <$> ask
183 g <- rulesVersion <$> ask
180 g <- rulesVersion <$> ask
@@ -187,9 +184,9 @@ resources = RulesM $ do
187--------------------------------------------------------------------------------
184--------------------------------------------------------------------------------
188-- | Generate a fresh Identifier with a given prefix
185-- | Generate a fresh Identifier with a given prefix
189-- TODO: remove?
186-- TODO: remove?
190−freshIdentifier :: String -- ^ Prefix
187+freshIdentifier :: String -- ^ Prefix
191− -> RulesM (Identifier a) -- ^ Fresh identifier
188+ -> Rules Identifier -- ^ Fresh identifier
192−freshIdentifier prefix = RulesM $ do
189+freshIdentifier prefix = Rules $ do
193 state <- get
190 state <- get
194 let index = rulesNextIdentifier state
191 let index = rulesNextIdentifier state
195 id' = fromFilePath $ prefix ++ "/" ++ show index
192 id' = fromFilePath $ prefix ++ "/" ++ show index