-
-
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-cli): handle mj-include with http and local loaders (#380)
* test(mrml-core): add local loading mj-include test Signed-off-by: Jérémie Drouet <jeremie.drouet@gmail.com> * feat(mrml-cli): allow to use local include Signed-off-by: Jérémie Drouet <jeremie.drouet@gmail.com> * refactor(mrml-cli): using array instead of vec Signed-off-by: Jérémie Drouet <jeremie.drouet@gmail.com> * feat(mrml-cli): handle mj-include with local and http loaders 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
220 additions
and
16 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
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,27 @@ | ||
#![cfg(all(feature = "parse", feature = "render", feature = "local-loader"))] | ||
|
||
use std::assert; | ||
|
||
const TEMPLATE_PATH: &str = "file:///mj-text-hello-world.mjml"; | ||
|
||
#[test] | ||
fn loading_include() { | ||
use mrml::prelude::parser::local_loader::LocalIncludeLoader; | ||
use mrml::prelude::parser::ParserOptions; | ||
use mrml::prelude::render::RenderOptions; | ||
|
||
let template = format!("<mjml><mj-body><mj-include path={TEMPLATE_PATH:?} /></mj-body></mjml>"); | ||
let resolver = LocalIncludeLoader::new( | ||
std::env::current_dir() | ||
.unwrap() | ||
.join("tests") | ||
.join("resources"), | ||
); | ||
let options = ParserOptions { | ||
include_loader: Box::new(resolver), | ||
}; | ||
let parsed = mrml::parse_with_options(template, &options).unwrap(); | ||
let output = parsed.render(&RenderOptions::default()).unwrap(); | ||
|
||
assert!(output.contains("Hello World")); | ||
} |
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> |