-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mrml-python): implement mj-include (#381)
* feat(mrml-python): create local loader Signed-off-by: Jérémie Drouet <jeremie.drouet@gmail.com> * feat(mrml-python): create http loader Signed-off-by: Jérémie Drouet <jeremie.drouet@gmail.com> * chore(mrml-python): update editor config Signed-off-by: Jérémie Drouet <jeremie.drouet@gmail.com> --------- Signed-off-by: Jérémie Drouet <jeremie.drouet@gmail.com>
- Loading branch information
Showing
8 changed files
with
228 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<mj-text>Hello World</mj-text> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<mjml> | ||
<mj-body> | ||
<mj-include | ||
path="https://gist.githubusercontent.com/jdrouet/b0ac80fa08a3e7262bd4c94fc8865a87/raw/ec8771f4804a6c38427ed2a9f5937e11ec2b8c27/hello-world.mjml" | ||
/> | ||
</mj-body> | ||
</mjml> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<mjml> | ||
<mj-body> | ||
<mj-include path="file:///hello-world.mjml" /> | ||
</mj-body> | ||
</mjml> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<mjml> | ||
<mj-body> | ||
<mj-include path="file:///hello-world.mjml" /> | ||
<mj-include | ||
path="https://gist.githubusercontent.com/jdrouet/b0ac80fa08a3e7262bd4c94fc8865a87/raw/ec8771f4804a6c38427ed2a9f5937e11ec2b8c27/hello-world.mjml" | ||
/> | ||
</mj-body> | ||
</mjml> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import mrml | ||
|
||
|
||
def test_memory_loader(): | ||
parser_options = mrml.ParserOptions( | ||
include_loader=mrml.memory_loader( | ||
{ | ||
"hello-world.mjml": "<mj-text>Hello World!</mj-text>", | ||
} | ||
) | ||
) | ||
result = mrml.to_html( | ||
'<mjml><mj-body><mj-include path="hello-world.mjml" /></mj-body></mjml>', | ||
parser_options=parser_options, | ||
) | ||
assert result.startswith("<!doctype html>") | ||
|
||
|
||
def test_local_loader_success(): | ||
parser_options = mrml.ParserOptions( | ||
include_loader=mrml.local_loader("./resources/partials") | ||
) | ||
result = mrml.to_html( | ||
'<mjml><mj-body><mj-include path="file:///hello-world.mjml" /></mj-body></mjml>', | ||
parser_options=parser_options, | ||
) | ||
assert result.startswith("<!doctype html>") | ||
|
||
|
||
def test_local_loader_missing(): | ||
parser_options = mrml.ParserOptions( | ||
include_loader=mrml.local_loader("./resources/partials") | ||
) | ||
try: | ||
mrml.to_html( | ||
'<mjml><mj-body><mj-include path="file:///not-found.mjml" /></mj-body></mjml>', | ||
parser_options=parser_options, | ||
) | ||
assert False | ||
except Exception as err: | ||
assert err | ||
|
||
|
||
def test_http_loader_success(): | ||
parser_options = mrml.ParserOptions( | ||
include_loader=mrml.http_loader( | ||
mode=mrml.HttpIncludeLoaderOptionsMode.Allow, | ||
list=set(["https://gist.githubusercontent.com"]), | ||
) | ||
) | ||
result = mrml.to_html( | ||
"""<mjml> | ||
<mj-body> | ||
<mj-include | ||
path="https://gist.githubusercontent.com/jdrouet/b0ac80fa08a3e7262bd4c94fc8865a87/raw/ec8771f4804a6c38427ed2a9f5937e11ec2b8c27/hello-world.mjml" | ||
/> | ||
</mj-body> | ||
</mjml>""", | ||
parser_options=parser_options, | ||
) | ||
assert result.startswith("<!doctype html>") | ||
|
||
|
||
def test_http_loader_failed_not_in_allow_list(): | ||
parser_options = mrml.ParserOptions( | ||
include_loader=mrml.http_loader( | ||
mode=mrml.HttpIncludeLoaderOptionsMode.Allow, | ||
list=set([]), | ||
) | ||
) | ||
try: | ||
mrml.to_html( | ||
"""<mjml> | ||
<mj-body> | ||
<mj-include | ||
path="https://gist.githubusercontent.com/jdrouet/b0ac80fa08a3e7262bd4c94fc8865a87/raw/ec8771f4804a6c38427ed2a9f5937e11ec2b8c27/hello-world.mjml" | ||
/> | ||
</mj-body> | ||
</mjml>""", | ||
parser_options=parser_options, | ||
) | ||
assert False | ||
except Exception as err: | ||
assert err | ||
|
||
|
||
def test_http_loader_success_allow_everything(): | ||
parser_options = mrml.ParserOptions( | ||
include_loader=mrml.http_loader(mode=mrml.HttpIncludeLoaderOptionsMode.Deny) | ||
) | ||
mrml.to_html( | ||
"""<mjml> | ||
<mj-body> | ||
<mj-include | ||
path="https://gist.githubusercontent.com/jdrouet/b0ac80fa08a3e7262bd4c94fc8865a87/raw/ec8771f4804a6c38427ed2a9f5937e11ec2b8c27/hello-world.mjml" | ||
/> | ||
</mj-body> | ||
</mjml>""", | ||
parser_options=parser_options, | ||
) | ||
|
||
|
||
def test_http_loader_failed_deny_github(): | ||
parser_options = mrml.ParserOptions( | ||
include_loader=mrml.http_loader( | ||
mode=mrml.HttpIncludeLoaderOptionsMode.Deny, | ||
list=set(["https://gist.githubusercontent.com"]), | ||
) | ||
) | ||
try: | ||
mrml.to_html( | ||
"""<mjml> | ||
<mj-body> | ||
<mj-include | ||
path="https://gist.githubusercontent.com/jdrouet/b0ac80fa08a3e7262bd4c94fc8865a87/raw/ec8771f4804a6c38427ed2a9f5937e11ec2b8c27/hello-world.mjml" | ||
/> | ||
</mj-body> | ||
</mjml>""", | ||
parser_options=parser_options, | ||
) | ||
assert False | ||
except Exception as err: | ||
assert err |