yesod-static-streamly 0.1.2.1 → 0.1.3.1
raw patch · 4 files changed
+92/−4 lines, 4 filesdep +template-haskell
Dependencies added: template-haskell
Files
- CHANGELOG.md +6/−0
- src/Yesod/Static/Streamly.hs +13/−2
- src/Yesod/Static/Streamly/Internal.hs +71/−1
- yesod-static-streamly.cabal +2/−1
CHANGELOG.md view
@@ -23,3 +23,9 @@ * Fourth version. * Added staticStreamly function in Yesod.Static.Streamly. * Added supporting functionality for staticStreamly in Yesod.Static.Streamly.Internal.++## 0.1.3.1 -- 2023-07-07++* Fifth version.+* Added staticFilesStreamly function to Yesod.Static.Streamly.+* Added supporting functionality for staticFilesStreamly in Yesod.Static.Streamly.Internal.
src/Yesod/Static/Streamly.hs view
@@ -2,6 +2,8 @@ {-# LANGUAGE OverloadedLists #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE PackageImports #-}+{-# LANGUAGE TemplateHaskell #-}+{-# Language QuasiQuotes #-} -- | -- Module : Yesod.Static.Streamly@@ -15,19 +17,28 @@ -- This library utilizes [Streamly](https://hackage.haskell.org/package/streamly-core)'s superb performance characteristics to replace some of [Yesod](https://hackage.haskell.org/package/yesod)'s functionality with streamly-based functionality. module Yesod.Static.Streamly ( -- * Yesod.Static Replacement functions- staticStreamly+ staticStreamly,+ staticFilesStreamly ) where import Yesod.Static.Streamly.Internal +import Language.Haskell.TH import Network.Wai.Application.Static (webAppSettingsWithLookup) import Yesod.Static -- | A more performant replacement of -- [static](https://hackage.haskell.org/package/yesod-static-1.6.1.0/docs/Yesod-Static.html#v:static)--- found in [Yesod.Static](https://hackage.haskell.org/package/yesod-static-1.6.1.0/docs/Yesod-Static.html#g:2).+-- found in [Yesod.Static](https://hackage.haskell.org/package/yesod-static-1.6.1.0/docs/Yesod-Static.html). staticStreamly :: FilePath -> IO Static staticStreamly dir = do hashLookup <- cachedETagLookupStreamly dir return $ Static $ webAppSettingsWithLookup dir hashLookup++-- | A more performant replacement of+-- [staticFiles](https://hackage.haskell.org/package/yesod-static-1.6.1.0/docs/src/Yesod.Static.html#staticFiles)+-- found in [Yesod.Static](https://hackage.haskell.org/package/yesod-static-1.6.1.0/docs/Yesod-Static.html).+staticFilesStreamly :: FilePath+ -> Q [Dec]+staticFilesStreamly dir = mkStaticFilesStreamly dir
src/Yesod/Static/Streamly/Internal.hs view
@@ -2,6 +2,8 @@ {-# LANGUAGE OverloadedLists #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE PackageImports #-}+{-# LANGUAGE TemplateHaskell #-}+{-# Language QuasiQuotes #-} -- | -- Module : Yesod.Static.Streamly.Internal@@ -31,6 +33,10 @@ -- This library utilizes [Streamly](https://hackage.haskell.org/package/streamly-core)'s superb performance characteristics to replace some of [Yesod](https://hackage.haskell.org/package/yesod)'s functionality with streamly-based functionality. module Yesod.Static.Streamly.Internal ( -- * Yesod.Static Replacement functions+ mkStaticFilesStreamly,+ mkStaticFilesStreamly',+ mkStaticFilesListStreamly,+ mkStaticFilesListStreamly', cachedETagLookupStreamly, mkHashMapStreamly, notHiddenStreamly,@@ -54,8 +60,11 @@ import qualified Data.ByteString.Char8 as S8 import Data.ByteString.Lazy as L (fromStrict) import Data.ByteString.Lazy.Internal as IL (ByteString(..))-import Data.List (foldl',sort)+import Data.Char (isLower,isDigit)+import Data.List (foldl',intercalate,sort) import qualified Data.Map as M+import Language.Haskell.TH+import Language.Haskell.TH.Syntax as TH import qualified Streamly.Data.Stream as S import qualified Streamly.Data.Fold as Fold import Streamly.External.ByteString as StreamlyByteString@@ -65,6 +74,67 @@ import System.Directory (doesDirectoryExist,doesFileExist,getDirectoryContents) import System.IO (openFile, IOMode(ReadMode)) import WaiAppStatic.Storage.Filesystem (ETagLookup)+import Yesod.Static++-- | A replacement of+-- [mkStaticFiles](https://hackage.haskell.org/package/yesod-static-1.6.1.0/docs/src/Yesod.Static.html#mkStaticFiles).+mkStaticFilesStreamly :: FilePath+ -> Q [Dec]+mkStaticFilesStreamly fp = mkStaticFilesStreamly' fp True++-- | A replacement of+-- [mkStaticFiles'](https://hackage.haskell.org/package/yesod-static-1.6.1.0/docs/src/Yesod.Static.html#mkStaticFiles').+mkStaticFilesStreamly' :: FilePath -- ^ static directory+ -> Bool -- ^ append checksum query parameter+ -> Q [Dec]+mkStaticFilesStreamly' fp makeHash = do+ fs <- qRunIO $ getFileListPiecesStreamly fp+ mkStaticFilesListStreamly fp fs makeHash++-- | A replacement of+-- [mkStaticFilesList](https://hackage.haskell.org/package/yesod-static-1.6.1.0/docs/src/Yesod.Static.html#mkStaticFilesList).+mkStaticFilesListStreamly :: FilePath -- ^ static directory+ -> [[String]] -- ^ list of files to create identifiers for+ -> Bool -- ^ append checksum query parameter+ -> Q [Dec]+mkStaticFilesListStreamly fp fs makeHash = mkStaticFilesListStreamly' fp (zip fs fs) makeHash++-- | A replacement of+-- [mkStaticFilesList'](https://hackage.haskell.org/package/yesod-static-1.6.1.0/docs/src/Yesod.Static.html#mkStaticFilesList').+mkStaticFilesListStreamly' :: FilePath -- ^ static directory+ -> [([String], [String])] -- ^ list of files to create identifiers for, where+ -- the first argument of the tuple is the identifier+ -- alias and the second is the actual file name+ -> Bool -- ^ append checksum query parameter+ -> Q [Dec]+mkStaticFilesListStreamly' fp fs makeHash = do+ concat `fmap` mapM mkRoute fs+ where+ replace' c+ | 'A' <= c && c <= 'Z' = c+ | 'a' <= c && c <= 'z' = c+ | '0' <= c && c <= '9' = c+ | otherwise = '_'+ mkRoute (alias,f) = do+ let name' = Data.List.intercalate "_" $ map (map replace') alias+ routeName = mkName $+ case () of+ ()+ | null name' -> error "null-named file"+ | isDigit (head name') -> '_' : name'+ | isLower (head name') -> name'+ | otherwise -> '_' : name'+ f' <- [|map pack $(TH.lift f)|]+ qs <- if makeHash+ then do hash <- qRunIO $ base64md5FileStreamly $ pathFromRawPiecesStreamly fp f+ [|[(pack "etag", pack $(TH.lift hash))]|]+ else return $ ListE []+ return+ [ SigD routeName $ ConT ''StaticRoute+ , FunD routeName+ [ Clause [] (NormalB $ (ConE 'StaticRoute) `AppE` f' `AppE` qs) []+ ]+ ] -- | A replacement of -- [cachedETagLookup](https://hackage.haskell.org/package/yesod-static-1.6.1.0/docs/src/Yesod.Static.html#cachedETagLookup).
yesod-static-streamly.cabal view
@@ -20,7 +20,7 @@ -- PVP summary: +-+------- breaking API changes -- | | +----- non-breaking API additions -- | | | +--- code changes with no API change-version: 0.1.2.1+version: 0.1.3.1 -- A short (one-line) description of the package. synopsis: A streamly-based library providing performance-focused alternatives for functionality found in yesod-static.@@ -90,6 +90,7 @@ mtl >= 2.2.2 && < 2.3, streamly-bytestring >= 0.2.0 && < 0.3, streamly-core >= 0.1.0 && < 0.2,+ template-haskell, text >= 2.0.2 && < 2.1, wai-app-static >= 3.1.7 && < 3.2, yesod-core >= 1.6.24 && < 1.7,