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
Changes from 1 commit
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
8 changes: 7 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,11 @@ embedFile fp =
#endif
(runIO $ B.readFile fp) >>= bsToExp

-- | Embed a file file in your source code.
-- Unlike 'embedFile', path is given relative to project root.
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
Loading