1 {-# LANGUAGE CPP #-} 2 module Databrary.Web.Types 3 ( WebFileInfo(..) 4 , WebFileMap 5 , Web(..) 6 , WebGeneratorM 7 , WebGenerator 8 ) where 9 10 #ifdef DEVEL 11 import Control.Concurrent.MVar (MVar) 12 #endif 13 import Control.Monad.Trans.Except (ExceptT) 14 import Control.Monad.Trans.State.Strict (StateT) 15 import Crypto.Hash (Digest, MD5) 16 import qualified Data.ByteString as BS 17 import qualified Data.HashMap.Strict as HM 18 19 import Databrary.Model.Time 20 import Databrary.Web 21 22 data WebFileInfo = WebFileInfo 23 { webFileFormat :: BS.ByteString 24 , webFileHash :: !(Digest MD5) 25 , webFileTimestamp :: !Timestamp 26 } 27 28 type WebFileMap = HM.HashMap WebFilePath WebFileInfo 29 30 data Web = Web 31 { webCache :: 32 #ifdef DEVEL 33 MVar 34 #endif 35 WebFileMap 36 , webVersion :: BS.ByteString -- Compute hash or increment of all js and css files 37 } 38 39 type WebGeneratorM a = ExceptT String (StateT WebFileMap IO) a 40 type WebGenerator = (WebFilePath, Maybe WebFileInfo) -> WebGeneratorM Bool 41