View Source README

build status coverage report documentation coverage License: CC BY-SA 4.0


"Mail merging" with Ecto structs.

A parser to interpolate MediaWiki-like [[]] markup using data from Ecto schemas.


If available in Hex, the package can be installed by adding mecto to your list of dependencies in mix.exs:

def deps do
    {:mecto, "~> 0.7.0"}


Mecto was originally built to provide dynamic "mail-merging" (think HEEx, but not compiled) from Elixir structs - specifically ones that use Ecto.Schema.

Take this struct:

defmodule MyApp.BlogPost do
  use Ecto.Schema

  schema "blog_posts" do
    field(:title, :string)
    field(:content, :string)

You could then have some text like:

text = "The latest blog post is [[blog_post.title]]"

If you wanted to validate the text has correct markup, you could call:

Mecto.validate(text, MyApp.BlogPost)

> %{blog_post: %{title: :string}}

And Mecto would ensure that the fields used in the text actually exist on MyApp.BlogPost. You can also take it a step further, calling Mecto.interpolate to then use the values in a specific struct:

Mecto.interpolate(text, %MyApp.BlogPost{title: "some title"})

> {:ok, "The latest blog post is some title"}

Mecto also handles relationships and custom Ecto types (i.e. defined with Ecto.Type).

By default there is an implementation for Ecto.Enum, but you can use protocol_ex for your own types - this is required for them as Elixir doesn't allow protocol dispatch on atoms (module names), only data...which Mecto doesn't have when parsing markup.

See the tests for more examples.

Documentation can be found at

Support my work

If you want to support my work, you can donate on Liberapay:

Liberapay donation link