summaryrefslogtreecommitdiff
path: root/src/Hakyll/Core
diff options
context:
space:
mode:
authorJasper Van der Jeugt <m@jaspervdj.be>2012-11-13 23:59:49 +0100
committerJasper Van der Jeugt <m@jaspervdj.be>2012-11-13 23:59:49 +0100
commit555f510e547cf2496bf909bd578c77f4c3b1a5d5 (patch)
treeec325c6a077a5849d517809da8d45b264ab8d3ce /src/Hakyll/Core
parent50f8f819f9b67822305350b77117d4cb7a00cf45 (diff)
downloadhakyll-555f510e547cf2496bf909bd578c77f4c3b1a5d5.tar.gz
Various things...
Diffstat (limited to 'src/Hakyll/Core')
-rw-r--r--src/Hakyll/Core/Compiler.hs31
-rw-r--r--src/Hakyll/Core/Compiler/Require.hs4
-rw-r--r--src/Hakyll/Core/Dependencies.hs22
-rw-r--r--src/Hakyll/Core/Metadata.hs14
4 files changed, 38 insertions, 33 deletions
diff --git a/src/Hakyll/Core/Compiler.hs b/src/Hakyll/Core/Compiler.hs
index e59506f..67de7c8 100644
--- a/src/Hakyll/Core/Compiler.hs
+++ b/src/Hakyll/Core/Compiler.hs
@@ -6,6 +6,8 @@ module Hakyll.Core.Compiler
, getIdentifier
, getRoute
, getRouteFor
+ , getMetadata
+ , getMetadataFor
, getResourceBody
, getResourceString
, getResourceLBS
@@ -20,22 +22,24 @@ module Hakyll.Core.Compiler
--------------------------------------------------------------------------------
-import Control.Applicative ((<$>))
-import Data.Binary (Binary)
-import Data.ByteString.Lazy (ByteString)
-import Data.Typeable (Typeable)
-import Prelude hiding (id, (.))
-import System.Environment (getProgName)
+import Control.Applicative ((<$>))
+import Data.Binary (Binary)
+import Data.ByteString.Lazy (ByteString)
+import Data.Typeable (Typeable)
+import Prelude hiding (id, (.))
+import System.Environment (getProgName)
--------------------------------------------------------------------------------
import Hakyll.Core.Compiler.Internal
import Hakyll.Core.Compiler.Require
+import Hakyll.Core.Dependencies
import Hakyll.Core.Identifier
import Hakyll.Core.Logger
+import Hakyll.Core.Metadata
import Hakyll.Core.ResourceProvider
import Hakyll.Core.Routes
-import qualified Hakyll.Core.Store as Store
+import qualified Hakyll.Core.Store as Store
import Hakyll.Core.Writable
@@ -60,6 +64,19 @@ getRouteFor identifier = do
--------------------------------------------------------------------------------
+getMetadata :: Compiler Metadata
+getMetadata = getIdentifier >>= getMetadataFor
+
+
+--------------------------------------------------------------------------------
+getMetadataFor :: Identifier -> Compiler Metadata
+getMetadataFor identifier = do
+ provider <- compilerProvider <$> compilerAsk
+ compilerTell [IdentifierDependency identifier]
+ compilerUnsafeIO $ resourceMetadata provider identifier
+
+
+--------------------------------------------------------------------------------
-- | Get the body of the underlying resource
getResourceBody :: Compiler String
getResourceBody = getResourceWith resourceBody
diff --git a/src/Hakyll/Core/Compiler/Require.hs b/src/Hakyll/Core/Compiler/Require.hs
index 1dc96e7..5838852 100644
--- a/src/Hakyll/Core/Compiler/Require.hs
+++ b/src/Hakyll/Core/Compiler/Require.hs
@@ -31,7 +31,7 @@ require :: (Binary a, Typeable a) => Identifier -> Compiler a
require id' = do
store <- compilerStore <$> compilerAsk
- compilerTell [Identifier id']
+ compilerTell [IdentifierDependency id']
compilerResult $ CompilerRequire id' $ do
result <- compilerUnsafeIO $ Store.get store (key id')
case result of
@@ -54,7 +54,7 @@ requireAll :: (Binary a, Typeable a) => Pattern -> Compiler [a]
requireAll pattern = do
universe <- compilerUniverse <$> compilerAsk
let matching = filterMatches pattern universe
- compilerTell [Pattern pattern matching]
+ compilerTell [PatternDependency pattern matching]
mapM require matching
diff --git a/src/Hakyll/Core/Dependencies.hs b/src/Hakyll/Core/Dependencies.hs
index 0a83375..e81b38f 100644
--- a/src/Hakyll/Core/Dependencies.hs
+++ b/src/Hakyll/Core/Dependencies.hs
@@ -32,18 +32,18 @@ import Hakyll.Core.Identifier.Pattern
--------------------------------------------------------------------------------
data Dependency
- = Pattern Pattern [Identifier]
- | Identifier Identifier
+ = PatternDependency Pattern [Identifier]
+ | IdentifierDependency Identifier
deriving (Show, Typeable)
--------------------------------------------------------------------------------
instance Binary Dependency where
- put (Pattern p is) = putWord8 0 >> put p >> put is
- put (Identifier i) = putWord8 1 >> put i
+ put (PatternDependency p is) = putWord8 0 >> put p >> put is
+ put (IdentifierDependency i) = putWord8 1 >> put i
get = getWord8 >>= \t -> case t of
- 0 -> Pattern <$> get <*> get
- 1 -> Identifier <$> get
+ 0 -> PatternDependency <$> get <*> get
+ 1 -> IdentifierDependency <$> get
_ -> error "Data.Binary.get: Invalid Dependency"
@@ -89,7 +89,7 @@ dependenciesFor :: Identifier -> DependencyM [Identifier]
dependenciesFor id' = do
facts <- dependencyFacts <$> State.get
let relevant = fromMaybe [] $ M.lookup id' facts
- return [i | Identifier i <- relevant]
+ return [i | IdentifierDependency i <- relevant]
--------------------------------------------------------------------------------
@@ -111,16 +111,16 @@ checkChangedPatterns = do
State.modify $ \s -> s
{dependencyFacts = M.insert id' deps' $ dependencyFacts s}
where
- go _ ds (Identifier i) = return $ Identifier i : ds
- go id' ds (Pattern p ls) = do
+ go _ ds (IdentifierDependency i) = return $ IdentifierDependency i : ds
+ go id' ds (PatternDependency p ls) = do
universe <- ask
let ls' = filterMatches p universe
if ls == ls'
- then return $ Pattern p ls : ds
+ then return $ PatternDependency p ls : ds
else do
tell [show id' ++ " is out-of-date because a pattern changed"]
markOod id'
- return $ Pattern p ls' : ds
+ return $ PatternDependency p ls' : ds
--------------------------------------------------------------------------------
diff --git a/src/Hakyll/Core/Metadata.hs b/src/Hakyll/Core/Metadata.hs
index a417624..f3e99f5 100644
--- a/src/Hakyll/Core/Metadata.hs
+++ b/src/Hakyll/Core/Metadata.hs
@@ -1,24 +1,12 @@
--------------------------------------------------------------------------------
module Hakyll.Core.Metadata
( Metadata
- , MonadMetadata (..)
) where
--------------------------------------------------------------------------------
-import Data.Map (Map)
-
-
---------------------------------------------------------------------------------
-import Hakyll.Core.Identifier
+import Data.Map (Map)
--------------------------------------------------------------------------------
type Metadata = Map String String
-
-
---------------------------------------------------------------------------------
-class MonadMetadata m where
- identifierMetadata :: Identifier -> m Metadata
- -- allMetadata :: m [(Resource, Metadata)]
- -- patternMetadata :: Pattern a -> m [(Resource, Metadata)]