summaryrefslogtreecommitdiff
path: root/src/Hakyll/Core/Compiler/Internal.hs
diff options
context:
space:
mode:
authorJasper Van der Jeugt <m@jaspervdj.be>2012-11-13 17:31:03 +0100
committerJasper Van der Jeugt <m@jaspervdj.be>2012-11-13 17:31:03 +0100
commitf0af2a3b79ea7eea3f521f79fd903f9023ec85df (patch)
treebbc460b65ab52879c616dffce1bb32fe8d8df2ac /src/Hakyll/Core/Compiler/Internal.hs
parentd2e913f42434841c584b97ae9d5417ff2737c0ce (diff)
downloadhakyll-f0af2a3b79ea7eea3f521f79fd903f9023ec85df.tar.gz
WIP
Diffstat (limited to 'src/Hakyll/Core/Compiler/Internal.hs')
-rw-r--r--src/Hakyll/Core/Compiler/Internal.hs33
1 files changed, 22 insertions, 11 deletions
diff --git a/src/Hakyll/Core/Compiler/Internal.hs b/src/Hakyll/Core/Compiler/Internal.hs
index f211367..5b7fb51 100644
--- a/src/Hakyll/Core/Compiler/Internal.hs
+++ b/src/Hakyll/Core/Compiler/Internal.hs
@@ -5,19 +5,21 @@
module Hakyll.Core.Compiler.Internal
( CompilerRead (..)
, CompilerResult (..)
- , Compiler
+ , Compiler (..)
, runCompiler
, compilerTell
, compilerAsk
, compilerThrow
, compilerCatch
, compilerResult
+ , compilerUnsafeIO
) where
--------------------------------------------------------------------------------
import Control.Applicative (Alternative (..),
Applicative (..))
+import Control.Exception (SomeException, handle)
import Data.Monoid (mappend, mempty)
@@ -34,19 +36,17 @@ import Hakyll.Core.Store
-- | Environment in which a compiler runs
data CompilerRead = CompilerRead
{ -- | Target identifier
- compilerIdentifier :: Identifier
+ compilerIdentifier :: Identifier
, -- | Resource provider
- compilerResourceProvider :: ResourceProvider
+ compilerProvider :: ResourceProvider
, -- | List of all known identifiers
- compilerUniverse :: [Identifier]
+ compilerUniverse :: [Identifier]
, -- | Site routes
- compilerRoutes :: Routes
+ compilerRoutes :: Routes
, -- | Compiler store
- compilerStore :: Store
- , -- | Flag indicating if the underlying resource was modified
- compilerResourceModified :: Bool
+ compilerStore :: Store
, -- | Logger
- compilerLogger :: Logger
+ compilerLogger :: Logger
}
@@ -111,7 +111,10 @@ instance Applicative Compiler where
--------------------------------------------------------------------------------
runCompiler :: Compiler a -> CompilerRead -> IO (CompilerResult a)
-runCompiler = unCompiler
+runCompiler compiler read' = handle handler $ unCompiler compiler read'
+ where
+ handler :: SomeException -> IO (CompilerResult a)
+ handler e = return $ CompilerError $ show e
--------------------------------------------------------------------------------
@@ -128,7 +131,7 @@ compilerAsk = Compiler $ \r -> return $ CompilerDone r mempty
--------------------------------------------------------------------------------
-compilerTell :: [Dependency] -> Compiler ()
+compilerTell :: CompilerWrite -> Compiler ()
compilerTell deps = Compiler $ \_ -> return $ CompilerDone () deps
{-# INLINE compilerTell #-}
@@ -154,3 +157,11 @@ compilerCatch (Compiler x) f = Compiler $ \r -> do
compilerResult :: CompilerResult a -> Compiler a
compilerResult x = Compiler $ \_ -> return x
{-# INLINE compilerResult #-}
+
+
+--------------------------------------------------------------------------------
+compilerUnsafeIO :: IO a -> Compiler a
+compilerUnsafeIO io = Compiler $ \_ -> do
+ x <- io
+ return $ CompilerDone x mempty
+{-# INLINE compilerUnsafeIO #-}