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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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