Actualiza y simplifica la estructura del código

Revisión general del código fuente para asegurar los elementos que deben
ser públicos y estandarizar el uso de funciones globales.
This commit is contained in:
Manuel Cillero 2022-03-02 23:19:16 +01:00
parent 67952f6840
commit b6dd473578
34 changed files with 250 additions and 237 deletions

View file

@ -1,5 +1,5 @@
use crate::config::SETTINGS;
use crate::core::{all, server};
use crate::core::server;
use crate::core::theme::{Markup, html};
use crate::core::response::page::{Page, PageAssets, PageComponent};
use crate::base::component::Chunck;
@ -10,8 +10,8 @@ pub trait Theme: Send + Sync {
fn fullname(&self) -> String;
fn description(&self) -> String {
"".to_string()
fn description(&self) -> Option<String> {
None
}
#[allow(unused_variables)]
@ -25,7 +25,7 @@ pub trait Theme: Send + Sync {
fn render_page_head(&self, page: &mut Page) -> Markup {
let title = page.title();
let title = if title.is_empty() {
SETTINGS.app.name.to_string()
SETTINGS.app.name.to_owned()
} else {
[SETTINGS.app.name.to_string(), title.to_string()].join(" | ")
};
@ -104,15 +104,3 @@ pub trait Theme: Send + Sync {
.render()
}
}
pub fn register_theme(t: &'static (dyn Theme + 'static)) {
all::THEMES.write().unwrap().push(t);
}
pub fn find_theme(name: &str) -> Option<&'static (dyn Theme + 'static)> {
let themes = all::THEMES.write().unwrap();
match themes.iter().find(|t| t.name() == name) {
Some(theme) => Some(*theme),
_ => None,
}
}

View file

@ -1,4 +1,18 @@
use crate::core::global;
pub use maud::{DOCTYPE, Markup, PreEscaped, html};
mod api;
pub use api::{Theme, find_theme, register_theme};
mod definition;
pub use definition::Theme;
pub fn register_theme(t: &'static (dyn Theme + 'static)) {
global::THEMES.write().unwrap().push(t);
}
pub fn find_theme(name: &str) -> Option<&'static (dyn Theme + 'static)> {
let themes = global::THEMES.write().unwrap();
match themes.iter().find(|t| t.name() == name) {
Some(theme) => Some(*theme),
_ => None,
}
}