From 61813a44e50f02fe56f443d107c38303a653bf02 Mon Sep 17 00:00:00 2001 From: Manuel Cillero Date: Mon, 1 Aug 2022 20:01:36 +0200 Subject: [PATCH] =?UTF-8?q?Actualiza=20denominaciones=20en=20m=C3=B3dulos?= =?UTF-8?q?=20y=20temas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pagetop/src/app/application.rs | 7 +++++-- pagetop/src/core/module/all.rs | 10 ++++++++-- pagetop/src/core/module/definition.rs | 2 ++ pagetop/src/core/theme/all.rs | 2 +- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/pagetop/src/app/application.rs b/pagetop/src/app/application.rs index 8ecb2a84..e588cd6f 100644 --- a/pagetop/src/app/application.rs +++ b/pagetop/src/app/application.rs @@ -51,6 +51,9 @@ impl Application { #[cfg(feature = "database")] module::all::run_migrations(); + // Inicializa los módulos que lo requieran. + module::all::init_modules(); + // Ejecuta la función de inicio de la aplicación. trace::info!("Calling application bootstrap"); app.bootstrap(); @@ -59,8 +62,8 @@ impl Application { let server = super::HttpServer::new(move || { super::App::new() .wrap(tracing_actix_web::TracingLogger::default()) - .configure(&module::all::modules) - .configure(&theme::all::themes) + .configure(&module::all::configure_services) + .configure(&theme::all::configure_services) .default_service(super::web::route().to(service_not_found)) }) .bind(format!( diff --git a/pagetop/src/core/module/all.rs b/pagetop/src/core/module/all.rs index 91220b52..c6cef12c 100644 --- a/pagetop/src/core/module/all.rs +++ b/pagetop/src/core/module/all.rs @@ -72,7 +72,13 @@ fn add_to_enabled(list: &mut Vec, module: ModuleStaticRef) { // CONFIGURE MODULES ******************************************************************************* -pub fn modules(cfg: &mut app::web::ServiceConfig) { +pub fn init_modules() { + for m in ENABLED_MODULES.read().unwrap().iter() { + m.init_module(); + } +} + +pub fn configure_services(cfg: &mut app::web::ServiceConfig) { for m in ENABLED_MODULES.read().unwrap().iter() { m.configure_service(cfg); } @@ -87,7 +93,7 @@ pub fn register_actions() { } #[cfg(feature = "database")] -pub fn run_migrations() { +pub(crate) fn run_migrations() { run_now({ struct Migrator; impl MigratorTrait for Migrator { diff --git a/pagetop/src/core/module/definition.rs b/pagetop/src/core/module/definition.rs index 17105ba0..4e04050d 100644 --- a/pagetop/src/core/module/definition.rs +++ b/pagetop/src/core/module/definition.rs @@ -27,6 +27,8 @@ pub trait ModuleTrait: BaseModule + Send + Sync { vec![] } + fn init_module(&self) {} + #[allow(unused_variables)] fn configure_service(&self, cfg: &mut app::web::ServiceConfig) {} diff --git a/pagetop/src/core/theme/all.rs b/pagetop/src/core/theme/all.rs index 1f728ca8..9ee3b095 100644 --- a/pagetop/src/core/theme/all.rs +++ b/pagetop/src/core/theme/all.rs @@ -34,7 +34,7 @@ pub fn theme_by_single_name(single_name: &str) -> Option { } } -pub fn themes(cfg: &mut app::web::ServiceConfig) { +pub fn configure_services(cfg: &mut app::web::ServiceConfig) { theme_static_files!(cfg, "/theme"); for t in THEMES.read().unwrap().iter() {