summaryrefslogtreecommitdiff
path: root/src/Hakyll/Core
diff options
context:
space:
mode:
authorJasper Van der Jeugt <m@jaspervdj.be>2012-11-10 18:11:46 +0100
committerJasper Van der Jeugt <m@jaspervdj.be>2012-11-10 18:11:46 +0100
commit141e761ce11d4d4ae9e9b86201249dbd549e2924 (patch)
tree0d0ba398331bceb9326c58392680fb81361fb6c3 /src/Hakyll/Core
parent260e4e2e8936f756d2f3a2e6e788f05ca28e4324 (diff)
downloadhakyll-141e761ce11d4d4ae9e9b86201249dbd549e2924.tar.gz
Deprecate things, basics now work
Diffstat (limited to 'src/Hakyll/Core')
-rw-r--r--src/Hakyll/Core/Compiler.hs24
-rw-r--r--src/Hakyll/Core/ResourceProvider/Metadata.hs16
2 files changed, 29 insertions, 11 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 "
diff --git a/src/Hakyll/Core/ResourceProvider/Metadata.hs b/src/Hakyll/Core/ResourceProvider/Metadata.hs
index e297f2c..2b0615c 100644
--- a/src/Hakyll/Core/ResourceProvider/Metadata.hs
+++ b/src/Hakyll/Core/ResourceProvider/Metadata.hs
@@ -6,7 +6,7 @@ module Hakyll.Core.ResourceProvider.Metadata
--------------------------------------------------------------------------------
-import Control.Applicative ((<$>), (<*), (<*>))
+import Control.Applicative
import Control.Arrow (second)
import qualified Data.ByteString.Char8 as BC
import qualified Data.Map as M
@@ -80,16 +80,22 @@ inlineSpace = P.oneOf ['\t', ' '] <?> "space"
--------------------------------------------------------------------------------
+-- | Parse Windows newlines as well (i.e. "\n" or "\r\n")
+newline :: Parser String
+newline = P.string "\n" <|> P.string "\r\n"
+
+
+--------------------------------------------------------------------------------
-- | Parse a single metadata field
metadataField :: Parser (String, String)
metadataField = do
key <- P.manyTill P.alphaNum $ P.char ':'
P.skipMany1 inlineSpace <?> "space followed by metadata for: " ++ key
- value <- P.manyTill P.anyChar P.newline
+ value <- P.manyTill P.anyChar newline
trailing' <- P.many trailing
return (key, trim $ value ++ concat trailing')
where
- trailing = (++) <$> P.many1 inlineSpace <*> P.manyTill P.anyChar P.newline
+ trailing = (++) <$> P.many1 inlineSpace <*> P.manyTill P.anyChar newline
--------------------------------------------------------------------------------
@@ -102,11 +108,11 @@ metadata = P.many metadataField
-- | Parse a metadata block, including delimiters and trailing newlines
metadataBlock :: Parser [(String, String)]
metadataBlock = do
- open <- P.many1 (P.char '-') <* P.many inlineSpace <* P.newline
+ open <- P.many1 (P.char '-') <* P.many inlineSpace <* newline
metadata' <- metadata
_ <- P.choice $ map (P.string . replicate (length open)) ['-', '.']
P.skipMany inlineSpace
- P.skipMany1 P.newline
+ P.skipMany1 newline
return metadata'