summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Hakyll/Core/Rules.hs60
1 files changed, 10 insertions, 50 deletions
diff --git a/src/Hakyll/Core/Rules.hs b/src/Hakyll/Core/Rules.hs
index 2679531..fb6458b 100644
--- a/src/Hakyll/Core/Rules.hs
+++ b/src/Hakyll/Core/Rules.hs
@@ -19,7 +19,7 @@
module Hakyll.Core.Rules
( Rules
, match
- , group
+ , version
, compile
, route
) where
@@ -45,7 +45,7 @@ import Hakyll.Core.Identifier
import Hakyll.Core.Identifier.Pattern
import Hakyll.Core.Item
import Hakyll.Core.Item.SomeItem
-import Hakyll.Core.Provider
+import Hakyll.Core.Metadata
import Hakyll.Core.Routes
import Hakyll.Core.Rules.Internal
import Hakyll.Core.Writable
@@ -86,39 +86,10 @@ match pattern = Rules . local addPattern . unRules
--------------------------------------------------------------------------------
--- | Greate a group of compilers
--- Imagine you have a page that you want to render, but you also want the raw
--- content available on your site.
---
--- > match "test.markdown" $ do
--- > route $ setExtension "html"
--- > compile pageCompiler
--- >
--- > match "test.markdown" $ do
--- > route idRoute
--- > compile copyPageCompiler
---
--- Will of course conflict! In this case, Hakyll will pick the first matching
--- compiler (@pageCompiler@ in this case).
---
--- In case you want to have them both, you can use the 'group' function to
--- create a new group. For example,
---
--- > match "test.markdown" $ do
--- > route $ setExtension "html"
--- > compile pageCompiler
--- >
--- > group "raw" $ do
--- > match "test.markdown" $ do
--- > route idRoute
--- > compile copyPageCompiler
---
--- This will put the compiler for the raw content in a separate group
--- (@\"raw\"@), which causes it to be compiled as well.
-group :: String -> Rules a -> Rules a
-group g = Rules . local setVersion' . unRules
+version :: String -> Rules a -> Rules a
+version v = Rules . local setVersion' . unRules
where
- setVersion' env = env {rulesVersion = Just g}
+ setVersion' env = env {rulesVersion = Just v}
--------------------------------------------------------------------------------
@@ -130,15 +101,16 @@ group g = Rules . local setVersion' . unRules
compile :: (Binary a, Typeable a, Writable a)
=> Compiler (Item a) -> Rules ()
compile compiler = do
- pattern <- Rules $ rulesPattern <$> ask
- ids <- case fromLiteral pattern of
+ pattern <- Rules $ rulesPattern <$> ask
+ version' <- Rules $ rulesVersion <$> ask
+ ids <- case fromLiteral pattern of
Just id' -> return [id']
Nothing -> do
- ids <- resources
+ ids <- getMatches pattern
tellResources ids
return ids
- tellCompilers [(id', compiler) | id' <- ids]
+ tellCompilers [(setVersion version' id', compiler) | id' <- ids]
--------------------------------------------------------------------------------
@@ -153,15 +125,3 @@ route route' = Rules $ do
version' <- rulesVersion <$> ask
unRules $ tellRoute $ matchRoute
(pattern `mappend` fromVersion version') route'
-
-
---------------------------------------------------------------------------------
--- | Get a list of resources matching the current pattern. This will also set
--- the correct group to the identifiers.
--- TODO: Make this private?
-resources :: Rules [Identifier]
-resources = Rules $ do
- pattern <- rulesPattern <$> ask
- provider <- rulesProvider <$> ask
- g <- rulesVersion <$> ask
- return $ filterMatches pattern $ map (setVersion g) $ resourceList provider