Skip to main content

nfw_core/server/
renderer.rs

1pub mod page;
2
3pub use page::{PageMetadata, PageProps};
4
5mod renderer_mod {
6    use std::path::PathBuf;
7
8    #[derive(Clone)]
9    pub struct Renderer {
10        pages_dir: PathBuf,
11    }
12
13    impl Renderer {
14        pub fn new(pages_dir: PathBuf) -> Self {
15            Self { pages_dir }
16        }
17
18        pub async fn render(&self, path: &str, _props: super::PageProps) -> anyhow::Result<String> {
19            Ok(format!("<html><body><h1>{}</h1></body></html>", path))
20        }
21
22        pub fn get_layout_for_path(&self, _path: &str) -> Option<String> {
23            None
24        }
25
26        pub async fn render_with_layout(
27            &self,
28            _path: &str,
29            props: super::PageProps,
30            _layout: &str,
31        ) -> anyhow::Result<String> {
32            self.render(_path, props).await
33        }
34
35        pub fn path_to_page(&self, _route_path: &str) -> String {
36            format!("{}/page.tsx", self.pages_dir.display())
37        }
38    }
39}
40
41pub use renderer_mod::Renderer;