Add embedDirListing

Use case: need the file listing to be embedded, but without their
contents (which can be huge).
This commit is contained in:
Sridhar Ratnakumar 2018-07-21 13:20:09 -04:00
parent 47ad3a5e55
commit a21f18d8b3

View File

@ -21,6 +21,7 @@ module Data.FileEmbed
embedFile embedFile
, embedOneFileOf , embedOneFileOf
, embedDir , embedDir
, embedDirListing
, getDir , getDir
-- * Embed as a IsString -- * Embed as a IsString
, embedStringFile , embedStringFile
@ -118,6 +119,16 @@ embedDir fp = do
e <- ListE <$> ((runIO $ fileList fp) >>= mapM (pairToExp fp)) e <- ListE <$> ((runIO $ fileList fp) >>= mapM (pairToExp fp))
return $ SigE e typ return $ SigE e typ
-- | Embed a directory listing recursively in your source code.
--
-- > myFiles :: [FilePath]
-- > myFiles = $(embedDirListing "dirName")
embedDirListing :: FilePath -> Q Exp
embedDirListing fp = do
typ <- [t| [FilePath] |]
e <- ListE <$> ((runIO $ fmap fst <$> fileList fp) >>= mapM strToExp)
return $ SigE e typ
-- | Get a directory tree in the IO monad. -- | Get a directory tree in the IO monad.
-- --
-- This is the workhorse of 'embedDir' -- This is the workhorse of 'embedDir'