Añade soporte nativo a Bootstrap con un nuevo tema

This commit is contained in:
Manuel Cillero 2022-02-21 00:28:22 +01:00
parent d38df3a5b6
commit 7f8b94eafe
37 changed files with 652 additions and 6 deletions

View file

@ -176,6 +176,7 @@ pub struct Assets {
metadata : Vec<(String, String)>,
stylesheets: Vec<StyleSheet>,
javascripts: Vec<JavaScript>,
with_jquery: bool,
seqid_count: u16,
}
@ -186,6 +187,7 @@ impl Assets {
metadata : Vec::new(),
stylesheets: Vec::new(),
javascripts: Vec::new(),
with_jquery: false,
seqid_count: 0,
}
}
@ -222,6 +224,20 @@ impl Assets {
self
}
pub fn add_jquery(&mut self) -> &mut Self {
if !self.with_jquery {
self.add_javascript(
JavaScript::source(
"/assets/js/jquery.min.js?ver=3.6.0"
)
.with_weight(i8::MIN)
.with_mode(JSMode::Normal)
);
self.with_jquery = true;
}
self
}
pub fn render(&mut self) -> Markup {
let ordered_css = &mut self.stylesheets;
ordered_css.sort_by_key(|o| o.weight);

View file

@ -1,5 +1,5 @@
pub use actix_web::{
App, HttpRequest, HttpResponse, HttpServer, Responder, Result, web
App, HttpRequest, HttpResponse, HttpServer, Responder, Result, http, web
};
mod main;

View file

@ -14,7 +14,9 @@ use std::collections::HashMap;
pub static THEMES: Lazy<RwLock<Vec<&dyn Theme>>> = Lazy::new(|| {
RwLock::new(vec![
&base::theme::aliner::AlinerTheme,
&base::theme::minimal::MinimalTheme,
&base::theme::bootsier::BootsierTheme,
])
});
@ -24,7 +26,7 @@ pub static THEME: Lazy<&dyn Theme> = Lazy::new(|| {
return *t;
}
}
&base::theme::minimal::MinimalTheme
&base::theme::bootsier::BootsierTheme
});
pub fn register_theme(t: &'static (dyn Theme + 'static)) {

View file

@ -1,6 +1,7 @@
use crate::core::server;
use crate::core::theme::{Markup, html};
use crate::core::response::page::{Page, PageAssets, PageComponent};
use crate::base::component::Chunck;
/// Los temas deben implementar este "trait".
pub trait Theme: Send + Sync {
@ -81,4 +82,15 @@ pub trait Theme: Send + Sync {
}
*/
}
fn render_error_page(&self, s: server::http::StatusCode) -> server::Result<Markup> {
Page::prepare()
.with_title(format!("Error {}", s.as_str()).as_str())
.add_to("content", Chunck::markup(html! {
div {
h1 { (s) }
}
}))
.render()
}
}