packages feed

file-embed 0.0.8.2 → 0.0.9

raw patch · 4 files changed

+58/−1 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Data.FileEmbed: embedOneStringFileOf :: [FilePath] -> Q Exp
+ Data.FileEmbed: embedStringFile :: FilePath -> Q Exp
+ Data.FileEmbed: strToExp :: String -> Q Exp

Files

ChangeLog.md view
@@ -1,3 +1,7 @@+## 0.0.9++* embedStringFile [#14](https://github.com/snoyberg/file-embed/pull/14)+ ## 0.0.8.2  * Improve inject documentation [#11](https://github.com/snoyberg/file-embed/issues/11)
Data/FileEmbed.hs view
@@ -22,6 +22,9 @@     , embedOneFileOf     , embedDir     , getDir+      -- * Embed as a IsString+    , embedStringFile+    , embedOneStringFileOf       -- * Inject into an executable       -- $inject #if MIN_VERSION_template_haskell(2,5,0)@@ -35,6 +38,7 @@       -- * Internal     , stringToBs     , bsToExp+    , strToExp     ) where  import Language.Haskell.TH.Syntax@@ -61,6 +65,8 @@ import Data.ByteString.Unsafe (unsafePackAddressLen) import System.IO.Unsafe (unsafePerformIO) import System.FilePath ((</>))+import Data.String (fromString)+import Prelude as P  -- | Embed a single file in your source code. --@@ -143,6 +149,51 @@  stringToBs :: String -> B.ByteString stringToBs = B8.pack++-- | Embed a single file in your source code.+--+-- > import Data.String+-- >+-- > myFile :: IsString a => a+-- > myFile = $(embedStringFile "dirName/fileName")+--+-- Since 0.0.9+embedStringFile :: FilePath -> Q Exp+embedStringFile fp =+#if MIN_VERSION_template_haskell(2,7,0)+    qAddDependentFile fp >>+#endif+  (runIO $ P.readFile fp) >>= strToExp++-- | Embed a single existing string file in your source code+-- out of list a list of paths supplied.+--+-- Since 0.0.9+embedOneStringFileOf :: [FilePath] -> Q Exp+embedOneStringFileOf ps =+  (runIO $ readExistingFile ps) >>= \ ( path, content ) -> do+#if MIN_VERSION_template_haskell(2,7,0)+    qAddDependentFile path+#endif+    strToExp content+  where+    readExistingFile :: [FilePath] -> IO ( FilePath, String )+    readExistingFile xs = do+      ys <- filterM doesFileExist xs+      case ys of+        (p:_) -> P.readFile p >>= \ c -> return ( p, c )+        _ -> throw $ ErrorCall "Cannot find file to embed as resource"++strToExp :: String -> Q Exp+#if MIN_VERSION_template_haskell(2, 5, 0)+strToExp s =+    return $ VarE 'fromString+      `AppE` LitE (StringL s)+#else+strToExp s = do+    helper <- [| fromString |]+    return $! AppE helper $! LitE $! StringL s+#endif  notHidden :: FilePath -> Bool notHidden ('.':_) = False
file-embed.cabal view
@@ -1,5 +1,5 @@ name:            file-embed-version:         0.0.8.2+version:         0.0.9 license:         BSD3 license-file:    LICENSE author:          Michael Snoyman <michael@snoyman.com>
test/main.hs view
@@ -12,3 +12,5 @@         [ ("foo", "foo\r\n")         , ("bar" </> "baz", "baz\r\n")         ]+    let str = $(embedStringFile "test/sample/foo") :: String+    str @?= "foo\r\n"