build statuscoverage reportdocumentation coverage

Mecto

"Mail merging" with Ecto structs.

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

Installation

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.6.0"}
]
end

Usage

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)
end
end

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)

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"})

See the tests for more examples.

Documentation can be found at https://hexdocs.pm/mecto.