Modifica la identificación de módulos

This commit is contained in:
Manuel Cillero 2022-03-01 17:50:36 +01:00
parent 0f185887a6
commit 9e65f89d2d
14 changed files with 46 additions and 48 deletions

View file

@ -1,2 +1,2 @@
module_name = Admin module module_fullname = Admin module
module_desc = Administration module. module_description = Administration module.

View file

@ -1,2 +1,2 @@
module_name = Admin module module_fullname = Admin module
module_desc = Módulo de administración. module_description = Módulo de administración.

View file

@ -7,16 +7,16 @@ mod summary;
pub struct AdminModule; pub struct AdminModule;
impl Module for AdminModule { impl Module for AdminModule {
fn id(&self) -> &'static str { fn name(&self) -> &'static str {
"admin" "admin"
} }
fn name(&self) -> String { fn fullname(&self) -> String {
l("module_name") l("module_fullname")
} }
fn description(&self) -> String { fn description(&self) -> String {
l("module_desc") l("module_description")
} }
fn configure_module(&self, cfg: &mut server::web::ServiceConfig) { fn configure_module(&self, cfg: &mut server::web::ServiceConfig) {

View file

@ -1,5 +1,5 @@
module_name = Default homepage module_fullname = Default homepage
module_desc = Displays a default homepage when none is configured. module_description = Displays a default homepage when none is configured.
page_title = Hello world! page_title = Hello world!

View file

@ -1,5 +1,5 @@
module_name = Página de inicio predeterminada module_fullname = Página de inicio predeterminada
module_desc = Muestra una página de inicio predeterminada cuando no hay ninguna configurada. module_description = Muestra una página de inicio predeterminada cuando no hay ninguna configurada.
page_title = ¡Hola mundo! page_title = ¡Hola mundo!

View file

@ -5,16 +5,16 @@ localize!("en-US", "src/base/module/homepage/locales");
pub struct HomepageModule; pub struct HomepageModule;
impl Module for HomepageModule { impl Module for HomepageModule {
fn id(&self) -> &'static str { fn name(&self) -> &'static str {
"homepage" "homepage"
} }
fn name(&self) -> String { fn fullname(&self) -> String {
l("module_name") l("module_fullname")
} }
fn description(&self) -> String { fn description(&self) -> String {
l("module_desc") l("module_description")
} }
fn configure_module(&self, cfg: &mut server::web::ServiceConfig) { fn configure_module(&self, cfg: &mut server::web::ServiceConfig) {

View file

@ -1,5 +1,5 @@
module_name = User module_fullname = User
module_desc = Manages the user registration and login system. module_description = Manages the user registration and login system.
username = User name username = User name
password = Password password = Password

View file

@ -1,5 +1,5 @@
module_name = Usuario module_fullname = Usuario
module_desc = Gestion el registro de usuarios y el sistema de accesos. module_description = Gestion el registro de usuarios y el sistema de accesos.
username = Nombre de usuario username = Nombre de usuario
password = Contraseña password = Contraseña

View file

@ -5,16 +5,16 @@ localize!("en-US", "src/base/module/user/locales");
pub struct UserModule; pub struct UserModule;
impl Module for UserModule { impl Module for UserModule {
fn id(&self) -> &'static str { fn name(&self) -> &'static str {
"user" "user"
} }
fn name(&self) -> String { fn fullname(&self) -> String {
l("module_name") l("module_fullname")
} }
fn description(&self) -> String { fn description(&self) -> String {
l("module_desc") l("module_description")
} }
fn configure_module(&self, cfg: &mut server::web::ServiceConfig) { fn configure_module(&self, cfg: &mut server::web::ServiceConfig) {

View file

@ -5,11 +5,11 @@ include!(concat!(env!("OUT_DIR"), "/aliner.rs"));
pub struct AlinerTheme; pub struct AlinerTheme;
impl Theme for AlinerTheme { impl Theme for AlinerTheme {
fn id(&self) -> &'static str { fn name(&self) -> &'static str {
"aliner" "aliner"
} }
fn name(&self) -> String { fn fullname(&self) -> String {
"Aliner".to_string() "Aliner".to_string()
} }

View file

@ -7,11 +7,11 @@ localize!("en-US", "src/base/theme/bootsier/locales");
pub struct BootsierTheme; pub struct BootsierTheme;
impl Theme for BootsierTheme { impl Theme for BootsierTheme {
fn id(&self) -> &'static str { fn name(&self) -> &'static str {
"bootsier" "bootsier"
} }
fn name(&self) -> String { fn fullname(&self) -> String {
"Bootsier".to_string() "Bootsier".to_string()
} }

View file

@ -3,11 +3,11 @@ use crate::prelude::*;
pub struct MinimalTheme; pub struct MinimalTheme;
impl Theme for MinimalTheme { impl Theme for MinimalTheme {
fn id(&self) -> &'static str { fn name(&self) -> &'static str {
"minimal" "minimal"
} }
fn name(&self) -> String { fn fullname(&self) -> String {
"Minimal".to_string() "Minimal".to_string()
} }
} }

View file

@ -1,10 +1,10 @@
use crate::core::server; use crate::core::{all, server};
/// Los módulos deben implementar este *trait*. /// Los módulos deben implementar este *trait*.
pub trait Module: Send + Sync { pub trait Module: Send + Sync {
fn id(&self) -> &'static str; fn name(&self) -> &'static str;
fn name(&self) -> String; fn fullname(&self) -> String;
fn description(&self) -> String { fn description(&self) -> String {
"".to_string() "".to_string()
@ -14,3 +14,15 @@ pub trait Module: Send + Sync {
fn configure_module(&self, cfg: &mut server::web::ServiceConfig) { fn configure_module(&self, cfg: &mut server::web::ServiceConfig) {
} }
} }
pub fn register_module(m: &'static (dyn Module + 'static)) {
all::MODULES.write().unwrap().push(m);
}
pub fn find_module(name: &str) -> Option<&'static (dyn Module + 'static)> {
let modules = all::MODULES.write().unwrap();
match modules.iter().find(|t| t.name() == name) {
Some(module) => Some(*module),
_ => None,
}
}

View file

@ -1,16 +1,2 @@
use crate::core::all::MODULES;
mod api; mod api;
pub use api::Module; pub use api::{Module, find_module, register_module};
pub fn register_module(m: &'static (dyn Module + 'static)) {
MODULES.write().unwrap().push(m);
}
pub fn find_module(id: &str) -> Option<&'static (dyn Module + 'static)> {
let modules = MODULES.write().unwrap();
match modules.iter().find(|t| t.id() == id) {
Some(module) => Some(*module),
_ => None,
}
}