use {
super::{ModulePtr, RuntimeInformation},
crate::{config::ModuleConfig, LewpError},
lewp_html::{api::div, NodeExt, Nodes},
std::{cell::RefCell, rc::Rc},
};
pub trait Module {
fn id(&self) -> &str;
fn config(&self) -> &ModuleConfig;
fn head_tags(&self) -> &Nodes;
fn into_module_ptr(self) -> ModulePtr
where
Self: Sized + 'static,
{
Rc::new(RefCell::new(self))
}
fn view(&self) -> Nodes;
fn render(&self) -> Nodes {
if self.config().skip_wrapper {
return self.view();
}
vec![div(self.view()).attrs(vec![
("class", self.id()),
("data-lewp-component", "module"),
])]
}
fn run(
&mut self,
runtime_info: Rc<RuntimeInformation>,
) -> Result<(), LewpError>;
}