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_desc = Administration module.
module_fullname = Admin module
module_description = Administration module.

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -5,16 +5,16 @@ localize!("en-US", "src/base/module/user/locales");
pub struct UserModule;
impl Module for UserModule {
fn id(&self) -> &'static str {
fn name(&self) -> &'static str {
"user"
}
fn name(&self) -> String {
l("module_name")
fn fullname(&self) -> String {
l("module_fullname")
}
fn description(&self) -> String {
l("module_desc")
l("module_description")
}
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;
impl Theme for AlinerTheme {
fn id(&self) -> &'static str {
fn name(&self) -> &'static str {
"aliner"
}
fn name(&self) -> String {
fn fullname(&self) -> String {
"Aliner".to_string()
}

View file

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

View file

@ -3,11 +3,11 @@ use crate::prelude::*;
pub struct MinimalTheme;
impl Theme for MinimalTheme {
fn id(&self) -> &'static str {
fn name(&self) -> &'static str {
"minimal"
}
fn name(&self) -> String {
fn fullname(&self) -> 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*.
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 {
"".to_string()
@ -14,3 +14,15 @@ pub trait Module: Send + Sync {
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;
pub use api::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,
}
}
pub use api::{Module, find_module, register_module};