1#![allow(dead_code)]
2
3use std::marker::PhantomData;
4
5use crate::mj_body::MjBody;
6use crate::mj_head::MjHead;
7use crate::prelude::{Component, StaticTag};
8
9#[cfg(feature = "json")]
10mod json;
11#[cfg(feature = "parse")]
12pub mod parse;
13#[cfg(feature = "print")]
14mod print;
15#[cfg(feature = "render")]
16mod render;
17
18pub const NAME: &str = "mjml";
19
20#[derive(Clone, Debug, Default)]
21#[cfg_attr(feature = "json", derive(serde::Serialize, serde::Deserialize))]
22pub struct MjmlAttributes {
23 #[cfg_attr(feature = "json", serde(skip_serializing_if = "Option::is_none"))]
24 pub owa: Option<String>,
25 #[cfg_attr(feature = "json", serde(skip_serializing_if = "Option::is_none"))]
26 pub lang: Option<String>,
27 #[cfg_attr(feature = "json", serde(skip_serializing_if = "Option::is_none"))]
28 pub dir: Option<String>,
29}
30
31impl MjmlAttributes {
32 fn lang(&self) -> &str {
33 self.lang.as_deref().unwrap_or("und")
34 }
35
36 fn dir(&self) -> &str {
37 self.dir.as_deref().unwrap_or("auto")
38 }
39}
40
41#[derive(Clone, Debug, Default)]
42pub struct MjmlChildren {
43 pub head: Option<MjHead>,
44 pub body: Option<MjBody>,
45}
46
47pub struct MjmlTag;
48
49impl StaticTag for MjmlTag {
50 fn static_tag() -> &'static str {
51 NAME
52 }
53}
54
55pub type Mjml = Component<PhantomData<MjmlTag>, MjmlAttributes, MjmlChildren>;
58
59impl Mjml {
60 pub fn body(&self) -> Option<&MjBody> {
61 self.children.body.as_ref()
62 }
63
64 pub fn head(&self) -> Option<&MjHead> {
65 self.children.head.as_ref()
66 }
67}