git.iko.soy/typeable/file-embed
on master help sign in
Add `embedDirListing`

Use case: need the file listing to be embedded, but without their contents (which can be huge).

commita21f18d8b34972cf6ad76e510d1aa507fd37125f authorSridhar Ratnakumar <srid@srid.ca> dateSat 21 Jul 2018, 13:20 (8 years ago) parent47ad3a5
1 file changed+11
Data/FileEmbed.hs+11
Data/FileEmbed.hs+11
@@ -21,6 +21,7 @@ module Data.FileEmbed
2121 embedFile
2222 , embedOneFileOf
2323 , embedDir
24+ , embedDirListing
2425 , getDir
2526 -- * Embed as a IsString
2627 , embedStringFile
@@ -118,6 +119,16 @@ embedDir fp = do
118119 e <- ListE <$> ((runIO $ fileList fp) >>= mapM (pairToExp fp))
119120 return $ SigE e typ
120121
122+-- | Embed a directory listing recursively in your source code.
123+--
124+-- > myFiles :: [FilePath]
125+-- > myFiles = $(embedDirListing "dirName")
126+embedDirListing :: FilePath -> Q Exp
127+embedDirListing fp = do
128+ typ <- [t| [FilePath] |]
129+ e <- ListE <$> ((runIO $ fmap fst <$> fileList fp) >>= mapM strToExp)
130+ return $ SigE e typ
131+
121132-- | Get a directory tree in the IO monad.
122133--
123134-- This is the workhorse of 'embedDir'