File: Writable.hs

package info (click to toggle)
haskell-hakyll 4.16.2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 928 kB
  • sloc: haskell: 6,504; xml: 44; makefile: 9
file content (56 lines) | stat: -rw-r--r-- 1,926 bytes parent folder | download | duplicates (6)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
--------------------------------------------------------------------------------
-- | Describes writable items; items that can be saved to the disk
{-# LANGUAGE FlexibleInstances    #-}
{-# LANGUAGE TypeSynonymInstances #-}
module Hakyll.Core.Writable
    ( Writable (..)
    ) where


--------------------------------------------------------------------------------
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)


--------------------------------------------------------------------------------
import           Hakyll.Core.Item


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


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


--------------------------------------------------------------------------------
instance Writable [Char] where
    write p = writeFile p . itemBody


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


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


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


--------------------------------------------------------------------------------
instance Writable Html where
    write p = write p . fmap renderHtml