💥 ModuleRef and ThemeRef replace *StaticRef

This commit is contained in:
Manuel Cillero 2023-07-21 18:34:26 +02:00
parent 05304f116a
commit 09ac316cb5
17 changed files with 38 additions and 39 deletions

View file

@ -9,7 +9,7 @@ impl ModuleTrait for Drust {
APP_DRUST APP_DRUST
} }
fn dependencies(&self) -> Vec<ModuleStaticRef> { fn dependencies(&self) -> Vec<ModuleRef> {
vec![ vec![
// Themes. // Themes.
&pagetop_aliner::Aliner, &pagetop_aliner::Aliner,
@ -23,7 +23,7 @@ impl ModuleTrait for Drust {
] ]
} }
fn drop_modules(&self) -> Vec<ModuleStaticRef> { fn drop_modules(&self) -> Vec<ModuleRef> {
vec![ vec![
// &pagetop_node::Node // &pagetop_node::Node
] ]

View file

@ -22,7 +22,7 @@ impl ModuleTrait for Admin {
} }
#[rustfmt::skip] #[rustfmt::skip]
fn dependencies(&self) -> Vec<ModuleStaticRef> { fn dependencies(&self) -> Vec<ModuleRef> {
vec![ vec![
&pagetop_minimal::Minimal, &pagetop_minimal::Minimal,
&pagetop_megamenu::MegaMenu, &pagetop_megamenu::MegaMenu,

View file

@ -11,7 +11,7 @@ impl ModuleTrait for Aliner {
THEME_ALINER THEME_ALINER
} }
fn theme(&self) -> Option<ThemeStaticRef> { fn theme(&self) -> Option<ThemeRef> {
Some(&Aliner) Some(&Aliner)
} }

View file

@ -14,11 +14,11 @@ impl ModuleTrait for Bootsier {
THEME_BOOTSIER THEME_BOOTSIER
} }
fn theme(&self) -> Option<ThemeStaticRef> { fn theme(&self) -> Option<ThemeRef> {
Some(&Bootsier) Some(&Bootsier)
} }
fn dependencies(&self) -> Vec<ModuleStaticRef> { fn dependencies(&self) -> Vec<ModuleRef> {
vec![&pagetop_jquery::JQuery] vec![&pagetop_jquery::JQuery]
} }

View file

@ -13,12 +13,12 @@ impl ModuleTrait for Bulmix {
THEME_BULMIX THEME_BULMIX
} }
fn theme(&self) -> Option<ThemeStaticRef> { fn theme(&self) -> Option<ThemeRef> {
Some(&Bulmix) Some(&Bulmix)
} }
#[rustfmt::skip] #[rustfmt::skip]
fn dependencies(&self) -> Vec<ModuleStaticRef> { fn dependencies(&self) -> Vec<ModuleRef> {
vec![ vec![
&pagetop_jquery::JQuery, &pagetop_jquery::JQuery,
&pagetop_minimal::Minimal, &pagetop_minimal::Minimal,

View file

@ -22,7 +22,7 @@ impl ModuleTrait for HomeDemo {
L10n::t("module_description", &LOCALES_HOMEDEMO) L10n::t("module_description", &LOCALES_HOMEDEMO)
} }
fn dependencies(&self) -> Vec<ModuleStaticRef> { fn dependencies(&self) -> Vec<ModuleRef> {
vec![&pagetop_minimal::Minimal] vec![&pagetop_minimal::Minimal]
} }

View file

@ -13,7 +13,7 @@ impl ModuleTrait for MegaMenu {
MODULE_MEGAMENU MODULE_MEGAMENU
} }
fn dependencies(&self) -> Vec<ModuleStaticRef> { fn dependencies(&self) -> Vec<ModuleRef> {
vec![&pagetop_jquery::JQuery, &pagetop_minimal::Minimal] vec![&pagetop_jquery::JQuery, &pagetop_minimal::Minimal]
} }

View file

@ -22,7 +22,7 @@ impl ModuleTrait for User {
L10n::t("module_description", &LOCALES_USER) L10n::t("module_description", &LOCALES_USER)
} }
fn dependencies(&self) -> Vec<ModuleStaticRef> { fn dependencies(&self) -> Vec<ModuleRef> {
vec![&pagetop_minimal::Minimal] vec![&pagetop_minimal::Minimal]
} }

View file

@ -2,7 +2,7 @@
mod figfont; mod figfont;
use crate::core::{module, module::ModuleStaticRef}; use crate::core::{module, module::ModuleRef};
use crate::html::Markup; use crate::html::Markup;
use crate::response::fatal_error::FatalError; use crate::response::fatal_error::FatalError;
use crate::response::page::ResultPage; use crate::response::page::ResultPage;
@ -26,7 +26,7 @@ pub struct Application {
} }
impl Application { impl Application {
pub fn prepare(app: ModuleStaticRef) -> Result<Self, Error> { pub fn prepare(app: ModuleRef) -> Result<Self, Error> {
// Rótulo de presentación. // Rótulo de presentación.
print_on_startup(); print_on_startup();

View file

@ -1,5 +1,5 @@
use crate::core::theme::all::{theme_by_single_name, THEME}; use crate::core::theme::all::{theme_by_single_name, THEME};
use crate::core::theme::ThemeStaticRef; use crate::core::theme::ThemeRef;
use crate::html::{html, Assets, HeadScript, HeadStyles, JavaScript, Markup, StyleSheet}; use crate::html::{html, Assets, HeadScript, HeadStyles, JavaScript, Markup, StyleSheet};
use crate::locale::{LanguageIdentifier, LANGID}; use crate::locale::{LanguageIdentifier, LANGID};
use crate::service::HttpRequest; use crate::service::HttpRequest;
@ -29,7 +29,7 @@ pub enum ContextOp {
pub struct Context { pub struct Context {
request : HttpRequest, request : HttpRequest,
langid : &'static LanguageIdentifier, langid : &'static LanguageIdentifier,
theme : ThemeStaticRef, theme : ThemeRef,
stylesheet: Assets<StyleSheet>, // Stylesheets. stylesheet: Assets<StyleSheet>, // Stylesheets.
headstyles: Assets<HeadStyles>, // Styles in head. headstyles: Assets<HeadStyles>, // Styles in head.
javascript: Assets<JavaScript>, // JavaScripts. javascript: Assets<JavaScript>, // JavaScripts.
@ -99,7 +99,7 @@ impl Context {
self.langid self.langid
} }
pub(crate) fn theme(&self) -> ThemeStaticRef { pub(crate) fn theme(&self) -> ThemeRef {
self.theme self.theme
} }

View file

@ -1,4 +1,4 @@
mod definition; mod definition;
pub use definition::{ModuleBase, ModuleStaticRef, ModuleTrait}; pub use definition::{ModuleBase, ModuleRef, ModuleTrait};
pub(crate) mod all; pub(crate) mod all;

View file

@ -1,5 +1,5 @@
use crate::core::action::add_action; use crate::core::action::add_action;
use crate::core::module::ModuleStaticRef; use crate::core::module::ModuleRef;
use crate::core::theme::all::THEMES; use crate::core::theme::all::THEMES;
use crate::{service, trace, LazyStatic}; use crate::{service, trace, LazyStatic};
@ -10,22 +10,22 @@ use std::sync::RwLock;
// MODULES ***************************************************************************************** // MODULES *****************************************************************************************
static ENABLED_MODULES: LazyStatic<RwLock<Vec<ModuleStaticRef>>> = static ENABLED_MODULES: LazyStatic<RwLock<Vec<ModuleRef>>> =
LazyStatic::new(|| RwLock::new(Vec::new())); LazyStatic::new(|| RwLock::new(Vec::new()));
static DROPPED_MODULES: LazyStatic<RwLock<Vec<ModuleStaticRef>>> = static DROPPED_MODULES: LazyStatic<RwLock<Vec<ModuleRef>>> =
LazyStatic::new(|| RwLock::new(Vec::new())); LazyStatic::new(|| RwLock::new(Vec::new()));
// REGISTER MODULES ******************************************************************************** // REGISTER MODULES ********************************************************************************
pub fn register_modules(app: ModuleStaticRef) { pub fn register_modules(app: ModuleRef) {
// List of modules to drop. // List of modules to drop.
let mut list: Vec<ModuleStaticRef> = Vec::new(); let mut list: Vec<ModuleRef> = Vec::new();
add_to_dropped(&mut list, app); add_to_dropped(&mut list, app);
DROPPED_MODULES.write().unwrap().append(&mut list); DROPPED_MODULES.write().unwrap().append(&mut list);
// List of modules to enable. // List of modules to enable.
let mut list: Vec<ModuleStaticRef> = Vec::new(); let mut list: Vec<ModuleRef> = Vec::new();
// Enable basic theme. // Enable basic theme.
add_to_enabled(&mut list, &crate::core::theme::Basic); add_to_enabled(&mut list, &crate::core::theme::Basic);
@ -37,7 +37,7 @@ pub fn register_modules(app: ModuleStaticRef) {
ENABLED_MODULES.write().unwrap().append(&mut list); ENABLED_MODULES.write().unwrap().append(&mut list);
} }
fn add_to_dropped(list: &mut Vec<ModuleStaticRef>, module: ModuleStaticRef) { fn add_to_dropped(list: &mut Vec<ModuleRef>, module: ModuleRef) {
for d in module.drop_modules().iter() { for d in module.drop_modules().iter() {
if !list.iter().any(|m| m.handle() == d.handle()) { if !list.iter().any(|m| m.handle() == d.handle()) {
list.push(*d); list.push(*d);
@ -49,7 +49,7 @@ fn add_to_dropped(list: &mut Vec<ModuleStaticRef>, module: ModuleStaticRef) {
} }
} }
fn add_to_enabled(list: &mut Vec<ModuleStaticRef>, module: ModuleStaticRef) { fn add_to_enabled(list: &mut Vec<ModuleRef>, module: ModuleRef) {
if !list.iter().any(|m| m.handle() == module.handle()) { if !list.iter().any(|m| m.handle() == module.handle()) {
if DROPPED_MODULES if DROPPED_MODULES
.read() .read()

View file

@ -1,12 +1,12 @@
use crate::core::action::Action; use crate::core::action::Action;
use crate::core::component::l10n::L10n; use crate::core::component::l10n::L10n;
use crate::core::theme::ThemeStaticRef; use crate::core::theme::ThemeRef;
use crate::{service, util, Handle}; use crate::{service, util, Handle};
#[cfg(feature = "database")] #[cfg(feature = "database")]
use crate::db::MigrationItem; use crate::db::MigrationItem;
pub type ModuleStaticRef = &'static dyn ModuleTrait; pub type ModuleRef = &'static dyn ModuleTrait;
pub trait ModuleBase { pub trait ModuleBase {
fn single_name(&self) -> &'static str; fn single_name(&self) -> &'static str;
@ -24,15 +24,15 @@ pub trait ModuleTrait: ModuleBase + Send + Sync {
L10n::default() L10n::default()
} }
fn theme(&self) -> Option<ThemeStaticRef> { fn theme(&self) -> Option<ThemeRef> {
None None
} }
fn dependencies(&self) -> Vec<ModuleStaticRef> { fn dependencies(&self) -> Vec<ModuleRef> {
vec![] vec![]
} }
fn drop_modules(&self) -> Vec<ModuleStaticRef> { fn drop_modules(&self) -> Vec<ModuleRef> {
vec![] vec![]
} }

View file

@ -1,5 +1,5 @@
mod definition; mod definition;
pub use definition::{ThemeStaticRef, ThemeTrait}; pub use definition::{ThemeRef, ThemeTrait};
mod regions; mod regions;
pub use regions::add_component_to; pub use regions::add_component_to;

View file

@ -1,17 +1,16 @@
use crate::config; use crate::config;
use crate::core::theme::ThemeStaticRef; use crate::core::theme::ThemeRef;
use crate::LazyStatic; use crate::LazyStatic;
use std::sync::RwLock; use std::sync::RwLock;
// THEMES ****************************************************************************************** // THEMES ******************************************************************************************
pub static THEMES: LazyStatic<RwLock<Vec<ThemeStaticRef>>> = pub static THEMES: LazyStatic<RwLock<Vec<ThemeRef>>> = LazyStatic::new(|| RwLock::new(Vec::new()));
LazyStatic::new(|| RwLock::new(Vec::new()));
// DEFAULT THEME *********************************************************************************** // DEFAULT THEME ***********************************************************************************
pub static THEME: LazyStatic<ThemeStaticRef> = pub static THEME: LazyStatic<ThemeRef> =
LazyStatic::new(|| match theme_by_single_name(&config::SETTINGS.app.theme) { LazyStatic::new(|| match theme_by_single_name(&config::SETTINGS.app.theme) {
Some(theme) => theme, Some(theme) => theme,
None => &crate::core::theme::Basic, None => &crate::core::theme::Basic,
@ -19,7 +18,7 @@ pub static THEME: LazyStatic<ThemeStaticRef> =
// THEME BY NAME *********************************************************************************** // THEME BY NAME ***********************************************************************************
pub fn theme_by_single_name(single_name: &str) -> Option<ThemeStaticRef> { pub fn theme_by_single_name(single_name: &str) -> Option<ThemeRef> {
let single_name = single_name.to_lowercase(); let single_name = single_name.to_lowercase();
match THEMES match THEMES
.read() .read()

View file

@ -1,6 +1,6 @@
use crate::core::component::ContextOp; use crate::core::component::ContextOp;
use crate::core::module::ModuleTrait; use crate::core::module::ModuleTrait;
use crate::core::theme::{ThemeStaticRef, ThemeTrait}; use crate::core::theme::{ThemeRef, ThemeTrait};
use crate::html::{Favicon, StyleSheet}; use crate::html::{Favicon, StyleSheet};
use crate::response::page::Page; use crate::response::page::Page;
use crate::service; use crate::service;
@ -17,7 +17,7 @@ impl ModuleTrait for Basic {
THEME_BASIC THEME_BASIC
} }
fn theme(&self) -> Option<ThemeStaticRef> { fn theme(&self) -> Option<ThemeRef> {
Some(&Basic) Some(&Basic)
} }

View file

@ -5,7 +5,7 @@ use crate::html::{html, Favicon, Markup};
use crate::response::page::Page; use crate::response::page::Page;
use crate::{config, LOCALES_PAGETOP}; use crate::{config, LOCALES_PAGETOP};
pub type ThemeStaticRef = &'static dyn ThemeTrait; pub type ThemeRef = &'static dyn ThemeTrait;
/// Los temas deben implementar este "trait". /// Los temas deben implementar este "trait".
pub trait ThemeTrait: ModuleTrait + Send + Sync { pub trait ThemeTrait: ModuleTrait + Send + Sync {