Make staticRoutes more resilient to missing imports
This commit is contained in:
parent
fb42a6d4bb
commit
86ad70da6a
3
yesod-static/ChangeLog.md
Normal file
3
yesod-static/ChangeLog.md
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
## 1.4.0.3
|
||||||
|
|
||||||
|
Fix bug when `StaticRoute` constructor is not imported.
|
||||||
@ -247,7 +247,7 @@ staticFiles dir = mkStaticFiles dir
|
|||||||
-- files, but only need to refer to a few of them from Haskell.
|
-- files, but only need to refer to a few of them from Haskell.
|
||||||
staticFilesList :: Prelude.FilePath -> [Prelude.FilePath] -> Q [Dec]
|
staticFilesList :: Prelude.FilePath -> [Prelude.FilePath] -> Q [Dec]
|
||||||
staticFilesList dir fs =
|
staticFilesList dir fs =
|
||||||
mkStaticFilesList dir (map split fs) "StaticRoute" True
|
mkStaticFilesList dir (map split fs) True
|
||||||
where
|
where
|
||||||
split :: Prelude.FilePath -> [String]
|
split :: Prelude.FilePath -> [String]
|
||||||
split [] = []
|
split [] = []
|
||||||
@ -266,7 +266,7 @@ staticFilesList dir fs =
|
|||||||
-- contents, however they'll need send a request to the server to
|
-- contents, however they'll need send a request to the server to
|
||||||
-- see if their copy is up-to-date.
|
-- see if their copy is up-to-date.
|
||||||
publicFiles :: Prelude.FilePath -> Q [Dec]
|
publicFiles :: Prelude.FilePath -> Q [Dec]
|
||||||
publicFiles dir = mkStaticFiles' dir "StaticRoute" False
|
publicFiles dir = mkStaticFiles' dir False
|
||||||
|
|
||||||
|
|
||||||
mkHashMap :: Prelude.FilePath -> IO (M.Map F.FilePath S8.ByteString)
|
mkHashMap :: Prelude.FilePath -> IO (M.Map F.FilePath S8.ByteString)
|
||||||
@ -311,23 +311,21 @@ cachedETagLookup dir = do
|
|||||||
return $ (\f -> return $ M.lookup f etags)
|
return $ (\f -> return $ M.lookup f etags)
|
||||||
|
|
||||||
mkStaticFiles :: Prelude.FilePath -> Q [Dec]
|
mkStaticFiles :: Prelude.FilePath -> Q [Dec]
|
||||||
mkStaticFiles fp = mkStaticFiles' fp "StaticRoute" True
|
mkStaticFiles fp = mkStaticFiles' fp True
|
||||||
|
|
||||||
mkStaticFiles' :: Prelude.FilePath -- ^ static directory
|
mkStaticFiles' :: Prelude.FilePath -- ^ static directory
|
||||||
-> String -- ^ route constructor "StaticRoute"
|
|
||||||
-> Bool -- ^ append checksum query parameter
|
-> Bool -- ^ append checksum query parameter
|
||||||
-> Q [Dec]
|
-> Q [Dec]
|
||||||
mkStaticFiles' fp routeConName makeHash = do
|
mkStaticFiles' fp makeHash = do
|
||||||
fs <- qRunIO $ getFileListPieces fp
|
fs <- qRunIO $ getFileListPieces fp
|
||||||
mkStaticFilesList fp fs routeConName makeHash
|
mkStaticFilesList fp fs makeHash
|
||||||
|
|
||||||
mkStaticFilesList
|
mkStaticFilesList
|
||||||
:: Prelude.FilePath -- ^ static directory
|
:: Prelude.FilePath -- ^ static directory
|
||||||
-> [[String]] -- ^ list of files to create identifiers for
|
-> [[String]] -- ^ list of files to create identifiers for
|
||||||
-> String -- ^ route constructor "StaticRoute"
|
|
||||||
-> Bool -- ^ append checksum query parameter
|
-> Bool -- ^ append checksum query parameter
|
||||||
-> Q [Dec]
|
-> Q [Dec]
|
||||||
mkStaticFilesList fp fs routeConName makeHash = do
|
mkStaticFilesList fp fs makeHash = do
|
||||||
concat `fmap` mapM mkRoute fs
|
concat `fmap` mapM mkRoute fs
|
||||||
where
|
where
|
||||||
replace' c
|
replace' c
|
||||||
@ -345,16 +343,15 @@ mkStaticFilesList fp fs routeConName makeHash = do
|
|||||||
| isLower (head name') -> name'
|
| isLower (head name') -> name'
|
||||||
| otherwise -> '_' : name'
|
| otherwise -> '_' : name'
|
||||||
f' <- [|map pack $(TH.lift f)|]
|
f' <- [|map pack $(TH.lift f)|]
|
||||||
let route = mkName routeConName
|
|
||||||
pack' <- [|pack|]
|
pack' <- [|pack|]
|
||||||
qs <- if makeHash
|
qs <- if makeHash
|
||||||
then do hash <- qRunIO $ base64md5File $ pathFromRawPieces fp f
|
then do hash <- qRunIO $ base64md5File $ pathFromRawPieces fp f
|
||||||
[|[(pack "etag", pack $(TH.lift hash))]|]
|
[|[(pack "etag", pack $(TH.lift hash))]|]
|
||||||
else return $ ListE []
|
else return $ ListE []
|
||||||
return
|
return
|
||||||
[ SigD routeName $ ConT route
|
[ SigD routeName $ ConT ''StaticRoute
|
||||||
, FunD routeName
|
, FunD routeName
|
||||||
[ Clause [] (NormalB $ (ConE route) `AppE` f' `AppE` qs) []
|
[ Clause [] (NormalB $ (ConE 'StaticRoute) `AppE` f' `AppE` qs) []
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
name: yesod-static
|
name: yesod-static
|
||||||
version: 1.4.0.2
|
version: 1.4.0.3
|
||||||
license: MIT
|
license: MIT
|
||||||
license-file: LICENSE
|
license-file: LICENSE
|
||||||
author: Michael Snoyman <michael@snoyman.com>
|
author: Michael Snoyman <michael@snoyman.com>
|
||||||
@ -22,6 +22,7 @@ extra-source-files:
|
|||||||
test/embed-dir/foo
|
test/embed-dir/foo
|
||||||
test/embed-dir/lorem.txt
|
test/embed-dir/lorem.txt
|
||||||
test/embed-dir/abc/def.txt
|
test/embed-dir/abc/def.txt
|
||||||
|
ChangeLog.md
|
||||||
|
|
||||||
library
|
library
|
||||||
build-depends: base >= 4 && < 5
|
build-depends: base >= 4 && < 5
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user