adf_template/
lib.rs

1pub use adf_template_macro::template;
2
3pub mod prelude {
4    pub use super::GenerateADF;
5    pub use adf_template_macro::template;
6}
7
8#[doc(hidden)]
9pub mod __private {
10    pub use htmltoadf::convert_html_str_to_adf_str;
11    pub use serde;
12    pub use tinytemplate;
13}
14
15pub trait GenerateADF {
16    fn to_adf(&self) -> Result<String, Box<dyn std::error::Error>>;
17}
18
19#[cfg(test)]
20mod tests {
21    use super::*;
22    use serde::Serialize;
23
24    #[derive(Serialize)]
25    #[template(path = "../tests/template.html")]
26    struct TestStruct {
27        name: String,
28        age: u32,
29    }
30
31    #[test]
32    fn test_generate_adf() {
33        let test_struct = TestStruct {
34            name: "John".to_string(),
35            age: 20,
36        };
37        let adf = test_struct.to_adf().unwrap();
38        assert_eq!(
39            adf,
40            r#"{"version":1,"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"John"},{"type":"text","text":"20"}]}]}"#
41        );
42    }
43}