@@ -3,11 +3,10 @@
3{-# LANGUAGE ScopedTypeVariables #-}
3{-# LANGUAGE ScopedTypeVariables #-}
4module Hakyll.Core.Compiler
4module Hakyll.Core.Compiler
6− , getIdentifier
6+ , getUnderlying
9 , getMetadata
9 , getMetadata
11 , getResourceBody
10 , getResourceBody
12 , getResourceString
11 , getResourceString
13 , getResourceLBS
12 , getResourceLBS
@@ -34,42 +33,39 @@ import Hakyll.Core.Compiler.Internal
34import Hakyll.Core.Compiler.Require
33import Hakyll.Core.Compiler.Require
35import Hakyll.Core.Dependencies
34import Hakyll.Core.Dependencies
36import Hakyll.Core.Identifier
35import Hakyll.Core.Identifier
36+import Hakyll.Core.Item
37import Hakyll.Core.Logger as Logger
37import Hakyll.Core.Logger as Logger
38import Hakyll.Core.Metadata
38import Hakyll.Core.Metadata
39−import Hakyll.Core.ResourceProvider
39+import Hakyll.Core.Provider
40import Hakyll.Core.Routes
40import Hakyll.Core.Routes
41import qualified Hakyll.Core.Store as Store
41import qualified Hakyll.Core.Store as Store
42−import Hakyll.Core.Writable
45--------------------------------------------------------------------------------
44--------------------------------------------------------------------------------
46−-- | Get the identifier of the item that is currently being compiled
45+-- | Get the underlying identifier. Only use this if you know what you're doing.
47−getIdentifier :: Compiler Identifier
46+getUnderlying :: Compiler Identifier
48−getIdentifier = compilerIdentifier <$> compilerAsk
47+getUnderlying = compilerUnderlying <$> compilerAsk
51--------------------------------------------------------------------------------
50--------------------------------------------------------------------------------
52−-- | Get the route we are using for this item
51+makeItem :: a -> Compiler (Item a)
53−getRoute :: Compiler (Maybe FilePath)
52+makeItem x = do
54−getRoute = getIdentifier >>= getRouteFor
53+ identifier <- getUnderlying
54+ return $ Item identifier x
57--------------------------------------------------------------------------------
57--------------------------------------------------------------------------------
58-- | Get the route for a specified item
58-- | Get the route for a specified item
59−getRouteFor :: Identifier -> Compiler (Maybe FilePath)
59+getRoute :: Identifier -> Compiler (Maybe FilePath)
60−getRouteFor identifier = do
60+getRoute identifier = do
61 routes <- compilerRoutes <$> compilerAsk
61 routes <- compilerRoutes <$> compilerAsk
62 return $ runRoutes routes identifier
62 return $ runRoutes routes identifier
65−--------------------------------------------------------------------------------
66−getMetadata :: Compiler Metadata
67−getMetadata = getIdentifier >>= getMetadataFor
70--------------------------------------------------------------------------------
66--------------------------------------------------------------------------------
71−getMetadataFor :: Identifier -> Compiler Metadata
67+getMetadata :: Identifier -> Compiler Metadata
72−getMetadataFor identifier = do
68+getMetadata identifier = do
73 provider <- compilerProvider <$> compilerAsk
69 provider <- compilerProvider <$> compilerAsk
74 compilerTellDependencies [IdentifierDependency identifier]
70 compilerTellDependencies [IdentifierDependency identifier]
75 compilerUnsafeIO $ resourceMetadata provider identifier
71 compilerUnsafeIO $ resourceMetadata provider identifier
@@ -77,32 +73,31 @@ getMetadataFor identifier = do
78--------------------------------------------------------------------------------
74--------------------------------------------------------------------------------
79-- | Get the body of the underlying resource
75-- | Get the body of the underlying resource
80−getResourceBody :: Compiler String
76+getResourceBody :: Compiler (Item String)
81getResourceBody = getResourceWith resourceBody
77getResourceBody = getResourceWith resourceBody
84--------------------------------------------------------------------------------
80--------------------------------------------------------------------------------
85-- | Get the resource we are compiling as a string
81-- | Get the resource we are compiling as a string
86−getResourceString :: Compiler String
82+getResourceString :: Compiler (Item String)
87getResourceString = getResourceWith $ const resourceString
83getResourceString = getResourceWith $ const resourceString
90--------------------------------------------------------------------------------
86--------------------------------------------------------------------------------
91-- | Get the resource we are compiling as a lazy bytestring
87-- | Get the resource we are compiling as a lazy bytestring
93−getResourceLBS :: Compiler ByteString
88+getResourceLBS :: Compiler (Item ByteString)
94getResourceLBS = getResourceWith $ const resourceLBS
89getResourceLBS = getResourceWith $ const resourceLBS
97--------------------------------------------------------------------------------
92--------------------------------------------------------------------------------
98-- | Overloadable function for 'getResourceString' and 'getResourceLBS'
93-- | Overloadable function for 'getResourceString' and 'getResourceLBS'
99−getResourceWith :: (ResourceProvider -> Identifier -> IO a) -> Compiler a
94+getResourceWith :: (Provider -> Identifier -> IO a) -> Compiler (Item a)
100getResourceWith reader = do
95getResourceWith reader = do
101 provider <- compilerProvider <$> compilerAsk
96 provider <- compilerProvider <$> compilerAsk
102− id' <- compilerIdentifier <$> compilerAsk
97+ id' <- compilerUnderlying <$> compilerAsk
103 let filePath = toFilePath id'
98 let filePath = toFilePath id'
104 if resourceExists provider id'
99 if resourceExists provider id'
105− then compilerUnsafeIO $ reader provider id'
100+ then compilerUnsafeIO $ Item id' <$> reader provider id'
106 else compilerThrow $ error' filePath
101 else compilerThrow $ error' filePath
108 error' fp = "Hakyll.Core.Compiler.getResourceWith: resource " ++
103 error' fp = "Hakyll.Core.Compiler.getResourceWith: resource " ++
@@ -110,12 +105,12 @@ getResourceWith reader = do
112--------------------------------------------------------------------------------
107--------------------------------------------------------------------------------
113−cached :: (Binary a, Typeable a, Writable a)
108+cached :: (Binary a, Typeable a)
114 => String
109 => String
115 -> Compiler a
110 -> Compiler a
116 -> Compiler a
111 -> Compiler a
117cached name compiler = do
112cached name compiler = do
118− id' <- compilerIdentifier <$> compilerAsk
113+ id' <- compilerUnderlying <$> compilerAsk
119 store <- compilerStore <$> compilerAsk
114 store <- compilerStore <$> compilerAsk
120 provider <- compilerProvider <$> compilerAsk
115 provider <- compilerProvider <$> compilerAsk
121 modified <- compilerUnsafeIO $ resourceModified provider id'
116 modified <- compilerUnsafeIO $ resourceModified provider id'