1mod children;
2#[cfg(feature = "json")]
3mod json;
4#[cfg(feature = "parse")]
5mod parse;
6#[cfg(feature = "print")]
7mod print;
8#[cfg(feature = "render")]
9mod render;
10
11use std::marker::PhantomData;
12
13pub use children::MjHeadChild;
14
15use crate::prelude::{Component, StaticTag};
16
17pub const NAME: &str = "mj-head";
18
19pub struct MjHeadTag;
20
21impl StaticTag for MjHeadTag {
22 fn static_tag() -> &'static str {
23 NAME
24 }
25}
26
27pub type MjHead = Component<PhantomData<MjHeadTag>, (), Vec<MjHeadChild>>;
28
29#[cfg(feature = "render")]
30impl MjHead {
31 pub fn breakpoint(&self) -> Option<&crate::mj_breakpoint::MjBreakpoint> {
32 self.children
33 .iter()
34 .flat_map(|item| {
35 item.as_mj_breakpoint().into_iter().chain(
36 item.as_mj_include()
37 .into_iter()
38 .filter(|item| item.0.attributes.kind.is_mjml())
39 .flat_map(|inner| {
40 inner
41 .0
42 .children
43 .iter()
44 .filter_map(|child| child.as_mj_breakpoint())
45 }),
46 )
47 })
48 .last()
49 }
50
51 pub fn preview(&self) -> Option<&crate::mj_preview::MjPreview> {
52 self.children
53 .iter()
54 .flat_map(|item| {
55 item.as_mj_preview().into_iter().chain(
56 item.as_mj_include()
57 .into_iter()
58 .filter(|item| item.0.attributes.kind.is_mjml())
59 .flat_map(|inner| {
60 inner
61 .0
62 .children
63 .iter()
64 .filter_map(|child| child.as_mj_preview())
65 }),
66 )
67 })
68 .last()
69 }
70
71 pub fn title(&self) -> Option<&crate::mj_title::MjTitle> {
72 self.children
73 .iter()
74 .flat_map(|item| {
75 item.as_mj_title().into_iter().chain(
76 item.as_mj_include()
77 .into_iter()
78 .filter(|item| item.0.attributes.kind.is_mjml())
79 .flat_map(|inner| {
80 inner
81 .0
82 .children
83 .iter()
84 .filter_map(|child| child.as_mj_title())
85 }),
86 )
87 })
88 .last()
89 }
90
91 pub fn children(&self) -> &Vec<MjHeadChild> {
92 &self.children
93 }
94}