on master help sign in
Rename group to version
commitcae87891543babe1a0ec989546cfabcb451bd890 authorJasper Van der Jeugt <m@jaspervdj.be> dateSat 24 Nov 2012, 18:45 (14 years ago) parent6e7a80e
1 file changed+10−50
src/Hakyll/Core/Rules.hs+10−50
src/Hakyll/Core/Rules.hs+10−50
@@ -19,7 +19,7 @@
1919module Hakyll.Core.Rules
2020 ( Rules
2121 , match
22− , group
22+ , version
2323 , compile
2424 , route
2525 ) where
@@ -45,7 +45,7 @@ import Hakyll.Core.Identifier
4545import Hakyll.Core.Identifier.Pattern
4646import Hakyll.Core.Item
4747import Hakyll.Core.Item.SomeItem
48−import Hakyll.Core.Provider
48+import Hakyll.Core.Metadata
4949import Hakyll.Core.Routes
5050import Hakyll.Core.Rules.Internal
5151import Hakyll.Core.Writable
@@ -86,39 +86,10 @@ match pattern = Rules . local addPattern . unRules
8686
8787
8888--------------------------------------------------------------------------------
89−-- | Greate a group of compilers
90−-- Imagine you have a page that you want to render, but you also want the raw
91−-- content available on your site.
92−--
93−-- > match "test.markdown" $ do
94−-- > route $ setExtension "html"
95−-- > compile pageCompiler
96−-- >
97−-- > match "test.markdown" $ do
98−-- > route idRoute
99−-- > compile copyPageCompiler
100−--
101−-- Will of course conflict! In this case, Hakyll will pick the first matching
102−-- compiler (@pageCompiler@ in this case).
103−--
104−-- In case you want to have them both, you can use the 'group' function to
105−-- create a new group. For example,
106−--
107−-- > match "test.markdown" $ do
108−-- > route $ setExtension "html"
109−-- > compile pageCompiler
110−-- >
111−-- > group "raw" $ do
112−-- > match "test.markdown" $ do
113−-- > route idRoute
114−-- > compile copyPageCompiler
115−--
116−-- This will put the compiler for the raw content in a separate group
117−-- (@\"raw\"@), which causes it to be compiled as well.
118−group :: String -> Rules a -> Rules a
119−group g = Rules . local setVersion' . unRules
89+version :: String -> Rules a -> Rules a
90+version v = Rules . local setVersion' . unRules
12091 where
121− setVersion' env = env {rulesVersion = Just g}
92+ setVersion' env = env {rulesVersion = Just v}
12293
12394
12495--------------------------------------------------------------------------------
@@ -130,15 +101,16 @@ group g = Rules . local setVersion' . unRules
130101compile :: (Binary a, Typeable a, Writable a)
131102 => Compiler (Item a) -> Rules ()
132103compile compiler = do
133− pattern <- Rules $ rulesPattern <$> ask
134− ids <- case fromLiteral pattern of
104+ pattern <- Rules $ rulesPattern <$> ask
105+ version' <- Rules $ rulesVersion <$> ask
106+ ids <- case fromLiteral pattern of
135107 Just id' -> return [id']
136108 Nothing -> do
137− ids <- resources
109+ ids <- getMatches pattern
138110 tellResources ids
139111 return ids
140112
141− tellCompilers [(id', compiler) | id' <- ids]
113+ tellCompilers [(setVersion version' id', compiler) | id' <- ids]
142114
143115
144116--------------------------------------------------------------------------------
@@ -153,15 +125,3 @@ route route' = Rules $ do
153125 version' <- rulesVersion <$> ask
154126 unRules $ tellRoute $ matchRoute
155127 (pattern `mappend` fromVersion version') route'
156−
157−
158−--------------------------------------------------------------------------------
159−-- | Get a list of resources matching the current pattern. This will also set
160−-- the correct group to the identifiers.
161−-- TODO: Make this private?
162−resources :: Rules [Identifier]
163−resources = Rules $ do
164− pattern <- rulesPattern <$> ask
165− provider <- rulesProvider <$> ask
166− g <- rulesVersion <$> ask
167− return $ filterMatches pattern $ map (setVersion g) $ resourceList provider