✏️ [pagetop] Un tema es ahora un tipo de módulo
This commit is contained in:
parent
84f1fc4a5c
commit
8ec2c698c8
14 changed files with 61 additions and 80 deletions
60
pagetop/src/core/module/module.rs
Normal file
60
pagetop/src/core/module/module.rs
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
use super::ThemeStaticRef;
|
||||
|
||||
use crate::core::hook::HookAction;
|
||||
use crate::server;
|
||||
use crate::util::{single_type_name, Handle};
|
||||
|
||||
#[cfg(feature = "database")]
|
||||
use crate::db::MigrationItem;
|
||||
|
||||
pub type ModuleStaticRef = &'static dyn ModuleTrait;
|
||||
|
||||
pub trait BaseModule {
|
||||
fn single_name(&self) -> &'static str;
|
||||
}
|
||||
|
||||
/// Los módulos deben implementar este *trait*.
|
||||
pub trait ModuleTrait: BaseModule + Send + Sync {
|
||||
fn handle(&self) -> Handle;
|
||||
|
||||
fn name(&self) -> String {
|
||||
self.single_name().to_owned()
|
||||
}
|
||||
|
||||
fn description(&self) -> Option<String> {
|
||||
None
|
||||
}
|
||||
|
||||
fn theme(&self) -> Option<ThemeStaticRef> {
|
||||
None
|
||||
}
|
||||
|
||||
fn dependencies(&self) -> Vec<ModuleStaticRef> {
|
||||
vec![]
|
||||
}
|
||||
|
||||
fn drop_modules(&self) -> Vec<ModuleStaticRef> {
|
||||
vec![]
|
||||
}
|
||||
|
||||
fn actions(&self) -> Vec<HookAction> {
|
||||
vec![]
|
||||
}
|
||||
|
||||
fn init(&self) {}
|
||||
|
||||
#[cfg(feature = "database")]
|
||||
#[allow(unused_variables)]
|
||||
fn migrations(&self) -> Vec<MigrationItem> {
|
||||
vec![]
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn configure_service(&self, cfg: &mut server::web::ServiceConfig) {}
|
||||
}
|
||||
|
||||
impl<M: ?Sized + ModuleTrait> BaseModule for M {
|
||||
fn single_name(&self) -> &'static str {
|
||||
single_type_name::<Self>()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue