From fef1172c77e510054fc9bf95d5d2b85b8a15478e Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Mon, 13 Dec 2010 22:02:54 +0100 Subject: ContextManipulations → Metadata MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Text/Hakyll/Transformer.hs | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'src/Text/Hakyll/Transformer.hs') diff --git a/src/Text/Hakyll/Transformer.hs b/src/Text/Hakyll/Transformer.hs index fff8470..669e1d0 100644 --- a/src/Text/Hakyll/Transformer.hs +++ b/src/Text/Hakyll/Transformer.hs @@ -5,17 +5,17 @@ module Text.Hakyll.Transformer , transformResourceM , transformData , transformDataM - , transformMetaData - , transformMetaDataM + , transformMetadata + , transformMetadataM , runTransformer , runTransformerForced ) where -import Data.Monoid (mappend, mempty) +import Data.Monoid (Monoid, mappend, mempty) import Control.Arrow import Control.Category import Control.Applicative ((<$>)) -import Control.Monad ((<=<), unless) +import Control.Monad ((<=<), unless, liftM2) import Prelude hiding ((.), id) import Text.Hakyll.Resource @@ -34,6 +34,16 @@ data Transformer a b = Transformer transformerFunction :: Resource a -> Hakyll (Resource b) } +instance Monoid b => Monoid (Transformer a b) where + mempty = arr (const mempty) + mappend x y = Transformer + { transformerDependencies = + transformerDependencies x ++ transformerDependencies y + , transformerUrl = transformerUrl x + , transformerFunction = \r -> + liftM2 mappend (transformerFunction x r) (transformerFunction y r) + } + instance Category Transformer where id = Transformer { transformerDependencies = [] @@ -70,11 +80,11 @@ transformDataM :: (a -> Hakyll b) -> Transformer a b transformDataM f = transformResourceM $ \(Resource m x) -> f x >>= return . Resource m -transformMetaData :: (Metadata -> Metadata) -> Transformer a a -transformMetaData = transformMetaDataM . (return .) +transformMetadata :: (Metadata -> Metadata) -> Transformer a a +transformMetadata = transformMetadataM . (return .) -transformMetaDataM :: (Metadata -> Hakyll Metadata) -> Transformer a a -transformMetaDataM f = transformResourceM $ \(Resource m x) -> do +transformMetadataM :: (Metadata -> Hakyll Metadata) -> Transformer a a +transformMetadataM f = transformResourceM $ \(Resource m x) -> do m' <- f m return $ Resource m' x -- cgit v1.2.3