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