use jinja_renderer::{OwnedTemplate, RenderContext, Renderer, Template}; use once_cell::sync::OnceCell; use serde::Serialize; static RENDERER: OnceCell = OnceCell::new(); #[derive(Debug, Serialize, Template)] #[template(name = "foo.html.j2")] struct Foo<'a> { bar: &'a str, } #[cfg(feature = "minify")] #[test] fn test_minify() { let data = Foo { bar: "baz" }; let renderer = get_render(); let ret = data.render(renderer).unwrap(); assert_eq!(ret, "baz"); } #[cfg(not(feature = "minify"))] #[test] fn test_not_minify() { let data = Foo { bar: "baz" }; let renderer = get_render(); let ret = data.render(renderer).unwrap(); assert_eq!(ret, "\n \n baz\n \n"); } fn get_render() -> &'static Renderer { RENDERER.get_or_init(|| { let templates = vec![OwnedTemplate::new( "foo.html.j2", "\n \n {{ bar }}\n \n", )]; let mut renderer = Renderer::default(); renderer.add_templates(templates.into_iter()).unwrap(); renderer }) }