catapulte_engine/
render.rs

1use std::collections::HashMap;
2
3pub use mrml::prelude::render::Error;
4
5#[derive(Clone, Debug, Default, serde::Deserialize)]
6pub struct Config {
7    #[serde(default)]
8    pub disable_comments: bool,
9    #[serde(default)]
10    pub social_icon_origin: Option<String>,
11    #[serde(default)]
12    pub fonts: Option<HashMap<String, String>>,
13}
14
15impl From<Config> for mrml::prelude::render::RenderOptions {
16    fn from(value: Config) -> Self {
17        let mut result: Self = mrml::prelude::render::RenderOptions {
18            disable_comments: value.disable_comments,
19            ..Default::default()
20        };
21        if let Some(origin) = value.social_icon_origin {
22            result.social_icon_origin = Some(origin.into());
23        }
24        // `RenderOptions.fonts` has a default list of `fonts`. We want to be able
25        // to override this list but to keep it if `fonts` is `None`.
26        if let Some(fonts) = value.fonts {
27            result.fonts = fonts
28                .into_iter()
29                .map(|(key, value)| (key, value.into()))
30                .collect();
31        }
32        result
33    }
34}