-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from malteneuss/patch-1
Add quickstart section to Readme
- Loading branch information
Showing
1 changed file
with
38 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,40 @@ | ||
## file-embed | ||
# file-embed ![Hackage](https://img.shields.io/hackage/v/file-embed.svg) ![Hackage-Deps](https://img.shields.io/hackage-deps/v/file-embed.svg) ![Tests](https://github.com/snoyberg/file-embed/workflows/Tests/badge.svg) | ||
|
||
![Tests](https://github.com/snoyberg/file-embed/workflows/Tests/badge.svg) | ||
Embed arbitrary files like JSON or plain text into your Haskell code as if they were written inside Haskell. | ||
|
||
Use Template Haskell to read a file or all the files in a directory, and turn | ||
them into (path, bytestring) pairs embedded in your haskell code. | ||
Note: This library uses Template Haskell for the embedding. | ||
|
||
## Quickstart | ||
|
||
Add [the latest version](https://hackage.haskell.org/package/file-embed) of `file-embed` to your | ||
package description `<package>.cabal` or Stack `package.yaml` file. | ||
|
||
Given the folder structure | ||
|
||
```shell | ||
$ tree | ||
. | ||
└── myapp | ||
│ ├── app | ||
│ │ └── Main.hs | ||
│ ├── embedded.json | ||
│ └── myapp.cabal | ||
└── cabal.project | ||
``` | ||
|
||
you can embed a file as follows: | ||
|
||
```haskell | ||
-- file: Main.hs | ||
{-# LANGUAGE TemplateHaskell #-} | ||
|
||
import qualified Data.ByteString as BS | ||
import Data.FileEmbed (embedFileRelative) | ||
|
||
myFile :: BS.ByteString | ||
myFile = $(embedFileRelative "embedded.json") | ||
``` | ||
|
||
The path to `embedFileRelative` is relative to the package root; the folder where the `<package>.cabal` file is. | ||
Take a look at the [Hackage documentation](https://hackage.haskell.org/package/file-embed/docs/Data-FileEmbed.html) | ||
for more examples and variations. |