Elixir NIF bindings for the MJML Rust implementation (mrml)
See the codeNative Implemented Function (NIF) bindings for the MJML Rust implementation (mrml).
The package can be installed by adding mjml to your list of dependencies in mix.exs:
def deps do
[
{:mjml, "~> 6.0"}
]
end
By default you don't need Rust installed because the lib will try to download
a precompiled NIF file. In case you want to force compilation set the
MJML_BUILD environment variable to true or 1. Alternatively you can also set the
application env in order to force the build:
config :rustler_precompiled, :force_build, mjml: true
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)
Available rendering options are:
keep_comments – when false, removes comments from the final HTML. Defaults to true.social_icon_path – when given, uses this base path to generate social icon URLs.fonts – a Map of font names and their URLs to a hosted CSS file.
When given, includes these fonts in the rendered HTML
(Note that only actually used fonts will show up!).
Defaults to nil, which will make the default font families available to
be used (Open Sans, Droid Sans, Lato, Roboto, and Ubuntu).Available parsing options are:
include_loader - the loader to use for mj-include tags.
By default, there is no include loader configured, which means that transpiling MJML templates with mj-include tags will fail with an error.
Currently, the only supported include loader is
Mjml.ParserOptions.LocalIncludeLoader. By default MJML includes are looked up from the currently working directory as the root directory. You can also define an optional custom path for the LocalIncludeLoader struct.alias Mjml.ParserOptions.LocalIncludeLoader
mjml = "<mjml>...</mjml>"
opts = [
keep_comments: false,
social_icon_path: "https://example.com/icons/",
fonts: %{
"Noto Color Emoji": "https://fonts.googleapis.com/css?family=Noto+Color+Emoji:400"
},
include_loader: %LocalIncludeLoader{path: "/path/to/mjml/includes"}
]
{:ok, html} = Mjml.to_html(mjml, opts)
We encourage you to contribute to mjml_nif. Please check our Contributing 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.
Copyright (c) 2020 Paul Götze
This work is free. You can redistribute it and/or modify it under the terms of the MIT License. See the LICENSE.md file for more details.
Elixir
84.1%
Rust
15.9%
Elixir NIF bindings for the MJML Rust implementation (mrml)
See the codeNative Implemented Function (NIF) bindings for the MJML Rust implementation (mrml).
The package can be installed by adding mjml to your list of dependencies in mix.exs:
def deps do
[
{:mjml, "~> 6.0"}
]
end
By default you don't need Rust installed because the lib will try to download
a precompiled NIF file. In case you want to force compilation set the
MJML_BUILD environment variable to true or 1. Alternatively you can also set the
application env in order to force the build:
config :rustler_precompiled, :force_build, mjml: true
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)
Available rendering options are:
keep_comments – when false, removes comments from the final HTML. Defaults to true.social_icon_path – when given, uses this base path to generate social icon URLs.fonts – a Map of font names and their URLs to a hosted CSS file.
When given, includes these fonts in the rendered HTML
(Note that only actually used fonts will show up!).
Defaults to nil, which will make the default font families available to
be used (Open Sans, Droid Sans, Lato, Roboto, and Ubuntu).Available parsing options are:
include_loader - the loader to use for mj-include tags.
By default, there is no include loader configured, which means that transpiling MJML templates with mj-include tags will fail with an error.
Currently, the only supported include loader is
Mjml.ParserOptions.LocalIncludeLoader. By default MJML includes are looked up from the currently working directory as the root directory. You can also define an optional custom path for the LocalIncludeLoader struct.alias Mjml.ParserOptions.LocalIncludeLoader
mjml = "<mjml>...</mjml>"
opts = [
keep_comments: false,
social_icon_path: "https://example.com/icons/",
fonts: %{
"Noto Color Emoji": "https://fonts.googleapis.com/css?family=Noto+Color+Emoji:400"
},
include_loader: %LocalIncludeLoader{path: "/path/to/mjml/includes"}
]
{:ok, html} = Mjml.to_html(mjml, opts)
We encourage you to contribute to mjml_nif. Please check our Contributing 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.
Copyright (c) 2020 Paul Götze
This work is free. You can redistribute it and/or modify it under the terms of the MIT License. See the LICENSE.md file for more details.
Elixir
84.1%
Rust
15.9%