#mjml #mrml #email #json #macro #features

macro mrml-json-macros

Macros for the JSON feature of the MRML crate

4 releases

0.1.3 Mar 21, 2024
0.1.2 Dec 4, 2023
0.1.1 Dec 1, 2023
0.1.0 Feb 12, 2023

#5 in #mrml

Download history 864/week @ 2024-01-28 812/week @ 2024-02-04 775/week @ 2024-02-11 733/week @ 2024-02-18 2453/week @ 2024-02-25 1858/week @ 2024-03-03 2275/week @ 2024-03-10 2799/week @ 2024-03-17 2154/week @ 2024-03-24 2133/week @ 2024-03-31 2438/week @ 2024-04-07 2451/week @ 2024-04-14 1834/week @ 2024-04-21 2174/week @ 2024-04-28 1597/week @ 2024-05-05 2703/week @ 2024-05-12

8,349 downloads per month
Used in mrml

MIT license

31KB
471 lines

MRML

Crates.io Crates.io FOSSA Status

.github/workflows/main.yml codecov

Average time to resolve an issue Percentage of issues still open Maintainability

Introduction

This project is a reimplementation of the nice MJML markup language in Rust.

How to use it in my code

Update your cargo.toml:

[dependencies]
mrml = "2"
serde = { version = "1.0", features = ["derive"] }

Create your main.rs:

use mrml;

fn main() {
    let root = mrml::parse("<mjml><mj-body></mj-body></mjml>").expect("parse template");
    let opts = mrml::prelude::render::Options::default();
    match root.render(&opts) {
        Ok(content) => println!("{}", content),
        Err(_) => println!("couldn't render mjml template"),
    };
}

Available options are:

Name Comment Default value
disable_comments Strip comments out of rendered HTML false
social_icon_origin Custom URL for fetching social icons None
fonts Default fonts imported in the HTML rendered by MJML See default options

Why?

  • A Node.js server rendering an MJML template takes around 20 MB of RAM at startup and 130 MB under stress test. In Rust, less than 1.7 MB at startup and a bit less that 3 MB under stress test. The Rust version can also handle twice as many requests per second. You can perform the benchmarks by running bash script/run-bench.sh.
  • The JavaScript implementation cannot be run in the browser; the Rust one (and WebAssembly one) can be.

You want to contribute?

Feel free to read our contributing section and the code of conduct.

Performance

With the same Linux amd64 machine, to render the amario template

  • Node: 606.59ms
  • Rust: 3.48ms

Missing implementations

  • mj-style[inline]: not yet implemented. It requires parsing the generated html to apply the inline styles afterward (that's how it's done in mjml) which would kill the performances. Applying it at render time would improve the performance but it would still require to parse the CSS.
  • mj-include: not yet implemented. It requires to handle loading remote templates when using mrml in a wasm (browser or server side) format, which implies being able to load from a different location (file://, https://, relative, etc).

Who is using MRML?

If you are using MRML and want to be added to this list, don't hesitate to create an issue or open a pull request.

What is using MRML?

mjml_nif - Elixir library

mrml-ruby - Ruby library

mjml-python - Python library

If you are using MRML and want to be added to this list, don't hesitate to create an issue or open a pull request.

You want to sponsor us?

Buy Me A Coffee

Thanks to zachzurn.

License

FOSSA Status

Dependencies

~0.8–1.3MB
~28K SLoC