Closed buttle closed 3 years ago
I think this code should solve your problem (untested, though mostly copied from mjml.py):
from pathlib import Path
from mjml.mjml2html import mjml_to_html
with Path(mjml_filename).open('rb') as mjml_fp:
result = mjml_to_html(mjml_fp)
assert not result.errors
html_str = result.html
Yes sir!
To take this one step further. Could I pass the mjml file content directly to a mjml-stub function?
result = mjml.some_funtion(mjml_file_content)
Currently such a convenience function is not present though adding it would be probably a good idea.
These functions could be named mjml.render_html_from_file(<fp>/<path>)
and mjml.render_html_from_string(<str>)
and would just return the HTML as str
(raising an exception whenever result.errors
is not empty). Users who need more control could call mjml.process_mjml_from_file(<fp>/<path>)
which would return the result
instance.
I'd be happy to merge your pull request 😀 You don't have to implement all the functions but I like to map out the API in advance so the final API is somewhat consistently named.
implemented in e779836
So far no additional API (e.g. mjml.render_html_from_file(<fp>/<path>)
) but that can be done in a future PR.
Hi,
I would like to be able to do something like this
Is that possible?
Cheers.