summaryrefslogtreecommitdiff
path: root/src/Hakyll/Core
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2011-05-27 18:25:09 +0200
committerJasper Van der Jeugt <jaspervdj@gmail.com>2011-05-27 18:25:09 +0200
commite2cce1b341fdbf65c270c7e64bb2f5264b8a4468 (patch)
tree081d546954662876f4af1d98c2b376921b38d94e /src/Hakyll/Core
parent0807e4c49aeb66fdbe9ea9a755b6865bfb075336 (diff)
parent5849ab36c784eebc6f0d9ae2ff7efe91c2f6e4ac (diff)
downloadhakyll-e2cce1b341fdbf65c270c7e64bb2f5264b8a4468.tar.gz
Merge branch 'master' into type-safe-identifiers
Diffstat (limited to 'src/Hakyll/Core')
-rw-r--r--src/Hakyll/Core/Compiler.hs6
-rw-r--r--src/Hakyll/Core/Logger.hs15
-rw-r--r--src/Hakyll/Core/Resource/Provider/Dummy.hs8
-rw-r--r--src/Hakyll/Core/Run.hs2
4 files changed, 20 insertions, 11 deletions
diff --git a/src/Hakyll/Core/Compiler.hs b/src/Hakyll/Core/Compiler.hs
index 02e59ac..2eb219c 100644
--- a/src/Hakyll/Core/Compiler.hs
+++ b/src/Hakyll/Core/Compiler.hs
@@ -93,6 +93,7 @@ module Hakyll.Core.Compiler
( Compiler
, runCompiler
, getIdentifier
+ , getResource
, getRoute
, getRouteFor
, getResourceString
@@ -175,6 +176,11 @@ getIdentifier :: Compiler a (Identifier b)
getIdentifier = fromJob $ const $ CompilerM $
castIdentifier . compilerIdentifier <$> ask
+-- | Get the resource that is currently being compiled
+--
+getResource :: Compiler a Resource
+getResource = getIdentifier >>> arr fromIdentifier
+
-- | Get the route we are using for this item
--
getRoute :: Compiler a (Maybe FilePath)
diff --git a/src/Hakyll/Core/Logger.hs b/src/Hakyll/Core/Logger.hs
index 5d75fa9..912cc98 100644
--- a/src/Hakyll/Core/Logger.hs
+++ b/src/Hakyll/Core/Logger.hs
@@ -13,7 +13,7 @@ module Hakyll.Core.Logger
import Control.Monad (forever)
import Control.Monad.Trans (MonadIO, liftIO)
-import Control.Applicative ((<$>), (<*>))
+import Control.Applicative (pure, (<$>), (<*>))
import Control.Concurrent (forkIO)
import Control.Concurrent.Chan.Strict (Chan, newChan, readChan, writeChan)
import Control.Concurrent.MVar.Strict (MVar, newEmptyMVar, takeMVar, putMVar)
@@ -24,15 +24,16 @@ import Data.Time (getCurrentTime, diffUTCTime)
-- | Logger structure. Very complicated.
--
data Logger = Logger
- { loggerChan :: Chan (Maybe String) -- Nothing marks the end
- , loggerSync :: MVar () -- Used for sync on quit
+ { loggerChan :: Chan (Maybe String) -- ^ Nothing marks the end
+ , loggerSync :: MVar () -- ^ Used for sync on quit
+ , loggerSink :: String -> IO () -- ^ Out sink
}
-- | Create a new logger
--
-makeLogger :: IO Logger
-makeLogger = do
- logger <- Logger <$> newChan <*> newEmptyMVar
+makeLogger :: (String -> IO ()) -> IO Logger
+makeLogger sink = do
+ logger <- Logger <$> newChan <*> newEmptyMVar <*> pure sink
_ <- forkIO $ loggerThread logger
return logger
where
@@ -42,7 +43,7 @@ makeLogger = do
-- Stop: sync
Nothing -> putMVar (loggerSync logger) ()
-- Print and continue
- Just m -> putStrLn m
+ Just m -> loggerSink logger m
-- | Flush the logger (blocks until flushed)
--
diff --git a/src/Hakyll/Core/Resource/Provider/Dummy.hs b/src/Hakyll/Core/Resource/Provider/Dummy.hs
index bc0b16d..9f15178 100644
--- a/src/Hakyll/Core/Resource/Provider/Dummy.hs
+++ b/src/Hakyll/Core/Resource/Provider/Dummy.hs
@@ -7,15 +7,17 @@ module Hakyll.Core.Resource.Provider.Dummy
import Data.Map (Map)
import qualified Data.Map as M
-import qualified Data.ByteString.Lazy.Char8 as LBC
+import qualified Data.Text.Lazy as TL
+import qualified Data.Text.Lazy.Encoding as TL
+import Data.ByteString.Lazy (ByteString)
import Hakyll.Core.Resource
import Hakyll.Core.Resource.Provider
-- | Create a dummy 'ResourceProvider'
--
-dummyResourceProvider :: Map String String -> IO ResourceProvider
+dummyResourceProvider :: Map String ByteString -> IO ResourceProvider
dummyResourceProvider vfs = makeResourceProvider
(map Resource (M.keys vfs))
+ (return . TL.unpack . TL.decodeUtf8 . (vfs M.!) . unResource)
(return . (vfs M.!) . unResource)
- (return . LBC.pack . (vfs M.!) . unResource)
diff --git a/src/Hakyll/Core/Run.hs b/src/Hakyll/Core/Run.hs
index 8bde15d..9b27cf3 100644
--- a/src/Hakyll/Core/Run.hs
+++ b/src/Hakyll/Core/Run.hs
@@ -37,7 +37,7 @@ import Hakyll.Core.Logger
--
run :: HakyllConfiguration -> Rules -> IO RuleSet
run configuration rules = do
- logger <- makeLogger
+ logger <- makeLogger putStrLn
section logger "Initialising"
store <- timed logger "Creating store" $