summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2011-04-12 11:43:12 +0200
committerJasper Van der Jeugt <jaspervdj@gmail.com>2011-04-12 11:43:12 +0200
commitedcd3151ee54f3f71d2ffe0a60348f6641909ce7 (patch)
tree6d8c56a45d4e2c9f736ee62d727c1d2721984421
parentb37da38d3911bbc8381a39fe526e69599d9ddcf1 (diff)
downloadhakyll-edcd3151ee54f3f71d2ffe0a60348f6641909ce7.tar.gz
Refactor resource provider creation
-rw-r--r--src/Hakyll/Core/Resource/Provider.hs12
-rw-r--r--src/Hakyll/Core/Resource/Provider/File.hs17
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)