summaryrefslogtreecommitdiff
path: root/src/Hakyll/Core/Compiler.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Hakyll/Core/Compiler.hs')
-rw-r--r--src/Hakyll/Core/Compiler.hs24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/Hakyll/Core/Compiler.hs b/src/Hakyll/Core/Compiler.hs
index 840f3bd..ee3f90e 100644
--- a/src/Hakyll/Core/Compiler.hs
+++ b/src/Hakyll/Core/Compiler.hs
@@ -95,6 +95,7 @@ module Hakyll.Core.Compiler
, getIdentifier
, getRoute
, getRouteFor
+ , getResourceBody
, getResourceString
, getResourceLBS
, getResourceWith
@@ -190,25 +191,36 @@ getRouteFor = fromJob $ \identifier -> CompilerM $ do
routes <- compilerRoutes <$> ask
return $ runRoutes routes identifier
+
+--------------------------------------------------------------------------------
+-- | Get the body of the underlying resource
+getResourceBody :: Compiler a String
+getResourceBody = getResourceWith resourceBody
+
+
+
+--------------------------------------------------------------------------------
-- | Get the resource we are compiling as a string
---
getResourceString :: Compiler a String
-getResourceString = getResourceWith resourceString
+getResourceString = getResourceWith $ const resourceString
+
+--------------------------------------------------------------------------------
-- | Get the resource we are compiling as a lazy bytestring
--
getResourceLBS :: Compiler a ByteString
-getResourceLBS = getResourceWith resourceLBS
+getResourceLBS = getResourceWith $ const resourceLBS
+
+--------------------------------------------------------------------------------
-- | Overloadable function for 'getResourceString' and 'getResourceLBS'
---
-getResourceWith :: (Identifier a -> IO b) -> Compiler c b
+getResourceWith :: (ResourceProvider -> Identifier a -> IO b) -> Compiler c b
getResourceWith reader = fromJob $ \_ -> CompilerM $ do
provider <- compilerResourceProvider <$> ask
r <- compilerIdentifier <$> ask
let filePath = toFilePath r
if resourceExists provider r
- then liftIO $ reader $ castIdentifier r
+ then liftIO $ reader provider $ castIdentifier r
else throwError $ error' filePath
where
error' id' = "Hakyll.Core.Compiler.getResourceWith: resource "