Hello everyone, I’m exited to announce the very first version of elm-embed. This is intended as a rough sketch for an idea, a basis for discussion.
Would love if you wanted to try it out!
What is elm-embed?
elm-embed
is a tool for parsing external data like environment variables and file content and then embedding it in Elm code.
You do this with embedders, which is any Elm declaration with the type Embed.Task
living inside the special folder elm-embed-scripts
. I can for example embed an environment variable pointing to the server my app should target, so that I can use my own local server for development. I would do that with an embedder like this:
-- elm-embed-scripts/Server.elm
serverUrl : Embed.Task String
serverUrl =
Embed.Environment.string "target_server"
If I then run elm-embed run
with the env variable target_server
set to localhost:8080
I would get the resulting code in src/Generated/Server.elm
which can then be imported in the rest of the codebase.
-- src/Generated/Server.elm
serverUrl : String
serverUrl =
"localhost:8080"
External data can also be validated and transformed with Embed.andThen
. So it is possible to do more advanced stuff, like parsing a markdown document with elm-markdown and reporting any errors at build-time.
Installation
Pre-built binary availible for Linux Here. Just unzip, give execute permissions and place on your path. Detailed instructions here.
Mac and Windows users will need to build from source for now, the process is the same as for the Elm compiler. If you’re on Mac or Windows and want to give elm-embed
a try, send me a message and that would really motivate me to fix binaries.
Next steps
I would really love to hear what use cases you can see yourself having for elm-embed
, that way I can make more informed design decisions. So please let me know in a comment here, somewhere in the Elm Slack, or this Github issue.
And at this point in the project, any kind of questions, thoughts or discussion relating to elm-embed
is very welcome.
All the best to y’all