-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integrate mjml-python? #184
Comments
For anyone who wants to try this now, I've copied the template tag from this library and copied it into my own project. There's not much to it when you don't have to talk to a separate process: In from django import template
from mjml import mjml2html
register = template.Library()
class MJMLRenderNode(template.Node):
def __init__(self, nodelist):
self.nodelist = nodelist
def render(self, context) -> str:
mjml_source = self.nodelist.render(context)
return mjml_render(mjml_source)
@register.tag
def mjml(parser, token) -> MJMLRenderNode:
"""
Compile MJML template after render django template.
Usage:
{% mjml %}
.. MJML template code ..
{% endmjml %}
"""
nodelist = parser.parse(("endmjml",))
parser.delete_first_token()
tokens = token.split_contents()
if len(tokens) != 1:
raise template.TemplateSyntaxError("'%r' tag doesn't receive any arguments." % tokens[0])
return MJMLRenderNode(nodelist)
def mjml_render(mjml_source: str) -> str:
return mjml2html(mjml_source) |
@blopker I think you can use |
Tried @blopker version. Works well so far, and about 100x faster than cmd implementation of django-mjml. |
Hey I love to use this package in our project, but adding Node as a runtime dependency has me a bit scared. Are you interested in adding https://github.com/mgd020/mjml-python as an optional backend? It just wraps https://github.com/jdrouet/mrml (the Rust version of MJML) so no extra runtime dependency needed. Thanks!
The text was updated successfully, but these errors were encountered: