on master help sign in
Simplify stuff
commit89272dd97f805695b3d03f9a9fb05d22f30d8a7d authorJasper Van der Jeugt <m@jaspervdj.be> dateTue 13 Nov 2012, 13:13 (14 years ago) parent760b434
14 files changed+112−170
src/Hakyll/Core/Compiler/Internal.hs+10−37 src/Hakyll/Core/Dependencies.hs+11−11 src/Hakyll/Core/Identifier.hs+8−16 src/Hakyll/Core/Identifier/Pattern.hs+18−31 src/Hakyll/Core/Metadata.hs+1−1 src/Hakyll/Core/ResourceProvider.hs+2−2 src/Hakyll/Core/ResourceProvider/Internal.hs+8−8 src/Hakyll/Core/ResourceProvider/Metadata.hs+1−1 src/Hakyll/Core/ResourceProvider/MetadataCache.hs+4−4 src/Hakyll/Core/ResourceProvider/Modified.hs+3−3 src/Hakyll/Core/Routes.hs+6−6 src/Hakyll/Core/Rules.hs+31−34 src/Hakyll/Core/Rules/Internal.hs+8−15 src/Hakyll/Core/Writable.hs+1−1
src/Hakyll/Core/Compiler/Internal.hs+10−37
@@ -4,7 +4,8 @@
44{-# LANGUAGE GeneralizedNewtypeDeriving #-}
55module Hakyll.Core.Compiler.Internal
66 ( CompilerRead (..)
7− , Compiler (..)
7+ , Compiler
8+ , runCompiler
89 , compilerTell
910 , compilerAsk
1011 , compilerThrow
@@ -31,11 +32,11 @@ import Hakyll.Core.Store
3132-- | Environment in which a compiler runs
3233data CompilerRead = CompilerRead
3334 { -- | Target identifier
34− compilerIdentifier :: Identifier ()
35+ compilerIdentifier :: Identifier
3536 , -- | Resource provider
3637 compilerResourceProvider :: ResourceProvider
3738 , -- | List of all known identifiers
38− compilerUniverse :: [Identifier ()]
39+ compilerUniverse :: [Identifier]
3940 , -- | Site routes
4041 compilerRoutes :: Routes
4142 , -- | Compiler store
@@ -55,7 +56,7 @@ type CompilerWrite = [Dependency]
5556data CompilerResult a where
5657 CompilerDone :: a -> CompilerWrite -> CompilerResult a
5758 CompilerError :: String -> CompilerResult a
58− CompilerRequire :: Identifier b -> (b -> Compiler a) -> CompilerResult a
59+ CompilerRequire :: Identifier -> (b -> Compiler a) -> CompilerResult a
5960
6061
6162--------------------------------------------------------------------------------
@@ -106,6 +107,11 @@ instance Applicative Compiler where
106107 {-# INLINE (<*>) #-}
107108
108109
110+--------------------------------------------------------------------------------
111+runCompiler :: Compiler a -> CompilerRead -> IO (CompilerResult a)
112+runCompiler = unCompiler
113+
114+
109115--------------------------------------------------------------------------------
110116instance Alternative Compiler where
111117 empty = compilerThrow "Hakyll.Core.Compiler.Internal: empty alternative"
@@ -139,36 +145,3 @@ compilerCatch (Compiler x) f = Compiler $ \r -> do
139145 CompilerError e -> unCompiler (f e) r
140146 _ -> return res
141147{-# INLINE compilerCatch #-}
142−
143−
144−{-
145−--------------------------------------------------------------------------------
146−-- | The compiler monad
147−newtype CompilerM a = CompilerM
148− { unCompilerM :: ErrorT String (ReaderT CompilerEnvironment IO) a
149− } deriving (Monad, Functor, Applicative)
150−
151−
152−--------------------------------------------------------------------------------
153−-- | The compiler arrow
154−data Compiler a = Compiler
155− { compilerDependencies :: Reader DependencyEnvironment Dependencies
156− , compilerJob :: CompilerM a
157− }
158−
159−
160−--------------------------------------------------------------------------------
161−instance Functor Compiler where
162− fmap f (Compiler d j) = Compiler d $ fmap f j
163− {-# INLINE fmap #-}
164−
165−
166−--------------------------------------------------------------------------------
167−instance Applicative Compiler where
168− pure = fromJob . return
169− {-# INLINE pure #-}
170−
171− Compiler d1 j1 <*> Compiler d2 j2 =
172− Compiler (liftM2 S.union d1 d2) $ j1 <*> j2
173− {-# INLINE (<*>) #-}
174−-}
src/Hakyll/Core/Dependencies.hs+11−11
@@ -28,21 +28,21 @@ import Hakyll.Core.Identifier.Pattern
2828
2929--------------------------------------------------------------------------------
3030data Dependency
31− = Pattern (Pattern ()) [Identifier ()]
32− | Identifier (Identifier ())
31+ = Pattern Pattern [Identifier]
32+ | Identifier Identifier
3333 deriving (Show)
3434
3535
3636--------------------------------------------------------------------------------
37−type DependencyFacts = Map (Identifier ()) [Dependency]
37+type DependencyFacts = Map Identifier [Dependency]
3838
3939
4040--------------------------------------------------------------------------------
4141outOfDate
42− :: [Identifier ()] -- ^ All known identifiers
43− -> Set (Identifier ()) -- ^ Initially out-of-date resources
44− -> DependencyFacts -- ^ Old dependency facts
45− -> (Set (Identifier ()), DependencyFacts, [String])
42+ :: [Identifier] -- ^ All known identifiers
43+ -> Set Identifier -- ^ Initially out-of-date resources
44+ -> DependencyFacts -- ^ Old dependency facts
45+ -> (Set Identifier, DependencyFacts, [String])
4646outOfDate universe ood oldFacts =
4747 let (_, state, logs) = runRWS rws universe (DependencyState oldFacts ood)
4848 in (dependencyOod state, dependencyFacts state, logs)
@@ -56,21 +56,21 @@ outOfDate universe ood oldFacts =
5656--------------------------------------------------------------------------------
5757data DependencyState = DependencyState
5858 { dependencyFacts :: DependencyFacts
59− , dependencyOod :: Set (Identifier ())
59+ , dependencyOod :: Set Identifier
6060 } deriving (Show)
6161
6262
6363--------------------------------------------------------------------------------
64−type DependencyM a = RWS [Identifier ()] [String] DependencyState a
64+type DependencyM a = RWS [Identifier] [String] DependencyState a
6565
6666
6767--------------------------------------------------------------------------------
68−markOod :: Identifier () -> DependencyM ()
68+markOod :: Identifier -> DependencyM ()
6969markOod id' = modify $ \s -> s {dependencyOod = S.insert id' $ dependencyOod s}
7070
7171
7272--------------------------------------------------------------------------------
73−dependenciesFor :: Identifier () -> DependencyM [Identifier ()]
73+dependenciesFor :: Identifier -> DependencyM [Identifier]
7474dependenciesFor id' = do
7575 facts <- dependencyFacts <$> get
7676 let relevant = fromMaybe [] $ M.lookup id' facts
src/Hakyll/Core/Identifier.hs+8−16
@@ -35,7 +35,6 @@ module Hakyll.Core.Identifier
3535 ( Identifier
3636 , fromFilePath
3737 , toFilePath
38− , castIdentifier
3938 , identifierVersion
4039 , setVersion
4140 ) where
@@ -56,30 +55,30 @@ import GHC.Exts (IsString, fromString)
5655
5756--------------------------------------------------------------------------------
5857-- | An identifier used to uniquely identify a value
59−data Identifier a = Identifier
58+data Identifier = Identifier
6059 { identifierVersion :: Maybe String
6160 , identifierPath :: String
6261 } deriving (Eq, Ord, Typeable)
6362
6463
6564--------------------------------------------------------------------------------
66−instance Binary (Identifier a) where
65+instance Binary Identifier where
6766 put (Identifier v p) = put v >> put p
6867 get = Identifier <$> get <*> get
6968
7069
7170--------------------------------------------------------------------------------
72−instance IsString (Identifier a) where
71+instance IsString Identifier where
7372 fromString = fromFilePath
7473
7574
7675--------------------------------------------------------------------------------
77−instance NFData (Identifier a) where
76+instance NFData Identifier where
7877 rnf (Identifier v p) = rnf v `seq` rnf p `seq` ()
7978
8079
8180--------------------------------------------------------------------------------
82−instance Show (Identifier a) where
81+instance Show Identifier where
8382 show i = case identifierVersion i of
8483 Nothing -> toFilePath i
8584 Just v -> toFilePath i ++ " (" ++ v ++ ")"
@@ -87,7 +86,7 @@ instance Show (Identifier a) where
8786
8887--------------------------------------------------------------------------------
8988-- | Parse an identifier from a string
90−fromFilePath :: String -> Identifier a
89+fromFilePath :: String -> Identifier
9190fromFilePath = Identifier Nothing .
9291 intercalate "/" . filter (not . null) . split'
9392 where
@@ -96,17 +95,10 @@ fromFilePath = Identifier Nothing .
9695
9796--------------------------------------------------------------------------------
9897-- | Convert an identifier to a relative 'FilePath'
99−toFilePath :: Identifier a -> FilePath
98+toFilePath :: Identifier -> FilePath
10099toFilePath = identifierPath
101100
102101
103102--------------------------------------------------------------------------------
104−-- | Discard the phantom type parameter of an identifier
105−castIdentifier :: Identifier a -> Identifier b
106−castIdentifier (Identifier v p) = Identifier v p
107−{-# INLINE castIdentifier #-}
108−
109−
110−--------------------------------------------------------------------------------
111−setVersion :: Maybe String -> Identifier a -> Identifier a
103+setVersion :: Maybe String -> Identifier -> Identifier
112104setVersion v i = i {identifierVersion = v}
src/Hakyll/Core/Identifier/Pattern.hs+18−31
@@ -48,7 +48,6 @@ module Hakyll.Core.Identifier.Pattern
4848 -- * Manipulating patterns
4949 , complement
5050 , withVersion
51− , castPattern
5251
5352 -- * Applying patterns
5453 , matches
@@ -104,19 +103,19 @@ instance Binary GlobComponent where
104103
105104--------------------------------------------------------------------------------
106105-- | Type that allows matching on identifiers
107−data Pattern a
106+data Pattern
108107 = Everything
109− | Complement (Pattern a)
110− | And (Pattern a) (Pattern a)
108+ | Complement Pattern
109+ | And Pattern Pattern
111110 | Glob [GlobComponent]
112− | List [Identifier a] -- TODO Maybe use a set here
111+ | List [Identifier] -- TODO Maybe use a set here
113112 | Regex String
114113 | Version (Maybe String)
115114 deriving (Show)
116115
117116
118117--------------------------------------------------------------------------------
119−instance Binary (Pattern a) where
118+instance Binary Pattern where
120119 put Everything = putWord8 0
121120 put (Complement p) = putWord8 1 >> put p
122121 put (And x y) = putWord8 2 >> put x >> put y
@@ -136,19 +135,19 @@ instance Binary (Pattern a) where
136135
137136
138137--------------------------------------------------------------------------------
139−instance IsString (Pattern a) where
138+instance IsString Pattern where
140139 fromString = fromGlob
141140
142141
143142--------------------------------------------------------------------------------
144−instance Monoid (Pattern a) where
143+instance Monoid Pattern where
145144 mempty = Everything
146145 mappend = And
147146
148147
149148--------------------------------------------------------------------------------
150149-- | Parse a pattern from a string
151−fromGlob :: String -> Pattern a
150+fromGlob :: String -> Pattern
152151fromGlob = Glob . parse'
153152 where
154153 parse' str =
@@ -162,7 +161,7 @@ fromGlob = Glob . parse'
162161
163162--------------------------------------------------------------------------------
164163-- | Create a 'Pattern' from a list of 'Identifier's it should match
165−fromList :: [Identifier a] -> Pattern a
164+fromList :: [Identifier] -> Pattern
166165fromList = List
167166
168167
@@ -172,12 +171,12 @@ fromList = List
172171-- Example:
173172--
174173-- > regex "^foo/[^x]*$
175−fromRegex :: String -> Pattern a
174+fromRegex :: String -> Pattern
176175fromRegex = Regex
177176
178177
179178--------------------------------------------------------------------------------
180−fromVersion :: Maybe String -> Pattern a
179+fromVersion :: Maybe String -> Pattern
181180fromVersion = Version
182181
183182
@@ -187,7 +186,7 @@ fromVersion = Version
187186-- > complement "foo/bar.html"
188187--
189188-- will match /anything/ except @\"foo\/bar.html\"@
190−complement :: Pattern a -> Pattern a
189+complement :: Pattern -> Pattern
191190complement = Complement
192191
193192
@@ -195,25 +194,13 @@ complement = Complement
195194-- | Specify a version, e.g.
196195--
197196-- > "foo/*.markdown" `withVersion` "pdf"
198−withVersion :: Pattern a -> String -> Pattern a
197+withVersion :: Pattern -> String -> Pattern
199198withVersion p v = And p $ fromVersion $ Just v
200199
201200
202−--------------------------------------------------------------------------------
203−-- | Discard the phantom type parameter
204−castPattern :: Pattern a -> Pattern b
205−castPattern Everything = Everything
206−castPattern (Complement x) = Complement (castPattern x)
207−castPattern (And x y) = And (castPattern x) (castPattern y)
208−castPattern (Glob g) = Glob g
209−castPattern (List l) = List $ map castIdentifier l
210−castPattern (Regex r) = Regex r
211−castPattern (Version v) = Version v
212−
213−
214201--------------------------------------------------------------------------------
215202-- | Check if an identifier matches a pattern
216−matches :: Pattern a -> Identifier a -> Bool
203+matches :: Pattern -> Identifier -> Bool
217204matches Everything _ = True
218205matches (Complement p) i = not $ matches p i
219206matches (And x y) i = matches x i && matches y i
@@ -225,7 +212,7 @@ matches (Version v) i = identifierVersion i == v
225212
226213--------------------------------------------------------------------------------
227214-- | Given a list of identifiers, retain only those who match the given pattern
228−filterMatches :: Pattern a -> [Identifier a] -> [Identifier a]
215+filterMatches :: Pattern -> [Identifier] -> [Identifier]
229216filterMatches = filter . matches
230217
231218
@@ -238,7 +225,7 @@ splits = inits &&& tails >>> uncurry zip >>> reverse
238225
239226--------------------------------------------------------------------------------
240227-- | Match a glob against a pattern, generating a list of captures
241−capture :: Pattern a -> Identifier a -> Maybe [String]
228+capture :: Pattern -> Identifier -> Maybe [String]
242229capture (Glob p) i = capture' p (toFilePath i)
243230capture _ _ = Nothing
244231
@@ -272,14 +259,14 @@ capture' (CaptureMany : ms) str =
272259-- Result:
273260--
274261-- > "tags/foo"
275−fromCapture :: Pattern a -> String -> Identifier a
262+fromCapture :: Pattern -> String -> Identifier
276263fromCapture pattern = fromCaptures pattern . repeat
277264
278265
279266--------------------------------------------------------------------------------
280267-- | Create an identifier from a pattern by filling in the captures with the
281268-- given list of strings
282−fromCaptures :: Pattern a -> [String] -> Identifier a
269+fromCaptures :: Pattern -> [String] -> Identifier
283270fromCaptures (Glob p) = fromFilePath . fromCaptures' p
284271fromCaptures _ = error $
285272 "Hakyll.Core.Identifier.Pattern.fromCaptures: fromCaptures only works " ++
src/Hakyll/Core/Metadata.hs+1−1
@@ -19,6 +19,6 @@ type Metadata = Map String String
1919
2020--------------------------------------------------------------------------------
2121class MonadMetadata m where
22− identifierMetadata :: Identifier a -> m Metadata
22+ identifierMetadata :: Identifier -> m Metadata
2323 -- allMetadata :: m [(Resource, Metadata)]
2424 -- patternMetadata :: Pattern a -> m [(Resource, Metadata)]
src/Hakyll/Core/ResourceProvider.hs+2−2
@@ -32,7 +32,7 @@ import Hakyll.Core.ResourceProvider.Modified
3232
3333--------------------------------------------------------------------------------
3434-- | Wrapper to ensure metadata cache is invalidated if necessary
35−resourceMetadata :: ResourceProvider -> Identifier a -> IO Metadata
35+resourceMetadata :: ResourceProvider -> Identifier -> IO Metadata
3636resourceMetadata rp r = do
3737 _ <- resourceModified rp r
3838 Internal.resourceMetadata rp r
@@ -40,7 +40,7 @@ resourceMetadata rp r = do
4040
4141--------------------------------------------------------------------------------
4242-- | Wrapper to ensure metadata cache is invalidated if necessary
43−resourceBody :: ResourceProvider -> Identifier a -> IO String
43+resourceBody :: ResourceProvider -> Identifier -> IO String
4444resourceBody rp r = do
4545 _ <- resourceModified rp r
4646 Internal.resourceBody rp r
src/Hakyll/Core/ResourceProvider/Internal.hs+8−8
@@ -33,9 +33,9 @@ import Hakyll.Core.Identifier
3333-- | Responsible for retrieving and listing resources
3434data ResourceProvider = ResourceProvider
3535 { -- | A list of all files found
36− resourceSet :: Set (Identifier ())
36+ resourceSet :: Set Identifier
3737 , -- | Cache keeping track of modified files
38− resourceModifiedCache :: IORef (Map (Identifier ()) Bool)
38+ resourceModifiedCache :: IORef (Map Identifier Bool)
3939 , -- | Underlying persistent store for caching
4040 resourceStore :: Store
4141 }
@@ -55,32 +55,32 @@ newResourceProvider store ignore directory = do
5555
5656
5757--------------------------------------------------------------------------------
58−resourceList :: ResourceProvider -> [Identifier ()]
58+resourceList :: ResourceProvider -> [Identifier]
5959resourceList = S.toList . resourceSet
6060
6161
6262--------------------------------------------------------------------------------
6363-- | Check if a given resource exists
64−resourceExists :: ResourceProvider -> Identifier a -> Bool
64+resourceExists :: ResourceProvider -> Identifier -> Bool
6565resourceExists provider =
66− (`S.member` resourceSet provider) . setVersion Nothing . castIdentifier
66+ (`S.member` resourceSet provider) . setVersion Nothing
6767
6868
6969--------------------------------------------------------------------------------
7070-- | Each resource may have an associated metadata resource (with a @.metadata@
7171-- filename)
72−resourceMetadataResource :: Identifier a -> Identifier ()
72+resourceMetadataResource :: Identifier -> Identifier
7373resourceMetadataResource =
7474 fromFilePath . flip addExtension "metadata" . toFilePath
7575
7676
7777--------------------------------------------------------------------------------
7878-- | Get the raw body of a resource as string
79−resourceString :: Identifier a -> IO String
79+resourceString :: Identifier -> IO String
8080resourceString = readFile . toFilePath
8181
8282
8383--------------------------------------------------------------------------------
8484-- | Get the raw body of a resource of a lazy bytestring
85−resourceLBS :: Identifier a -> IO BL.ByteString
85+resourceLBS :: Identifier -> IO BL.ByteString
8686resourceLBS = BL.readFile . toFilePath
src/Hakyll/Core/ResourceProvider/Metadata.hs+1−1
@@ -24,7 +24,7 @@ import Hakyll.Core.Util.String
2424
2525
2626--------------------------------------------------------------------------------
27−loadMetadata :: ResourceProvider -> Identifier a -> IO (Metadata, Maybe String)
27+loadMetadata :: ResourceProvider -> Identifier -> IO (Metadata, Maybe String)
2828loadMetadata rp identifier = do
2929 hasHeader <- probablyHasMetadataHeader fp
3030 (md, body) <- if hasHeader
src/Hakyll/Core/ResourceProvider/MetadataCache.hs+4−4
@@ -15,7 +15,7 @@ import qualified Hakyll.Core.Store as Store
1515
1616
1717--------------------------------------------------------------------------------
18−resourceMetadata :: ResourceProvider -> Identifier a -> IO Metadata
18+resourceMetadata :: ResourceProvider -> Identifier -> IO Metadata
1919resourceMetadata rp r = do
2020 load rp r
2121 Store.Found md <- Store.get (resourceStore rp)
@@ -24,7 +24,7 @@ resourceMetadata rp r = do
2424
2525
2626--------------------------------------------------------------------------------
27−resourceBody :: ResourceProvider -> Identifier a -> IO String
27+resourceBody :: ResourceProvider -> Identifier -> IO String
2828resourceBody rp r = do
2929 load rp r
3030 Store.Found bd <- Store.get (resourceStore rp)
@@ -33,14 +33,14 @@ resourceBody rp r = do
3333
3434
3535--------------------------------------------------------------------------------
36−resourceInvalidateMetadataCache :: ResourceProvider -> Identifier a -> IO ()
36+resourceInvalidateMetadataCache :: ResourceProvider -> Identifier -> IO ()
3737resourceInvalidateMetadataCache rp r = do
3838 Store.delete (resourceStore rp) [name, toFilePath r, "metadata"]
3939 Store.delete (resourceStore rp) [name, toFilePath r, "body"]
4040
4141
4242--------------------------------------------------------------------------------
43−load :: ResourceProvider -> Identifier a -> IO ()
43+load :: ResourceProvider -> Identifier -> IO ()
4444load rp r = do
4545 mmd <- Store.get store mdk :: IO (Store.Result Metadata)
4646 case mmd of
src/Hakyll/Core/ResourceProvider/Modified.hs+3−3
@@ -27,7 +27,7 @@ import qualified Hakyll.Core.Store as Store
2727
2828--------------------------------------------------------------------------------
2929-- | A resource is modified if it or its metadata has changed
30−resourceModified :: ResourceProvider -> Identifier a -> IO Bool
30+resourceModified :: ResourceProvider -> Identifier -> IO Bool
3131resourceModified rp r
3232 | not exists = return False
3333 | otherwise = do
@@ -47,7 +47,7 @@ resourceModified rp r
4747
4848 return m
4949 where
50− normalized = castIdentifier $ setVersion Nothing r
50+ normalized = setVersion Nothing r
5151 exists = resourceExists rp r
5252 store = resourceStore rp
5353 cacheRef = resourceModifiedCache rp
@@ -79,5 +79,5 @@ fileDigest = fmap MD5.hashlazy . BL.readFile
7979
8080
8181--------------------------------------------------------------------------------
82−resourceModificationTime :: Identifier a -> IO UTCTime
82+resourceModificationTime :: Identifier -> IO UTCTime
8383resourceModificationTime = getModificationTime . toFilePath
src/Hakyll/Core/Routes.hs+6−6
@@ -53,7 +53,7 @@ import Hakyll.Core.Util.String
5353
5454--------------------------------------------------------------------------------
5555-- | Type used for a route
56−newtype Routes = Routes {unRoutes :: forall a. Identifier a -> Maybe FilePath}
56+newtype Routes = Routes {unRoutes :: Identifier -> Maybe FilePath}
5757
5858
5959--------------------------------------------------------------------------------
@@ -64,7 +64,7 @@ instance Monoid Routes where
6464
6565--------------------------------------------------------------------------------
6666-- | Apply a route to an identifier
67−runRoutes :: Routes -> Identifier a -> Maybe FilePath
67+runRoutes :: Routes -> Identifier -> Maybe FilePath
6868runRoutes = unRoutes
6969
7070
@@ -101,16 +101,16 @@ setExtension extension = Routes $
101101--------------------------------------------------------------------------------
102102-- | Apply the route if the identifier matches the given pattern, fail
103103-- otherwise
104−matchRoute :: Pattern a -> Routes -> Routes
104+matchRoute :: Pattern -> Routes -> Routes
105105matchRoute pattern (Routes route) = Routes $ \id' ->
106− if matches pattern (castIdentifier id') then route id' else Nothing
106+ if matches pattern id' then route id' else Nothing
107107
108108
109109--------------------------------------------------------------------------------
110110-- | Create a custom route. This should almost always be used with
111111-- 'matchRoute'
112−customRoute :: (Identifier a -> FilePath) -> Routes
113−customRoute f = Routes $ Just . f . castIdentifier
112+customRoute :: (Identifier -> FilePath) -> Routes
113+customRoute f = Routes $ Just . f
114114
115115
116116--------------------------------------------------------------------------------
src/Hakyll/Core/Rules.hs+31−34
@@ -2,7 +2,7 @@
22-- | This module provides a declarative DSL in which the user can specify the
33-- different rules used to run the compilers.
44--
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
66-- compilation rules.
77--
88-- A typical usage example would be:
@@ -17,8 +17,7 @@
1717{-# LANGUAGE GeneralizedNewtypeDeriving #-}
1818{-# LANGUAGE OverloadedStrings #-}
1919module Hakyll.Core.Rules
20− ( RulesM
21− , Rules
20+ ( Rules
2221 , match
2322 , group
2423 , compile
@@ -31,7 +30,7 @@ module Hakyll.Core.Rules
3130
3231--------------------------------------------------------------------------------
3332import Control.Applicative ((<$>))
34−import Control.Arrow ((***))
33+import Control.Arrow (second)
3534import Control.Monad.Reader (ask, local)
3635import Control.Monad.State (get, put)
3736import Control.Monad.Writer (tell)
@@ -57,36 +56,36 @@ import Hakyll.Core.Writable
5756
5857--------------------------------------------------------------------------------
5958-- | Add a route
60−tellRoute :: Routes -> Rules
61−tellRoute route' = RulesM $ tell $ RuleSet route' mempty mempty
59+tellRoute :: Routes -> Rules ()
60+tellRoute route' = Rules $ tell $ RuleSet route' mempty mempty
6261
6362
6463--------------------------------------------------------------------------------
6564-- | Add a number of compilers
6665tellCompilers :: (Binary a, Typeable a, Writable a)
67− => [(Identifier a, Compiler a)]
68− -> Rules
69−tellCompilers compilers = RulesM $ do
66+ => [(Identifier, Compiler a)]
67+ -> Rules ()
68+tellCompilers compilers = Rules $ do
7069 -- 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
7271 tell $ RuleSet mempty compilers' mempty
7372
7473
7574--------------------------------------------------------------------------------
7675-- | Add resources
77−tellResources :: [Identifier a]
78− -> Rules
79−tellResources resources' = RulesM $ tell $
80− RuleSet mempty mempty $ S.fromList $ map castIdentifier resources'
76+tellResources :: [Identifier]
77+ -> Rules ()
78+tellResources resources' = Rules $ tell $
79+ RuleSet mempty mempty $ S.fromList resources'
8180
8281
8382--------------------------------------------------------------------------------
8483-- | Only compile/route items satisfying the given predicate
85−match :: Pattern a -> RulesM b -> RulesM b
86−match pattern = RulesM . local addPredicate . unRulesM
84+match :: Pattern -> Rules b -> Rules b
85+match pattern = Rules . local addPredicate . unRules
8786 where
8887 addPredicate env = env
89− { rulesPattern = rulesPattern env `mappend` castPattern pattern
88+ { rulesPattern = rulesPattern env `mappend` pattern
9089 }
9190
9291
@@ -120,8 +119,8 @@ match pattern = RulesM . local addPredicate . unRulesM
120119--
121120-- This will put the compiler for the raw content in a separate group
122121-- (@\"raw\"@), which causes it to be compiled as well.
123−group :: String -> RulesM a -> RulesM a
124−group g = RulesM . local setVersion' . unRulesM
122+group :: String -> Rules a -> Rules a
123+group g = Rules . local setVersion' . unRules
125124 where
126125 setVersion' env = env {rulesVersion = Just g}
127126
@@ -133,12 +132,11 @@ group g = RulesM . local setVersion' . unRulesM
133132-- no resources match the current selection, nothing will happen. In this case,
134133-- you might want to have a look at 'create'.
135134compile :: (Binary a, Typeable a, Writable a)
136− => Compiler a -> RulesM (Pattern a)
135+ => Compiler a -> Rules ()
137136compile compiler = do
138137 ids <- resources
139− tellCompilers [(castIdentifier id', compiler) | id' <- ids]
138+ tellCompilers [(id', compiler) | id' <- ids]
140139 tellResources ids
141− return $ fromList $ map castIdentifier ids
142140
143141
144142--------------------------------------------------------------------------------
@@ -151,33 +149,32 @@ compile compiler = do
151149-- replaced by the group set via 'group' (or 'Nothing', if 'group' has not been
152150-- used).
153151create :: (Binary a, Typeable a, Writable a)
154− => Identifier a -> Compiler a -> RulesM (Identifier a)
155−create id' compiler = RulesM $ do
152+ => Identifier -> Compiler a -> Rules ()
153+create id' compiler = Rules $ do
156154 version' <- rulesVersion <$> ask
157155 let id'' = setVersion version' id'
158− unRulesM $ tellCompilers [(id'', compiler)]
159− return id''
156+ unRules $ tellCompilers [(id'', compiler)]
160157
161158
162159--------------------------------------------------------------------------------
163160-- | Add a route.
164161--
165162-- This adds a route for all items matching the current pattern.
166−route :: Routes -> Rules
167−route route' = RulesM $ do
163+route :: Routes -> Rules ()
164+route route' = Rules $ do
168165 -- We want the route only to be applied if we match the current pattern and
169166 -- version
170167 pattern <- rulesPattern <$> ask
171168 version' <- rulesVersion <$> ask
172− unRulesM $ tellRoute $ matchRoute
169+ unRules $ tellRoute $ matchRoute
173170 (pattern `mappend` fromVersion version') route'
174171
175172
176173--------------------------------------------------------------------------------
177174-- | Get a list of resources matching the current pattern. This will also set
178175-- the correct group to the identifiers.
179−resources :: RulesM [Identifier ()]
180−resources = RulesM $ do
176+resources :: Rules [Identifier]
177+resources = Rules $ do
181178 pattern <- rulesPattern <$> ask
182179 provider <- rulesResourceProvider <$> ask
183180 g <- rulesVersion <$> ask
@@ -187,9 +184,9 @@ resources = RulesM $ do
187184--------------------------------------------------------------------------------
188185-- | Generate a fresh Identifier with a given prefix
189186-- TODO: remove?
190−freshIdentifier :: String -- ^ Prefix
191− -> RulesM (Identifier a) -- ^ Fresh identifier
192−freshIdentifier prefix = RulesM $ do
187+freshIdentifier :: String -- ^ Prefix
188+ -> Rules Identifier -- ^ Fresh identifier
189+freshIdentifier prefix = Rules $ do
193190 state <- get
194191 let index = rulesNextIdentifier state
195192 id' = fromFilePath $ prefix ++ "/" ++ show index
src/Hakyll/Core/Rules/Internal.hs+8−15
@@ -6,8 +6,7 @@ module Hakyll.Core.Rules.Internal
66 ( RuleSet (..)
77 , RuleState (..)
88 , RuleEnvironment (..)
9− , RulesM (..)
10− , Rules
9+ , Rules (..)
1110 , runRules
1211 ) where
1312
@@ -35,9 +34,9 @@ data RuleSet = RuleSet
3534 { -- | Routes used in the compilation structure
3635 rulesRoutes :: Routes
3736 , -- | Compilation rules
38− rulesCompilers :: [(Identifier (), Compiler CompiledItem)]
37+ rulesCompilers :: [(Identifier, Compiler CompiledItem)]
3938 , -- | A set of the actually used files
40− rulesResources :: Set (Identifier ())
39+ rulesResources :: Set Identifier
4140 }
4241
4342
@@ -59,29 +58,23 @@ data RuleState = RuleState
5958-- | Rule environment
6059data RuleEnvironment = RuleEnvironment
6160 { rulesResourceProvider :: ResourceProvider
62− , rulesPattern :: forall a. Pattern a
61+ , rulesPattern :: Pattern
6362 , rulesVersion :: Maybe String
6463 }
6564
6665
6766--------------------------------------------------------------------------------
6867-- | The monad used to compose rules
69−newtype RulesM a = RulesM
70− { unRulesM :: RWST RuleEnvironment RuleSet RuleState IO a
68+newtype Rules a = Rules
69+ { unRules :: RWST RuleEnvironment RuleSet RuleState IO a
7170 } deriving (Monad, Functor, Applicative)
7271
7372
74−--------------------------------------------------------------------------------
75−-- | Simplification of the RulesM type; usually, it will not return any
76−-- result.
77−type Rules = RulesM ()
78−
79−
8073--------------------------------------------------------------------------------
8174-- | Run a Rules monad, resulting in a 'RuleSet'
82−runRules :: RulesM a -> ResourceProvider -> IO RuleSet
75+runRules :: Rules a -> ResourceProvider -> IO RuleSet
8376runRules rules provider = do
84− (_, _, ruleSet) <- runRWST (unRulesM rules) env state
77+ (_, _, ruleSet) <- runRWST (unRules rules) env state
8578 return $ nubCompilers ruleSet
8679 where
8780 state = RuleState {rulesNextIdentifier = 0}
src/Hakyll/Core/Writable.hs+1−1
@@ -38,5 +38,5 @@ instance Writable [Word8] where
3838instance Writable Html where
3939 write p html = write p $ renderHtml html
4040
41−instance Writable (Identifier a) where
41+instance Writable Identifier where
4242 write p = write p . show