Rivet Engram

Rivet Engram provides multi-section templates with EEx and YAML-based section types for the Rivet framework.

It is a standalone implementation from the original Rivet.Template format.

An Engram is a pattern or template that is realized through processing. Each document contains metadata followed by one or more named sections, which may contain YAML, EEx, or EEx-generated YAML.

Engrams are currently used by Dragon (an EEx CMS) and Rivet.Mailer (templated batching/sending of emails).

Warning

Engrams are not safe for untrusted or end-user input.

They generate atoms and may execute arbitrary Elixir code. Only process Engrams from sources you trust.

Engram Structure:

An Engram is divided into sections using:

=== section-name

The general rules are:

For example:

sections:
constants: yml
inputs: eex-yml
rack: eex-yml

This describes three named sections in addition to the initial metadata section.

Supported section types are:

Example

=== rivet-engram-v1
sections:
red: yml
blue: eex-yml
green: eex-yml-docs
embed_assign: bork bork
=== red
hello: nurse
=== blue
narf: <%= @sections.red.hello %>
=== green
---
- narf
---
dilbert: <%= @embed_assign %>

A few things are happening here:

Usage

Rivet.Engram provides the public entry points.

The simplest usage is:

{:ok, %Rivet.Engram{} = engram} = Rivet.Engram.process_string("...")

The resulting struct contains:

Most use cases can simply use:

Rivet.Engram.process_file/2
Rivet.Engram.process_string/2

The lower-level parsing functions perform the initial parse without evaluating deferred EEx sections:

Rivet.Engram.parse_file/2
Rivet.Engram.parse_string/2

Nuanced behavior

Section structure is not currently enforced beyond the basic metadata requirements, so malformed or inconsistent Engrams may produce unexpected results. Notably:

Todo