2012-11-18 20:56:52 +00:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- | An item is a combination of some content and its 'Identifier'. This way, we
|
|
|
|
-- can still use the 'Identifier' to access metadata.
|
|
|
|
{-# LANGUAGE DeriveDataTypeable #-}
|
|
|
|
module Hakyll.Core.Item
|
|
|
|
( Item (..)
|
|
|
|
, itemSetBody
|
2012-12-26 14:00:45 +00:00
|
|
|
, withItemBody
|
2012-11-18 20:56:52 +00:00
|
|
|
) where
|
|
|
|
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
2012-12-26 14:00:45 +00:00
|
|
|
import Control.Applicative (Applicative, (<$>), (<*>))
|
|
|
|
import Data.Binary (Binary (..))
|
|
|
|
import Data.Foldable (Foldable (..))
|
|
|
|
import Data.Traversable (Traversable (..))
|
|
|
|
import Data.Typeable (Typeable)
|
|
|
|
import Prelude hiding (foldr)
|
2012-11-18 20:56:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
2012-12-26 14:00:45 +00:00
|
|
|
import Hakyll.Core.Compiler.Internal
|
2012-11-18 20:56:52 +00:00
|
|
|
import Hakyll.Core.Identifier
|
|
|
|
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
data Item a = Item
|
|
|
|
{ itemIdentifier :: Identifier
|
|
|
|
, itemBody :: a
|
|
|
|
} deriving (Show, Typeable)
|
|
|
|
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
instance Functor Item where
|
|
|
|
fmap f (Item i x) = Item i (f x)
|
|
|
|
|
|
|
|
|
2012-12-26 14:00:45 +00:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
instance Foldable Item where
|
|
|
|
foldr f z (Item _ x) = f x z
|
|
|
|
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
instance Traversable Item where
|
|
|
|
traverse f (Item i x) = Item i <$> f x
|
|
|
|
|
|
|
|
|
2012-11-18 20:56:52 +00:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
instance Binary a => Binary (Item a) where
|
|
|
|
put (Item i x) = put i >> put x
|
|
|
|
get = Item <$> get <*> get
|
|
|
|
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
itemSetBody :: a -> Item b -> Item a
|
|
|
|
itemSetBody x (Item i _) = Item i x
|
2012-11-20 10:36:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
2012-12-26 14:00:45 +00:00
|
|
|
-- | Perform a compiler action on the item body. This is the same as 'traverse',
|
|
|
|
-- but looks less intimidating.
|
|
|
|
--
|
|
|
|
-- > withItemBody = traverse
|
|
|
|
withItemBody :: (a -> Compiler b) -> Item a -> Compiler (Item b)
|
|
|
|
withItemBody = traverse
|