file-embed 0.0.1 → 0.0.2
raw patch · 2 files changed
+16/−4 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- Data/FileEmbed.hs +15/−3
- file-embed.cabal +1/−1
Data/FileEmbed.hs view
@@ -13,13 +13,26 @@ getDirectoryContents) import Control.Monad (filterM) import qualified Data.ByteString as B+import qualified Data.ByteString.Char8 as B8 import Control.Arrow ((&&&), second, first) import Control.Applicative ((<$>)) import Data.Monoid (mappend) +-- | Embed a single file in your source code.+--+-- > import qualified Data.ByteString+-- >+-- > myFile :: Data.ByteString.ByteString+-- > myFile = $(embedFile "dirName/fileName") embedFile :: FilePath -> Q Exp embedFile fp = (runIO $ B.readFile fp) >>= bsToExp +-- | Embed a directory recusrively in your source code.+--+-- > import qualified Data.ByteString+-- >+-- > myDir :: [(FilePath, Data.ByteString.ByteString)]+-- > myDir = $(embedDir "dirName") embedDir :: FilePath -> Q Exp embedDir fp = ListE <$> ((runIO $ fileList fp) >>= mapM pairToExp) @@ -31,12 +44,11 @@ bsToExp :: B.ByteString -> Q Exp bsToExp bs = do helper <- runQ [| stringToBs |]- let octets = B.unpack bs- let chars = map (toEnum . fromEnum) octets+ let chars = B8.unpack bs return $! AppE helper $! LitE $! StringL chars stringToBs :: String -> B.ByteString-stringToBs = B.pack . map (toEnum . fromEnum)+stringToBs = B8.pack notHidden :: FilePath -> Bool notHidden ('.':_) = False
file-embed.cabal view
@@ -1,5 +1,5 @@ name: file-embed-version: 0.0.1+version: 0.0.2 license: BSD3 license-file: LICENSE author: Michael Snoyman <michael@snoyman.com>