GitXplorerGitXplorer
j

ppx_embed_file

public
2 stars
0 forks
0 issues

Commits

List of commits on branch master.
Unverified
8eacf5f15cde5d2026fe8ff4e1fafb5d8ace3977

v0.18~preview.129.42+498

ppublic-release committed 4 months ago
Unverified
96c9eb62eccb3082a5a7c9d1eb5433d9e8fbe4d8

v0.17~preview.129.36+325

ppublic-release committed 5 months ago
Unverified
cf079648ad2d4a6a8eba30af8f16ed0524fc3b5c

v0.17~preview.129.17+77

ppublic-release committed 9 months ago
Unverified
f7cd6624759de522beb8ab7f3d4eb8524a6f76a3

v0.17~preview.129.17+77

ppublic-release committed 9 months ago
Unverified
e0cd4fe67ad8aa29acec2ad387939746c937cbab

v0.17~preview.129.07+242

ppublic-release committed a year ago
Unverified
214227852e939d0c4eb4233a5eeace0ae9aa44f9

v0.17~preview.128.40+46

ppublic-release committed a year ago

README

The README file for this repository.

"Ppx_embed_file"

ppx_embed_file is a simple PPX that allows embedding files directly into executables as strings or bytes so that we can embed files into OCaml programs.

How to use

First, in your dune file, specify preprocess to include ppx_embed_file and preprocessor_deps to include any files to be included:

$ cat test/dune
(library (
  (name ppx_embed_test)
  (libraries (core))
  (preprocessor_deps (hello_world.txt))
  (preprocess (pps (ppx_jane ppx_embed_file)))))

Then, write the appropriate extension nodes in your .ml files:

open! Core

let hello_world_string = [%embed_file_as_string "hello_world.txt"]

let hello_world_string_with_filename =
  [%embed_file_as_string_with_filename "hello_world.txt"]
;;

let%expect_test "string test" =
  Core.print_string hello_world_string;
  [%expect {xxx| Hello world! |xxx}]
;;

let%expect_test "string with filename test" =
  [%sexp_of: string * string] hello_world_string_with_filename |> Core.print_s;
  [%expect {xxx| (hello_world.txt "Hello world!\n") |xxx}]
;;