diff --git a/Yesod/Helpers/Static.hs b/Yesod/Helpers/Static.hs index 22c28e27..d7141388 100644 --- a/Yesod/Helpers/Static.hs +++ b/Yesod/Helpers/Static.hs @@ -59,7 +59,6 @@ import Data.List (intercalate) import Language.Haskell.TH import Language.Haskell.TH.Syntax -import Data.Char import qualified Data.ByteString.Lazy as L import Data.Digest.Pure.MD5 import qualified Data.ByteString.Base64 @@ -67,13 +66,14 @@ import qualified Data.ByteString.Char8 as S8 import qualified Data.Serialize import Data.Text (Text, pack) import Data.Monoid (mempty) +import qualified Data.Map as M +import Data.IORef (readIORef, newIORef, writeIORef) import Network.Wai.Application.Static ( StaticSettings (..), CacheSettings (..) , defaultStaticSettings, defaultPublicSettings , staticAppPieces , pathFromPieces - , Pieces ) #if TEST @@ -103,7 +103,7 @@ static root fp = do hashes <- mkHashMap fp return $ Static $ (defaultStaticSettings (Forever $ isStaticRequest hashes)) { ssFolder = fp - , ssMkRedirect = \_ newPath -> S8.pack $ root ++ "/" ++ newPath + , ssMkRedirect = \_ newPath -> S8.append (S8.pack (root ++ "/")) newPath } where isStaticRequest hashes reqf reqh = case M.lookup reqf hashes of @@ -114,7 +114,7 @@ static root fp = do public :: String -> FilePath -> CacheSettings -> Public public root fp cache = Public $ (defaultPublicSettings cache) { ssFolder = fp - , ssMkRedirect = \_ newPath -> S8.pack $ root ++ "/" ++ newPath + , ssMkRedirect = \_ newPath -> S8.append (S8.pack (root ++ "/")) newPath } publicProduction :: String -> FilePath -> IO Public @@ -137,7 +137,7 @@ publicDevel root fp = do -- E.g. When generating image galleries. data StaticRoute = StaticRoute [Text] [(Text, Text)] deriving (Eq, Show, Read) -data PublicRoute = PublicRoute [String] [(String, String)] +data PublicRoute = PublicRoute [Text] [(Text, Text)] deriving (Eq, Show, Read) type instance Route Static = StaticRoute @@ -190,11 +190,11 @@ mkHashMap dir = do fs <- getFileListPieces dir hashAlist fs >>= return . M.fromList where - hashAlist :: [Pieces] -> IO [(FilePath, S8.ByteString)] + hashAlist :: [[String]] -> IO [(FilePath, S8.ByteString)] hashAlist fs = mapM hashPair fs where - hashPair :: Pieces -> IO (FilePath, S8.ByteString) - hashPair pieces = do let file = pathFromPieces dir pieces + hashPair :: [String] -> IO (FilePath, S8.ByteString) + hashPair pieces = do let file = pathFromPieces dir (map pack pieces) h <- base64md5File file return (file, S8.pack h) @@ -243,7 +243,7 @@ mkStaticFiles' fp routeConName makeHash = do let route = mkName routeConName pack' <- [|pack|] qs <- if makeHash - then do hash <- qRunIO $ base64md5File $ pathFromPieces fp f + then do hash <- qRunIO $ base64md5File $ pathFromPieces fp (map pack f) [|[(pack $(lift hash), mempty)]|] else return $ ListE [] return diff --git a/yesod-static.cabal b/yesod-static.cabal index fd47681b..99b4e97d 100644 --- a/yesod-static.cabal +++ b/yesod-static.cabal @@ -1,9 +1,5 @@ name: yesod-static -<<<<<<< HEAD version: 0.1.0 -======= -version: 0.1.0.0 ->>>>>>> update caching interface license: BSD3 license-file: LICENSE author: Michael Snoyman @@ -21,6 +17,8 @@ flag test library build-depends: base >= 4 && < 5 + , containers >= 0.4 + , old-time >= 1.0 , yesod-core >= 0.8 && < 0.9 , base64-bytestring >= 0.1.0.1 && < 0.2 , pureMD5 >= 2.1.0.3 && < 2.2 @@ -29,7 +27,7 @@ library , template-haskell , directory >= 1.0 && < 1.2 , transformers >= 0.2 && < 0.3 - , wai-app-static >= 0.1 && < 0.2 + , wai-app-static >= 0.3 && < 0.4 , text >= 0.5 && < 1.0 exposed-modules: Yesod.Helpers.Static ghc-options: -Wall