hakyll/src/Hakyll/Core/Writable.hs

57 lines
1.9 KiB
Haskell
Raw Normal View History

2012-11-18 20:56:52 +00:00
--------------------------------------------------------------------------------
2010-12-25 19:18:36 +00:00
-- | Describes writable items; items that can be saved to the disk
2012-11-18 20:56:52 +00:00
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeSynonymInstances #-}
2010-12-25 19:18:36 +00:00
module Hakyll.Core.Writable
( Writable (..)
) where
2010-12-30 12:49:58 +00:00
2012-11-18 20:56:52 +00:00
--------------------------------------------------------------------------------
import qualified Data.ByteString as SB
import qualified Data.ByteString.Lazy as LB
import Data.Word (Word8)
import Text.Blaze.Html (Html)
import Text.Blaze.Html.Renderer.String (renderHtml)
2010-12-30 12:49:58 +00:00
2011-05-02 21:16:43 +00:00
2012-11-18 20:56:52 +00:00
--------------------------------------------------------------------------------
import Hakyll.Core.Item
--------------------------------------------------------------------------------
2010-12-25 19:18:36 +00:00
-- | Describes an item that can be saved to the disk
class Writable a where
-- | Save an item to the given filepath
2012-11-18 20:56:52 +00:00
write :: FilePath -> Item a -> IO ()
2010-12-25 19:18:36 +00:00
2012-11-18 20:56:52 +00:00
--------------------------------------------------------------------------------
2011-05-22 18:19:55 +00:00
instance Writable () where
write _ _ = return ()
2012-11-18 20:56:52 +00:00
--------------------------------------------------------------------------------
2010-12-25 19:18:36 +00:00
instance Writable [Char] where
2012-11-18 20:56:52 +00:00
write p = writeFile p . itemBody
2010-12-30 12:49:58 +00:00
2012-11-18 20:56:52 +00:00
--------------------------------------------------------------------------------
2011-03-04 10:46:06 +00:00
instance Writable SB.ByteString where
2012-11-18 20:56:52 +00:00
write p = SB.writeFile p . itemBody
2011-03-04 10:46:06 +00:00
2012-11-18 20:56:52 +00:00
--------------------------------------------------------------------------------
2011-05-06 08:28:35 +00:00
instance Writable LB.ByteString where
2012-11-18 20:56:52 +00:00
write p = LB.writeFile p . itemBody
2011-05-06 08:28:35 +00:00
2012-11-18 20:56:52 +00:00
--------------------------------------------------------------------------------
instance Writable [Word8] where
2012-11-18 20:56:52 +00:00
write p = write p . fmap SB.pack
2011-03-04 10:46:06 +00:00
2011-05-02 21:16:43 +00:00
2012-11-18 20:56:52 +00:00
--------------------------------------------------------------------------------
instance Writable Html where
write p = write p . fmap renderHtml