Añade elección de tema específico por página

Característica útil para facilitar que el módulo Admin pueda renderizar
sus páginas siempre con el mismo tema, indepedientemente del tema por
defecto. También podrá ser decisivo para permitir a los usuarios usar un
tema diferente.
This commit is contained in:
Manuel Cillero 2022-02-26 21:15:00 +01:00
parent edf5ddf81b
commit 3764f707da
11 changed files with 127 additions and 86 deletions

View file

@ -1,4 +1,5 @@
use crate::core::theme::{Markup, PreEscaped, html};
use crate::core::all::DEFAULT_THEME;
use crate::core::theme::{Markup, PreEscaped, Theme, html};
// -----------------------------------------------------------------------------
// Favicon.
@ -172,6 +173,7 @@ impl JavaScript {
// -----------------------------------------------------------------------------
pub struct Assets {
theme : &'static dyn Theme,
favicon : Option<Favicon>,
metadata : Vec<(String, String)>,
stylesheets: Vec<StyleSheet>,
@ -183,6 +185,7 @@ pub struct Assets {
impl Assets {
pub fn new() -> Self {
Assets {
theme : *DEFAULT_THEME,
favicon : None,
metadata : Vec::new(),
stylesheets: Vec::new(),
@ -192,6 +195,11 @@ impl Assets {
}
}
pub fn using_theme(&mut self, theme: &'static dyn Theme) -> &mut Self {
self.theme = theme;
self
}
pub fn with_favicon(&mut self, favicon: Favicon) -> &mut Self {
self.favicon = Some(favicon);
self
@ -238,6 +246,14 @@ impl Assets {
self
}
/// Assets GETTERS.
pub fn theme(&mut self) -> &'static dyn Theme {
self.theme
}
/// Assets RENDER.
pub fn render(&mut self) -> Markup {
let ordered_css = &mut self.stylesheets;
ordered_css.sort_by_key(|o| o.weight);