Modifica la forma de identificar temas y módulos
Cada módulo y cada tema requerirá a partir de ahora un identificador que debería ser único y con alguna sintaxis particular aún por definir (por ejemplo, admitiendo sólo minúsculas y sin espacios).
This commit is contained in:
parent
3764f707da
commit
83fd12b5cc
16 changed files with 65 additions and 30 deletions
|
|
@ -2,6 +2,8 @@ use crate::core::server;
|
|||
|
||||
/// Los módulos deben implementar este *trait*.
|
||||
pub trait Module: Send + Sync {
|
||||
fn id(&self) -> &'static str;
|
||||
|
||||
fn name(&self) -> String;
|
||||
|
||||
fn description(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -7,9 +7,9 @@ pub fn register_module(m: &'static (dyn Module + 'static)) {
|
|||
MODULES.write().unwrap().push(m);
|
||||
}
|
||||
|
||||
pub fn find_module(name: &str) -> Option<&'static (dyn Module + 'static)> {
|
||||
pub fn find_module(id: &str) -> Option<&'static (dyn Module + 'static)> {
|
||||
let modules = MODULES.write().unwrap();
|
||||
match modules.iter().find(|t| t.name() == name) {
|
||||
match modules.iter().find(|t| t.id() == id) {
|
||||
Some(module) => Some(*module),
|
||||
_ => None,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use crate::core::all::DEFAULT_THEME;
|
||||
use crate::core::theme::{Markup, PreEscaped, Theme, html};
|
||||
use crate::core::theme::{Markup, PreEscaped, Theme, find_theme, html};
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Favicon.
|
||||
|
|
@ -195,8 +195,8 @@ impl Assets {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn using_theme(&mut self, theme: &'static dyn Theme) -> &mut Self {
|
||||
self.theme = theme;
|
||||
pub fn using_theme(&mut self, theme_id: &str) -> &mut Self {
|
||||
self.theme = find_theme(theme_id).unwrap_or(*DEFAULT_THEME);
|
||||
self
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use crate::config::SETTINGS;
|
||||
use crate::core::server;
|
||||
use crate::core::all::COMPONENTS;
|
||||
use crate::core::theme::{DOCTYPE, Markup, Theme, html};
|
||||
use crate::core::theme::{DOCTYPE, Markup, html};
|
||||
use crate::core::response::page::{PageAssets, PageComponent, PageContainer};
|
||||
|
||||
use std::borrow::Cow;
|
||||
|
|
@ -159,8 +159,8 @@ impl<'a> Page<'a> {
|
|||
|
||||
// Page EXTRAS.
|
||||
|
||||
pub fn using_theme(&mut self, theme: &'static dyn Theme) -> &mut Self {
|
||||
self.assets.using_theme(theme);
|
||||
pub fn using_theme(&mut self, theme_id: &str) -> &mut Self {
|
||||
self.assets.using_theme(theme_id);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ use crate::base::component::Chunck;
|
|||
|
||||
/// Los temas deben implementar este "trait".
|
||||
pub trait Theme: Send + Sync {
|
||||
fn id(&self) -> &'static str;
|
||||
|
||||
fn name(&self) -> String;
|
||||
|
||||
fn description(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -9,9 +9,9 @@ pub fn register_theme(t: &'static (dyn Theme + 'static)) {
|
|||
THEMES.write().unwrap().push(t);
|
||||
}
|
||||
|
||||
pub fn find_theme(name: &str) -> Option<&'static (dyn Theme + 'static)> {
|
||||
pub fn find_theme(id: &str) -> Option<&'static (dyn Theme + 'static)> {
|
||||
let themes = THEMES.write().unwrap();
|
||||
match themes.iter().find(|t| t.name() == name) {
|
||||
match themes.iter().find(|t| t.id() == id) {
|
||||
Some(theme) => Some(*theme),
|
||||
_ => None,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue