♻️ Diferencia módulos y temas

This commit is contained in:
Manuel Cillero 2023-06-06 21:03:41 +02:00
parent 163302f4ea
commit 772546c164
10 changed files with 40 additions and 29 deletions

View file

@ -6,8 +6,11 @@ pub mod action;
// API to build new components.
pub mod component;
// API to add new features with modules and themes.
// API to add new features with modules.
pub mod module;
// API to add new layouts with themes.
pub mod theme;
// Basic theme.
pub(crate) mod basic;

View file

@ -1,4 +1,5 @@
use crate::core::module::{ModuleTrait, ThemeStaticRef, ThemeTrait};
use crate::core::module::ModuleTrait;
use crate::core::theme::{ThemeStaticRef, ThemeTrait};
use crate::html::Favicon;
use crate::response::page::Page;
use crate::{define_handle, serve_static_files, server, Handle};

View file

@ -1,4 +1,4 @@
use crate::core::module::{all::theme_by_single_name, ThemeStaticRef};
use crate::core::theme::{all::theme_by_single_name, ThemeStaticRef};
use crate::html::{html, Assets, IdentifierValue, JavaScript, Markup, StyleSheet};
use crate::locale::{LanguageIdentifier, LANGID};
use crate::server::HttpRequest;

View file

@ -1,7 +1,4 @@
mod definition;
pub use definition::{BaseModule, ModuleStaticRef, ModuleTrait, MODULE_UNNAMED};
mod theme;
pub use theme::{ThemeStaticRef, ThemeTrait};
pub(crate) mod all;

View file

@ -1,5 +1,6 @@
use crate::core::action::add_action;
use crate::core::module::{ModuleStaticRef, ThemeStaticRef};
use crate::core::module::ModuleStaticRef;
use crate::core::theme::all::THEMES;
use crate::{server, trace, LazyStatic};
#[cfg(feature = "database")]
@ -15,24 +16,6 @@ static ENABLED_MODULES: LazyStatic<RwLock<Vec<ModuleStaticRef>>> =
static DROPPED_MODULES: LazyStatic<RwLock<Vec<ModuleStaticRef>>> =
LazyStatic::new(|| RwLock::new(Vec::new()));
// THEMES ******************************************************************************************
static THEMES: LazyStatic<RwLock<Vec<ThemeStaticRef>>> =
LazyStatic::new(|| RwLock::new(Vec::new()));
pub fn theme_by_single_name(single_name: &str) -> Option<ThemeStaticRef> {
let single_name = single_name.to_lowercase();
match THEMES
.read()
.unwrap()
.iter()
.find(|t| t.single_name().to_lowercase() == single_name)
{
Some(theme) => Some(*theme),
_ => None,
}
}
// REGISTER MODULES ********************************************************************************
pub fn register_modules(app: ModuleStaticRef) {

View file

@ -1,6 +1,6 @@
use crate::core::action::Action;
use crate::core::component::L10n;
use crate::core::module::ThemeStaticRef;
use crate::core::theme::ThemeStaticRef;
use crate::util::single_type_name;
use crate::{define_handle, server, Handle};

View file

@ -0,0 +1,4 @@
mod definition;
pub use definition::{ThemeStaticRef, ThemeTrait};
pub(crate) mod all;

View file

@ -0,0 +1,24 @@
use crate::core::theme::ThemeStaticRef;
use crate::LazyStatic;
use std::sync::RwLock;
// THEMES ******************************************************************************************
pub static THEMES: LazyStatic<RwLock<Vec<ThemeStaticRef>>> =
LazyStatic::new(|| RwLock::new(Vec::new()));
// THEME BY NAME ***********************************************************************************
pub fn theme_by_single_name(single_name: &str) -> Option<ThemeStaticRef> {
let single_name = single_name.to_lowercase();
match THEMES
.read()
.unwrap()
.iter()
.find(|t| t.single_name().to_lowercase() == single_name)
{
Some(theme) => Some(*theme),
_ => None,
}
}

View file

@ -1,8 +1,7 @@
use super::ModuleTrait;
use crate::app::LOCALE_PAGETOP;
use crate::config;
use crate::core::component::{ComponentTrait, L10n, RenderContext};
use crate::core::module::ModuleTrait;
use crate::html::{html, Favicon, Markup};
use crate::response::page::Page;

View file

@ -23,7 +23,7 @@ pub use crate::html::*;
#[cfg(feature = "database")]
pub use crate::{db, db::*, migration_item, pub_migration};
pub use crate::core::{action::*, component::*, module::*};
pub use crate::core::{action::*, component::*, module::*, theme::*};
pub use crate::{action, action_before_render_component};