mirror of
https://github.com/typeable/file-embed.git
synced 2024-09-11 07:45:30 +03:00
Merge pull request #41 from aveltras/build-system-agnostic-project-path
Add build system agnostic version of makeRelativeToProject
This commit is contained in:
commit
548430d2a7
@ -1,5 +1,9 @@
|
|||||||
# ChangeLog for file-embed
|
# ChangeLog for file-embed
|
||||||
|
|
||||||
|
## 0.0.15.0
|
||||||
|
|
||||||
|
* Add `makeRelativeToLocationPredicate`
|
||||||
|
|
||||||
## 0.0.14.0
|
## 0.0.14.0
|
||||||
|
|
||||||
* Add `embedFileIfExists`
|
* Add `embedFileIfExists`
|
||||||
|
@ -39,6 +39,7 @@ module Data.FileEmbed
|
|||||||
, injectFileWith
|
, injectFileWith
|
||||||
-- * Relative path manipulation
|
-- * Relative path manipulation
|
||||||
, makeRelativeToProject
|
, makeRelativeToProject
|
||||||
|
, makeRelativeToLocationPredicate
|
||||||
-- * Internal
|
-- * Internal
|
||||||
, stringToBs
|
, stringToBs
|
||||||
, bsToExp
|
, bsToExp
|
||||||
@ -408,7 +409,19 @@ available, you can use the non-@With@ variants.
|
|||||||
--
|
--
|
||||||
-- @since 0.0.10
|
-- @since 0.0.10
|
||||||
makeRelativeToProject :: FilePath -> Q FilePath
|
makeRelativeToProject :: FilePath -> Q FilePath
|
||||||
makeRelativeToProject rel = do
|
makeRelativeToProject = makeRelativeToLocationPredicate $ (==) ".cabal" . takeExtension
|
||||||
|
|
||||||
|
-- | 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
|
||||||
|
--
|
||||||
|
-- This function looks at the source location of the Haskell file calling it,
|
||||||
|
-- finds the first parent directory with a file matching the given predicate, and uses that as the
|
||||||
|
-- root directory for fixing the relative path.
|
||||||
|
--
|
||||||
|
-- @$(makeRelativeToLocationPredicate ((==) ".cabal" . takeExtension) "data/foo.txt" >>= embedFile)@
|
||||||
|
--
|
||||||
|
-- @since 0.0.15.0
|
||||||
|
makeRelativeToLocationPredicate :: (FilePath -> Bool) -> FilePath -> Q FilePath
|
||||||
|
makeRelativeToLocationPredicate isTargetFile rel = do
|
||||||
loc <- qLocation
|
loc <- qLocation
|
||||||
runIO $ do
|
runIO $ do
|
||||||
srcFP <- canonicalizePath $ loc_filename loc
|
srcFP <- canonicalizePath $ loc_filename loc
|
||||||
@ -423,8 +436,6 @@ makeRelativeToProject rel = do
|
|||||||
then return Nothing
|
then return Nothing
|
||||||
else do
|
else do
|
||||||
contents <- getDirectoryContents dir
|
contents <- getDirectoryContents dir
|
||||||
if any isCabalFile contents
|
if any isTargetFile contents
|
||||||
then return (Just dir)
|
then return (Just dir)
|
||||||
else findProjectDir dir
|
else findProjectDir dir
|
||||||
|
|
||||||
isCabalFile fp = takeExtension fp == ".cabal"
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
name: file-embed
|
name: file-embed
|
||||||
version: 0.0.14.0
|
version: 0.0.15.0
|
||||||
license: BSD2
|
license: BSD2
|
||||||
license-file: LICENSE
|
license-file: LICENSE
|
||||||
author: Michael Snoyman <michael@snoyman.com>
|
author: Michael Snoyman <michael@snoyman.com>
|
||||||
|
Loading…
Reference in New Issue
Block a user