1pub mod body;
2pub mod head;
3
4pub const NAME: &str = "mj-include";
5
6#[cfg(all(test, feature = "parse", feature = "render"))]
7mod tests {
8 use crate::mjml::Mjml;
9 use crate::prelude::parser::memory_loader::MemoryIncludeLoader;
10 use crate::prelude::parser::ParserOptions;
11 use crate::prelude::render::RenderOptions;
12
13 #[test]
14 fn should_render_css_in_include() {
15 let with_include = Mjml::parse_with_options(
16 r#"<mjml>
17<mj-head>
18 <mj-include path="style.css" type="css" />
19</mj-head>
20<mj-body>
21 <mj-text>Hello World!</mj-text>
22</mj-body>
23</mjml>"#,
24 &ParserOptions {
25 include_loader: Box::new(MemoryIncludeLoader::from(vec![(
26 "style.css",
27 ".container { background-color: #fffaee; padding: 48px 0px; }",
28 )])),
29 },
30 )
31 .unwrap();
32 let basic = Mjml::parse(
33 r#"<mjml>
34<mj-head>
35 <mj-style>.container { background-color: #fffaee; padding: 48px 0px; }</mj-style>
36</mj-head>
37<mj-body>
38 <mj-text>Hello World!</mj-text>
39</mj-body>
40</mjml>"#,
41 )
42 .unwrap();
43
44 let basic = basic.element.render(&RenderOptions::default()).unwrap();
45 let with_include = with_include
46 .element
47 .render(&RenderOptions::default())
48 .unwrap();
49 similar_asserts::assert_eq!(basic, with_include);
50 }
51
52 #[test]
53 fn should_render_mj_style_in_include() {
54 let with_include = Mjml::parse_with_options(
55 r#"<mjml>
56<mj-head>
57 <mj-include path="style.mjml" />
58</mj-head>
59<mj-body>
60 <mj-text>Hello World!</mj-text>
61</mj-body>
62</mjml>"#,
63 &ParserOptions {
64 include_loader: Box::new(MemoryIncludeLoader::from(vec![(
65 "style.mjml",
66 r#"<mj-style>
67.container { background-color: #fffaee; padding: 48px 0px; }
68</mj-style>"#,
69 )])),
70 },
71 )
72 .unwrap();
73 let basic = Mjml::parse(
74 r#"<mjml>
75<mj-head>
76 <mj-style>.container { background-color: #fffaee; padding: 48px 0px; }</mj-style>
77</mj-head>
78<mj-body>
79 <mj-text>Hello World!</mj-text>
80</mj-body>
81</mjml>"#,
82 )
83 .unwrap();
84
85 let basic = basic.element.render(&RenderOptions::default()).unwrap();
86 let with_include = with_include
87 .element
88 .render(&RenderOptions::default())
89 .unwrap();
90 similar_asserts::assert_eq!(basic, with_include);
91 }
92}