Skip to content

Commit

Permalink
Update MRML to 3.0.0 (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
mgd020 authored Jan 27, 2024
1 parent f3803f4 commit 9cbf957
Show file tree
Hide file tree
Showing 8 changed files with 235 additions and 126 deletions.
21 changes: 16 additions & 5 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
name: CI

on:
push:
branches:
- main
- master
pull_request:
release:
types: [published]

jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run tests
run: |
set -euo pipefail
python3 -m venv env
source env/bin/activate
pip install -r requirements.txt
maturin develop
python -m unittest
linux:
needs: [ tests ]
strategy:
fail-fast: true
matrix:
Expand Down Expand Up @@ -43,6 +52,7 @@ jobs:
path: dist

windows:
needs: [ tests ]
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -59,6 +69,7 @@ jobs:
path: dist

macos:
needs: [ tests ]
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
Expand Down
126 changes: 35 additions & 91 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mjml-python"
version = "1.2.4"
version = "1.3.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand All @@ -9,5 +9,5 @@ name = "mjml"
crate-type = ["cdylib"]

[dependencies]
mrml = "2.0.0-rc3"
pyo3 = { version = "0.19.0", features = ["abi3-py37", "extension-module"] }
mrml = "3.0.0"
pyo3 = { version = "0.20.2", features = ["abi3-py37", "extension-module"] }
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# mjml-python

Compile MJML at runtime without an external Node service/process. It is a Python wrapper for [MRML](https://github.com/jolimail/mrml-core) (Rust port of [MJML](https://github.com/mjmlio/mjml)).
Compile MJML at runtime without an external Node service/process. It is a Python wrapper for [MRML](https://github.com/jdrouet/mrml) (Rust port of [MJML](https://github.com/mjmlio/mjml)).

## Why

From [MRML](https://github.com/jolimail/mrml-core#why):
From [MRML](https://github.com/jolimail/mrml#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.
Expand Down Expand Up @@ -85,11 +85,12 @@ send_mail(

`mjml-python` supports the following options:

| Name | Type | Default value | Comment |
|----------------------|--------------------------|---------------|----------------------------------------------------------------------------------|
| `disable_comments` | `bool` | `False` | Strip comments out of rendered HTML |
| `social_icon_origin` | `str \| None` | `None` | Custom URL origin for social icons. Icon name is appended (e.g. `facebook.png`). |
| `fonts` | `dict[str, str] \| None` | `None` | Fonts imported in the HTML rendered by MJML. |
| Name | Type | Default value | Comment |
|----------------------|--------------------------------|---------------|----------------------------------------------------------------------------------|
| `disable_comments` | `bool` | `False` | Strip comments out of rendered HTML |
| `social_icon_origin` | `str \| None` | `None` | Custom URL origin for social icons. Icon name is appended (e.g. `facebook.png`). |
| `fonts` | `dict[str, str] \| None` | `None` | Fonts imported in the HTML rendered by MJML. |
| `include_loader` | `Callable[[str], str] \| None` | `None` | Fetch the included template using the path attribute. |

*Notes* :

Expand All @@ -108,7 +109,8 @@ send_mail(

```sh
python -m venv env
. env/bin/activate
source env/bin/activate
pip install -r requirements.txt
maturin develop
python -m unittest
```
20 changes: 18 additions & 2 deletions mjml.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from typing import Optional, Dict
from typing import Optional, Dict, Protocol


class IncludeLoader(Protocol):
def __call__(self, path: str) -> str: ...


def mjml2html(
Expand All @@ -7,5 +11,17 @@ def mjml2html(
disable_comments: bool = False,
social_icon_origin: Optional[str] = None,
fonts: Optional[Dict[str, str]] = None,
include_loader: Optional[IncludeLoader] = None,
) -> str:
"""Convert MJML string to HTML string."""
"""Convert MJML string to HTML string.
Params:
- input: The input MJML string
- disable_comments: Strip comments out of rendered HTML
- social_icon_origin: Custom URL origin for social icons. Icon name is appended
(e.g. `facebook.png`).
- fonts: Fonts imported in the HTML rendered by MJML.
- include_loader: Fetch the included template using the path attribute.
Returns: the rendered HTML string.
"""
Loading

0 comments on commit 9cbf957

Please sign in to comment.