From edcd3151ee54f3f71d2ffe0a60348f6641909ce7 Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Tue, 12 Apr 2011 11:43:12 +0200 Subject: Refactor resource provider creation --- src/Hakyll/Core/Resource/Provider.hs | 12 +++++++++++- src/Hakyll/Core/Resource/Provider/File.hs | 17 +++-------------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/Hakyll/Core/Resource/Provider.hs b/src/Hakyll/Core/Resource/Provider.hs index cb70cf9..d7f08e0 100644 --- a/src/Hakyll/Core/Resource/Provider.hs +++ b/src/Hakyll/Core/Resource/Provider.hs @@ -12,12 +12,14 @@ -- module Hakyll.Core.Resource.Provider ( ResourceProvider (..) + , makeResourceProvider , resourceExists , resourceDigest , resourceModified ) where -import Control.Concurrent (MVar, readMVar, modifyMVar_) +import Control.Applicative ((<$>)) +import Control.Concurrent (MVar, readMVar, modifyMVar_, newMVar) import Control.Monad ((<=<)) import Data.Word (Word8) import Data.Map (Map) @@ -43,6 +45,14 @@ data ResourceProvider = ResourceProvider resourceModifiedCache :: MVar (Map Resource Bool) } +-- | Create a resource provider +-- +makeResourceProvider :: [Resource] -- ^ Resource list + -> (Resource -> IO String) -- ^ String reader + -> (Resource -> IO LB.ByteString) -- ^ ByteString reader + -> IO ResourceProvider -- ^ Resulting provider +makeResourceProvider l s b = ResourceProvider l s b <$> newMVar M.empty + -- | Check if a given identifier has a resource -- resourceExists :: ResourceProvider -> Resource -> Bool diff --git a/src/Hakyll/Core/Resource/Provider/File.hs b/src/Hakyll/Core/Resource/Provider/File.hs index 5383b51..8365a5d 100644 --- a/src/Hakyll/Core/Resource/Provider/File.hs +++ b/src/Hakyll/Core/Resource/Provider/File.hs @@ -5,8 +5,6 @@ module Hakyll.Core.Resource.Provider.File ) where import Control.Applicative ((<$>)) -import Control.Concurrent (newMVar) -import qualified Data.Map as M import qualified Data.ByteString.Lazy as LB @@ -20,16 +18,7 @@ import Hakyll.Core.Configuration fileResourceProvider :: HakyllConfiguration -> IO ResourceProvider fileResourceProvider configuration = do -- Retrieve a list of paths - list <- filter (not . ignoreFile configuration) <$> + list <- map Resource . filter (not . ignoreFile configuration) <$> getRecursiveContents False "." - - -- MVar for the cache - mvar <- newMVar M.empty - - -- Construct a resource provider - return ResourceProvider - { resourceList = map Resource list - , resourceString = readFile . unResource - , resourceLazyByteString = LB.readFile . unResource - , resourceModifiedCache = mvar - } + makeResourceProvider list (readFile . unResource) + (LB.readFile . unResource) -- cgit v1.2.3