git.iko.soy/typeable/file-embed
on 752a2b8 help sign in
ChangeLog.md−8
since splitsnapshots
unifiedsplit
@@ -1,13 +1,5 @@
1# ChangeLog for file-embed
1# ChangeLog for file-embed
2
2
3−## 0.0.15.0
4−
5−* Add `makeRelativeToLocationPredicate`
6−
7−## 0.0.14.0
8−
9−* Add `embedFileIfExists`
10−
11## 0.0.13.0
3## 0.0.13.0
12
4
13* Ensure that directory listings are returned in sorted order for reproducibility [yesodweb/yesod#1684](https://github.com/yesodweb/yesod/issues/1684)
5* Ensure that directory listings are returned in sorted order for reproducibility [yesodweb/yesod#1684](https://github.com/yesodweb/yesod/issues/1684)
Data/FileEmbed.hs+4−17
@@ -39,7 +39,6 @@ module Data.FileEmbed
39 , injectFileWith
39 , injectFileWith
40 -- * Relative path manipulation
40 -- * Relative path manipulation
41 , makeRelativeToProject
41 , makeRelativeToProject
42− , makeRelativeToLocationPredicate
43 -- * Internal
42 -- * Internal
44 , stringToBs
43 , stringToBs
45 , bsToExp
44 , bsToExp
@@ -99,8 +98,6 @@ embedFile fp =
99-- >
98-- >
100-- > maybeMyFile :: Maybe Data.ByteString.ByteString
99-- > maybeMyFile :: Maybe Data.ByteString.ByteString
101-- > maybeMyFile = $(embedFileIfExists "dirName/fileName")
100-- > maybeMyFile = $(embedFileIfExists "dirName/fileName")
102−--
103−-- @since 0.0.14.0
104embedFileIfExists :: FilePath -> Q Exp
101embedFileIfExists :: FilePath -> Q Exp
105embedFileIfExists fp = do
102embedFileIfExists fp = do
106 mbs <- runIO maybeFile
103 mbs <- runIO maybeFile
@@ -409,19 +406,7 @@ available, you can use the non-@With@ variants.
409--
406--
410-- @since 0.0.10
407-- @since 0.0.10
411makeRelativeToProject :: FilePath -> Q FilePath
408makeRelativeToProject :: FilePath -> Q FilePath
412−makeRelativeToProject = makeRelativeToLocationPredicate $ (==) ".cabal" . takeExtension
409+makeRelativeToProject rel = do
413−
414−-- | Take a predicate to infer the project root and a relative file path, the given file path is then attached to the inferred project root
415−--
416−-- This function looks at the source location of the Haskell file calling it,
417−-- finds the first parent directory with a file matching the given predicate, and uses that as the
418−-- root directory for fixing the relative path.
419−--
420−-- @$(makeRelativeToLocationPredicate ((==) ".cabal" . takeExtension) "data/foo.txt" >>= embedFile)@
421−--
422−-- @since 0.0.15.0
423−makeRelativeToLocationPredicate :: (FilePath -> Bool) -> FilePath -> Q FilePath
424−makeRelativeToLocationPredicate isTargetFile rel = do
425 loc <- qLocation
410 loc <- qLocation
426 runIO $ do
411 runIO $ do
427 srcFP <- canonicalizePath $ loc_filename loc
412 srcFP <- canonicalizePath $ loc_filename loc
@@ -436,6 +421,8 @@ makeRelativeToLocationPredicate isTargetFile rel = do
436 then return Nothing
421 then return Nothing
437 else do
422 else do
438 contents <- getDirectoryContents dir
423 contents <- getDirectoryContents dir
439− if any isTargetFile contents
424+ if any isCabalFile contents
440 then return (Just dir)
425 then return (Just dir)
441 else findProjectDir dir
426 else findProjectDir dir
427+
428+ isCabalFile fp = takeExtension fp == ".cabal"
file-embed.cabal+2−2
@@ -1,6 +1,6 @@
1name: file-embed
1name: file-embed
2−version: 0.0.15.0
2+version: 0.0.13.0
3−license: BSD2
3+license: BSD3
4license-file: LICENSE
4license-file: LICENSE
5author: Michael Snoyman <michael@snoyman.com>
5author: Michael Snoyman <michael@snoyman.com>
6maintainer: Michael Snoyman <michael@snoyman.com>
6maintainer: Michael Snoyman <michael@snoyman.com>
test/main.hs+2−2
@@ -2,7 +2,7 @@
2{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE OverloadedStrings #-}
3
3
4import Control.Monad (unless)
4import Control.Monad (unless)
5−import qualified Data.ByteString as B (ByteString, filter)
5+import qualified Data.ByteString as B (ByteString)
6import Data.FileEmbed
6import Data.FileEmbed
7import System.FilePath ((</>))
7import System.FilePath ((</>))
8
8
@@ -22,7 +22,7 @@ main = do
22 filter (/= '\r') str @?= "foo\n"
22 filter (/= '\r') str @?= "foo\n"
23
23
24 let mbs = $(embedFileIfExists "test/sample/foo")
24 let mbs = $(embedFileIfExists "test/sample/foo")
25− fmap (B.filter (/= fromIntegral (fromEnum '\r'))) mbs @?= Just "foo\n"
25+ mbs @?= Just "foo\r\n"
26
26
27 let mbs2 = $(embedFileIfExists "test/sample/foo2") :: Maybe B.ByteString
27 let mbs2 = $(embedFileIfExists "test/sample/foo2") :: Maybe B.ByteString
28 mbs2 @?= Nothing
28 mbs2 @?= Nothing