use { lewp::{ config::{ModuleConfig, PageConfig}, html::{api::*, Nodes}, Charset, LanguageTag, LewpError, Module, Modules, Page, RuntimeInformation, }, std::rc::Rc, }; struct HelloWorld { pub config: ModuleConfig, head_tags: Nodes, data: String, } impl HelloWorld { pub fn new() -> Self { Self { config: ModuleConfig::new(), head_tags: vec![], data: String::from("hello-world"), } } } impl From for HelloWorld { fn from(config: ModuleConfig) -> Self { Self { config, head_tags: vec![], data: String::from("hello-world"), } } } impl Module for HelloWorld { fn head_tags(&self) -> &Nodes { &self.head_tags } fn id(&self) -> &str { "hello-world" } fn config(&self) -> &ModuleConfig { &self.config } fn run( &mut self, _runtime_info: Rc, ) -> Result<(), LewpError> { Ok(()) } fn view(&self) -> Nodes { vec![h1(vec![text(&self.data)])] } } struct HelloWorldPage { modules: Modules, config: PageConfig, } impl Page for HelloWorldPage { fn modules(&self) -> &Modules { &self.modules } fn modules_mut(&mut self) -> &mut Modules { &mut self.modules } fn title(&self) -> &str { "Hello World from lewp!" } fn description(&self) -> &str { "My first page using lewp!" } fn language(&self) -> LanguageTag { LanguageTag::parse("de-DE").unwrap() } fn charset(&self) -> Charset { Charset::Utf8 } fn config(&self) -> &PageConfig { &self.config } fn run(&mut self) {} } const HELLO_WORLD_RESULT: &str = "Hello World from lewp!

hello-world

"; const HELLO_WORLD_RESULT_SKIPPED_WRAPPER: &str = "Hello World from lewp!

hello-world

"; #[test] fn hello_world_with_module_wrapper() { let module = HelloWorld::new(); let mut page = HelloWorldPage { modules: vec![], config: PageConfig::new(), }; page.add_module(module.into_module_ptr()); let html_string = page.build(); assert_eq!(HELLO_WORLD_RESULT, html_string); } #[test] fn hello_world_skipped_wrapper() { let module_config = ModuleConfig { skip_wrapper: true }; let module = HelloWorld::from(module_config); let mut page = HelloWorldPage { modules: vec![], config: PageConfig::new(), }; page.add_module(module.into_module_ptr()); let html_string = page.build(); assert_eq!(HELLO_WORLD_RESULT_SKIPPED_WRAPPER, html_string); }