# Announcing elm-embed 0.1.0

**URL:** <https://discourse.elm-lang.org/t/announcing-elm-embed-0-1-0/7105>\
**Category:** Show and Tell\
**Created:** [March 16, 2021, 10:42am UTC](https://discourse.elm-lang.org/t/announcing-elm-embed-0-1-0/7105 "2021-03-16T10:42:44Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![emmabastas](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/emmabastas/32/3189_2.png) [@emmabastas](https://discourse.elm-lang.org/u/emmabastas)\
**Post date:** [March 16, 2021, 10:42am UTC](https://discourse.elm-lang.org/t/announcing-elm-embed-0-1-0/7105/1 "2021-03-16T10:42:44Z")

</div>

Hello everyone, I’m exited to announce the very first version of [elm-embed](https://github.com/emmabastas/elm-embed#readme). 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
-- 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.

```elm
-- 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](https://package.elm-lang.org/packages/dillonkearns/elm-markdown/latest) and reporting any errors at build-time.

# Installation

Pre-built binary availible for Linux [Here](https://github.com/emmabastas/elm-embed/releases/download/0.1.0/elm-embed-0.1.0-linux-x64.gz). Just unzip, give execute permissions and place on your path. Detailed instructions [here](https://github.com/emmabastas/elm-embed#linux).

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](https://github.com/emmabastas/elm-embed/issues/7).

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 💖**

---

<div class="post-metadata">

**Author:** ![terezka](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/terezka/32/579_2.png) [@terezka](https://discourse.elm-lang.org/u/terezka)\
**Post date:** [March 16, 2021, 10:44am UTC](https://discourse.elm-lang.org/t/announcing-elm-embed-0-1-0/7105/2 "2021-03-16T10:44:50Z")

</div>

This is so cool! Can’t wait to try it out! 😊

---

<div class="post-metadata">

**Author:** ![georgesboris](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/georgesboris/32/3598_2.png) [@georgesboris](https://discourse.elm-lang.org/u/georgesboris)\
**Post date:** [March 16, 2021, 12:49pm UTC](https://discourse.elm-lang.org/t/announcing-elm-embed-0-1-0/7105/3 "2021-03-16T12:49:23Z")

</div>

This looks really promising! And your timing 🎯 – I promise I was going to try and build something like this today! 🤯

FYI – I’m running a Mac and my use case would be to read `.md` files (with frontmatter) and parse those into some Elm code I would use to create a client-side search engine. (contents of the website are small enough that I could do it without any server setup).

Wishlist: I would love to be able to specify the name of the target folder. As I’m also using elm-pages and elm-tailwind-modules and both their generated files live under `/gen`.

Thanks so much for working on this! 🙂

---

<div class="post-metadata">

**Author:** ![emmabastas](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/emmabastas/32/3189_2.png) [@emmabastas](https://discourse.elm-lang.org/u/emmabastas)\
**Post date:** [March 16, 2021, 2:14pm UTC](https://discourse.elm-lang.org/t/announcing-elm-embed-0-1-0/7105/4 "2021-03-16T14:14:29Z")

</div>

Thank you so much for the use case and wishlist. The most obvious way to support `/gen` would be to implement an output flag for the generated code. But I’d like to think about it a bit first, and see how other tools do it, some output in `gen` while others output in `src`.

And I’ll let you know when OSX binaries are available 😊.

---

<div class="post-metadata">

**Author:** ![neurodynamic](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/neurodynamic/32/984_2.png) [@neurodynamic](https://discourse.elm-lang.org/u/neurodynamic)\
**Post date:** [March 16, 2021, 2:36pm UTC](https://discourse.elm-lang.org/t/announcing-elm-embed-0-1-0/7105/5 "2021-03-16T14:36:39Z")

</div>

This looks really cool; and very potentially useful for a project I’m working on right now. Another interested Mac user here!

---

<div class="post-metadata">

**Author:** ![choonkeat](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/choonkeat/32/1555_2.png) [@choonkeat](https://discourse.elm-lang.org/u/choonkeat)\
**Post date:** [March 17, 2021, 12:17pm UTC](https://discourse.elm-lang.org/t/announcing-elm-embed-0-1-0/7105/6 "2021-03-17T12:17:46Z")

</div>

_Background:_ I’m currently using scripts like [env2file.js](https://gist.github.com/choonkeat/a6580019b9089c163ab7779653007fdf) which produces `src/Env.elm` like

```elm
module Env exposing (..)

{-| environment variable AWS_REGION
-}
awsRegion =
     "us-east-1" 

```

which I reference in elsewhere in my app as `Env.awsRegion`. with [function-level dead code elimination](https://elm-lang.org/news/small-assets-without-the-headache) I don’t have to worry about the unreferenced env values. Same strategy for [file content and file paths as ` : String` functions](https://gist.github.com/choonkeat/b9959168e15d813d9f8a84d0e2c9632a)

Wondering what I’m missing by not approaching the problem like `elm-embed`?

---

<div class="post-metadata">

**Author:** ![wolfadex](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/wolfadex/32/2461_2.png) [@wolfadex](https://discourse.elm-lang.org/u/wolfadex)\
**Post date:** [March 17, 2021, 1:11pm UTC](https://discourse.elm-lang.org/t/announcing-elm-embed-0-1-0/7105/7 "2021-03-17T13:11:14Z")

</div>

I’ve used [GitHub - jaredramirez/elm-constants: Generate constant values in Elm from your environment](https://github.com/jaredramirez/elm-constants) before and liked it, but once elm-embed has a Mac installer I’d probably start recommending it at work instead. The main advantage I see is being able to generate not only non-String values, but also being able to wrqp env tokens and ids in phantom types.

---

<div class="post-metadata">

**Author:** ![emmabastas](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/emmabastas/32/3189_2.png) [@emmabastas](https://discourse.elm-lang.org/u/emmabastas)\
**Post date:** [March 17, 2021, 4:27pm UTC](https://discourse.elm-lang.org/t/announcing-elm-embed-0-1-0/7105/8 "2021-03-17T16:27:21Z")

</div>

~~With regards to environment variables. With `elm-embed` you …~~

@wolfadex Summed it up nicely. But if you are satisfied with your current solution, then I don’t see a need to switch to `elm-embed`.

---

<div class="post-metadata">

**Author:** ![choonkeat](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/choonkeat/32/1555_2.png) [@choonkeat](https://discourse.elm-lang.org/u/choonkeat)\
**Post date:** [March 20, 2021, 6:08am UTC](https://discourse.elm-lang.org/t/announcing-elm-embed-0-1-0/7105/9 "2021-03-20T06:08:31Z")

</div>

> [@wolfadex](#):
>
> The main advantage I see is being able to generate not only non-String values, but also being able to wrqp env tokens and ids in phantom types.

i think _“i can transform those `String` to phantom types”_ but keep slipping my mind that it would be even better if those values don’t exist as `String` in my codebase _at all_ 👍 thanks for the reminder

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/elm_lang/original/1X/50a05e53677a2c3b47776d7abd0f113eb50193a1.png) [@system](https://discourse.elm-lang.org/u/system)\
**Post date:** [March 30, 2021, 6:09am UTC](https://discourse.elm-lang.org/t/announcing-elm-embed-0-1-0/7105/10 "2021-03-30T06:09:13Z")

</div>

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.
