hakyll/src/Hakyll/Core/Writable.hs

36 lines
962 B
Haskell
Raw Normal View History

2010-12-25 19:18:36 +00:00
-- | Describes writable items; items that can be saved to the disk
--
2010-12-30 12:49:58 +00:00
{-# LANGUAGE FlexibleInstances, GeneralizedNewtypeDeriving,
DeriveDataTypeable #-}
2010-12-25 19:18:36 +00:00
module Hakyll.Core.Writable
( Writable (..)
2010-12-30 12:49:58 +00:00
, CopyFile (..)
2010-12-25 19:18:36 +00:00
) where
2010-12-30 12:49:58 +00:00
import System.Directory (copyFile)
import Data.Word (Word8)
2010-12-30 12:49:58 +00:00
import qualified Data.ByteString as SB
2010-12-30 12:49:58 +00:00
import Data.Binary (Binary)
import Data.Typeable (Typeable)
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
write :: FilePath -> a -> IO ()
instance Writable [Char] where
write = writeFile
2010-12-30 12:49:58 +00:00
instance Writable [Word8] where
write p = SB.writeFile p . SB.pack
2010-12-30 12:49:58 +00:00
-- | Newtype construct around 'FilePath' which will copy the file directly
--
newtype CopyFile = CopyFile {unCopyFile :: FilePath}
deriving (Show, Eq, Ord, Binary, Typeable)
instance Writable CopyFile where
write dst (CopyFile src) = copyFile src dst