Skip to content

Commit

Permalink
Merge pull request #48 from typeable/embed-file-relative
Browse files Browse the repository at this point in the history
Add embedFileRelative function.
  • Loading branch information
snoyberg authored Jan 28, 2024
2 parents 548430d + 001cded commit ec0b53c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# ChangeLog for file-embed

## 0.0.16.0

* Add `embedFileRelative`

## 0.0.15.0

* Add `makeRelativeToLocationPredicate`
Expand Down
9 changes: 8 additions & 1 deletion Data/FileEmbed.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
module Data.FileEmbed
( -- * Embed at compile time
embedFile
, embedFileRelative
, embedFileIfExists
, embedOneFileOf
, embedDir
Expand Down Expand Up @@ -63,7 +64,7 @@ import qualified Data.ByteString.Internal as B
import System.Directory (doesDirectoryExist, doesFileExist,
getDirectoryContents, canonicalizePath)
import Control.Exception (throw, tryJust, ErrorCall(..))
import Control.Monad (filterM, guard)
import Control.Monad ((<=<), filterM, guard)
import qualified Data.ByteString as B
import qualified Data.ByteString.Char8 as B8
import Control.Arrow ((&&&), second)
Expand All @@ -90,6 +91,12 @@ embedFile fp =
#endif
(runIO $ B.readFile fp) >>= bsToExp

-- | Embed a single file in your source code.
-- Unlike 'embedFile', path is given relative to project root.
-- @since 0.0.16.0
embedFileRelative :: FilePath -> Q Exp
embedFileRelative = embedFile <=< makeRelativeToProject

-- | Maybe embed a single file in your source code depending on whether or not file exists.
--
-- Warning: When a build is compiled with the file missing, a recompile when the file exists might not trigger an embed of the file.
Expand Down
2 changes: 1 addition & 1 deletion file-embed.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: file-embed
version: 0.0.15.0
version: 0.0.16.0
license: BSD2
license-file: LICENSE
author: Michael Snoyman <[email protected]>
Expand Down

0 comments on commit ec0b53c

Please sign in to comment.