Skip to content

Latest commit

 

History

History
84 lines (53 loc) · 2.98 KB

README.md

File metadata and controls

84 lines (53 loc) · 2.98 KB

MJML (Rust NIFs for Elixir)

Hex version badge License badge Build Status

Native Implemented Function (NIF) bindings for the MJML Rust implementation (mrml).

Installation

In order to use the package you need to install Rust.

The package can be installed by adding mjml to your list of dependencies in mix.exs:

def deps do
  [
    {:mjml, "~> 1.1.1"}
  ]
end

Usage

Transpile MJML templates to HTML with:

mjml = "<mjml>...</mjml>"
{:ok, html} = Mjml.to_html(mjml)

# For an invalid MJML template:
mjml = "something not MJML"
{:error, message} = Mjml.to_html(mjml)

Deployment

MJML requires that the Rust compiler be installed wherever MJML is compiled.

Deploying to Heroku

Most Heroku buildpacks for Elixir do not come with Rust installed; you will need to:

  • Add a Rust buildpack to your app, setting it to run before Elixir; and
  • Add a RustConfig file to your project's root directory, with RUST_SKIP_BUILD=1 set.

For example:

heroku buildpacks:add -i 1 https://github.com/emk/heroku-buildpack-rust.git
echo "RUST_SKIP_BUILD=1" > RustConfig

Deploying with Docker

Make sure Rust is installed prior to running mix deps.compile. You can see examples of what commands to include in your Dockerfile by looking at the official Rust Dockerfiles. For example, here are the commands for alpine3.11 based images.

If your Dockerfile is separated into a build stage and a release stage Rust only needs to be installed on the build stage. However, your release stage will need to have libgcc installed.

Alpine, for example, does not include libgcc by default and you will need to install it.

RUN apk add --no-cache libgcc

You will also need to have the following environment variable set during the build stage or else mix compile will fail.

RUSTFLAGS='--codegen target-feature=-crt-static'

Contributing

We encourage you to contribute to mjml_nif. Please check our CONTRIBUTING.md guides for more information.

This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to our CODE_OF_CONDUCT.md.

License

Copyright (c) 2020-2021, Paul Götze

This software is licensed under the MIT License.