1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
use super::prelude::*; use crate::mjml::error::Error; use crate::util::Header; use crate::Options; use roxmltree::Node; #[derive(Clone, Debug)] pub struct MJFont { name: String, href: String, } impl MJFont { pub fn parse<'a, 'b>(node: Node<'a, 'b>, _opts: &Options) -> Result<Self, Error> { let name = match node.attribute("name") { Some(value) => value.to_string(), None => return Err(Error::ParseError("name attribute missing".into())), }; let href = match node.attribute("href") { Some(value) => value.to_string(), None => return Err(Error::ParseError("href attribute missing".into())), }; Ok(Self { name, href }) } } impl HeadComponent for MJFont { fn update_header(&self, header: &mut Header) { header.register_font(self.name.as_str(), self.href.as_str()); } } #[cfg(test)] pub mod tests { use crate::tests::compare_render; #[test] fn base() { compare_render( include_str!("../../../test/mj-font.mjml"), include_str!("../../../test/mj-font.html"), ); } }