mirror of
https://github.com/typeable/file-embed.git
synced 2024-09-11 07:45:30 +03:00
Merge pull request #1 from travitch/master
Use qAddDependentFile when available
This commit is contained in:
commit
a60b60d04f
@ -23,6 +23,9 @@ import Language.Haskell.TH.Syntax
|
||||
#endif
|
||||
, Q
|
||||
, runIO
|
||||
#if MIN_VERSION_template_haskell(2,7,0)
|
||||
, Quasi(qAddDependentFile)
|
||||
#endif
|
||||
)
|
||||
import System.Directory (doesDirectoryExist, doesFileExist,
|
||||
getDirectoryContents)
|
||||
@ -42,7 +45,11 @@ import System.IO.Unsafe (unsafePerformIO)
|
||||
-- > myFile :: Data.ByteString.ByteString
|
||||
-- > myFile = $(embedFile "dirName/fileName")
|
||||
embedFile :: FilePath -> Q Exp
|
||||
embedFile fp = (runIO $ B.readFile fp) >>= bsToExp
|
||||
embedFile fp =
|
||||
#if MIN_VERSION_template_haskell(2,7,0)
|
||||
qAddDependentFile fp >>
|
||||
#endif
|
||||
(runIO $ B.readFile fp) >>= bsToExp
|
||||
|
||||
-- | Embed a directory recusrively in your source code.
|
||||
--
|
||||
@ -61,6 +68,9 @@ getDir = fileList
|
||||
|
||||
pairToExp :: (FilePath, B.ByteString) -> Q Exp
|
||||
pairToExp (path, bs) = do
|
||||
#if MIN_VERSION_template_haskell(2,7,0)
|
||||
qAddDependentFile path
|
||||
#endif
|
||||
exp' <- bsToExp bs
|
||||
return $! TupE [LitE $ StringL path, exp']
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user