diff options
Diffstat (limited to 'src/Hakyll/Core/Rules.hs')
-rw-r--r-- | src/Hakyll/Core/Rules.hs | 49 |
1 files changed, 10 insertions, 39 deletions
diff --git a/src/Hakyll/Core/Rules.hs b/src/Hakyll/Core/Rules.hs index 0d9b7e2..2679531 100644 --- a/src/Hakyll/Core/Rules.hs +++ b/src/Hakyll/Core/Rules.hs @@ -21,10 +21,7 @@ module Hakyll.Core.Rules , match , group , compile - , create , route - , resources - , freshIdentifier ) where @@ -32,7 +29,6 @@ module Hakyll.Core.Rules import Control.Applicative ((<$>)) import Control.Arrow (second) import Control.Monad.Reader (ask, local) -import Control.Monad.State (get, put) import Control.Monad.Writer (tell) import Data.Monoid (mappend, mempty) import qualified Data.Set as S @@ -81,11 +77,10 @@ tellResources resources' = Rules $ tell $ -------------------------------------------------------------------------------- --- | Only compile/route items satisfying the given predicate match :: Pattern -> Rules b -> Rules b -match pattern = Rules . local addPredicate . unRules +match pattern = Rules . local addPattern . unRules where - addPredicate env = env + addPattern env = env { rulesPattern = rulesPattern env `mappend` pattern } @@ -135,26 +130,15 @@ group g = Rules . local setVersion' . unRules compile :: (Binary a, Typeable a, Writable a) => Compiler (Item a) -> Rules () compile compiler = do - ids <- resources - tellCompilers [(id', compiler) | id' <- ids] - tellResources ids - + pattern <- Rules $ rulesPattern <$> ask + ids <- case fromLiteral pattern of + Just id' -> return [id'] + Nothing -> do + ids <- resources + tellResources ids + return ids --------------------------------------------------------------------------------- --- | Add a compilation rule --- --- This sets a compiler for the given identifier. No resource is needed, since --- we are creating the item from scratch. This is useful if you want to create a --- page on your site that just takes content from other items -- but has no --- actual content itself. Note that the group of the given identifier is --- replaced by the group set via 'group' (or 'Nothing', if 'group' has not been --- used). -create :: (Binary a, Typeable a, Writable a) - => Identifier -> Compiler (Item a) -> Rules () -create id' compiler = Rules $ do - version' <- rulesVersion <$> ask - let id'' = setVersion version' id' - unRules $ tellCompilers [(id'', compiler)] + tellCompilers [(id', compiler) | id' <- ids] -------------------------------------------------------------------------------- @@ -181,16 +165,3 @@ resources = Rules $ do provider <- rulesProvider <$> ask g <- rulesVersion <$> ask return $ filterMatches pattern $ map (setVersion g) $ resourceList provider - - --------------------------------------------------------------------------------- --- | Generate a fresh Identifier with a given prefix --- TODO: remove? -freshIdentifier :: String -- ^ Prefix - -> Rules Identifier -- ^ Fresh identifier -freshIdentifier prefix = Rules $ do - state <- get - let index = rulesNextIdentifier state - id' = fromFilePath $ prefix ++ "/" ++ show index - put $ state {rulesNextIdentifier = index + 1} - return id' |