diff --git a/pagetop/src/core.rs b/pagetop/src/core.rs index 007bc9be..fa45c442 100644 --- a/pagetop/src/core.rs +++ b/pagetop/src/core.rs @@ -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; diff --git a/pagetop/src/core/basic.rs b/pagetop/src/core/basic.rs index d88e174a..e2ce7b3a 100644 --- a/pagetop/src/core/basic.rs +++ b/pagetop/src/core/basic.rs @@ -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}; diff --git a/pagetop/src/core/component/context.rs b/pagetop/src/core/component/context.rs index b6311bec..4eec5377 100644 --- a/pagetop/src/core/component/context.rs +++ b/pagetop/src/core/component/context.rs @@ -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; diff --git a/pagetop/src/core/module.rs b/pagetop/src/core/module.rs index 6266ddd8..31e857e6 100644 --- a/pagetop/src/core/module.rs +++ b/pagetop/src/core/module.rs @@ -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; diff --git a/pagetop/src/core/module/all.rs b/pagetop/src/core/module/all.rs index 01847819..ee4dd019 100644 --- a/pagetop/src/core/module/all.rs +++ b/pagetop/src/core/module/all.rs @@ -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>> = static DROPPED_MODULES: LazyStatic>> = LazyStatic::new(|| RwLock::new(Vec::new())); -// THEMES ****************************************************************************************** - -static THEMES: LazyStatic>> = - LazyStatic::new(|| RwLock::new(Vec::new())); - -pub fn theme_by_single_name(single_name: &str) -> Option { - 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) { diff --git a/pagetop/src/core/module/definition.rs b/pagetop/src/core/module/definition.rs index 6277df2e..c071cf1b 100644 --- a/pagetop/src/core/module/definition.rs +++ b/pagetop/src/core/module/definition.rs @@ -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}; diff --git a/pagetop/src/core/theme.rs b/pagetop/src/core/theme.rs new file mode 100644 index 00000000..67902dcb --- /dev/null +++ b/pagetop/src/core/theme.rs @@ -0,0 +1,4 @@ +mod definition; +pub use definition::{ThemeStaticRef, ThemeTrait}; + +pub(crate) mod all; diff --git a/pagetop/src/core/theme/all.rs b/pagetop/src/core/theme/all.rs new file mode 100644 index 00000000..ade7ef3e --- /dev/null +++ b/pagetop/src/core/theme/all.rs @@ -0,0 +1,24 @@ +use crate::core::theme::ThemeStaticRef; +use crate::LazyStatic; + +use std::sync::RwLock; + +// THEMES ****************************************************************************************** + +pub static THEMES: LazyStatic>> = + LazyStatic::new(|| RwLock::new(Vec::new())); + +// THEME BY NAME *********************************************************************************** + +pub fn theme_by_single_name(single_name: &str) -> Option { + 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, + } +} diff --git a/pagetop/src/core/module/theme.rs b/pagetop/src/core/theme/definition.rs similarity index 98% rename from pagetop/src/core/module/theme.rs rename to pagetop/src/core/theme/definition.rs index 02b1e94f..29cc8136 100644 --- a/pagetop/src/core/module/theme.rs +++ b/pagetop/src/core/theme/definition.rs @@ -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; diff --git a/pagetop/src/prelude.rs b/pagetop/src/prelude.rs index 24879ecc..10a43058 100644 --- a/pagetop/src/prelude.rs +++ b/pagetop/src/prelude.rs @@ -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};