summaryrefslogtreecommitdiff
path: root/src/Hakyll/Core/Writable.hs
blob: d001f00069d441b4d564c833bb69868f3abd031a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
-- | Describes writable items; items that can be saved to the disk
--
{-# LANGUAGE FlexibleInstances, TypeSynonymInstances #-}
module Hakyll.Core.Writable
    ( Writable (..)
    ) where

import Data.Word (Word8)

import qualified Data.ByteString as SB
import qualified Data.ByteString.Lazy as LB
import Text.Blaze (Html)
import Text.Blaze.Renderer.String (renderHtml)

import Hakyll.Core.Identifier

-- | Describes an item that can be saved to the disk
--
class Writable a where
    -- | Save an item to the given filepath
    write :: FilePath -> a -> IO ()

instance Writable () where
    write _ _ = return ()

instance Writable [Char] where
    write = writeFile

instance Writable SB.ByteString where
    write p = SB.writeFile p

instance Writable LB.ByteString where
    write p = LB.writeFile p

instance Writable [Word8] where
    write p = write p . SB.pack

instance Writable Html where
    write p html = write p $ renderHtml html

instance Writable (Identifier a) where
    write p = write p . show