Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add embedFileRelative function. #48

Merged
merged 4 commits into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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