Añade nuevo código para soportar MdBook
This commit is contained in:
parent
a7105d6a63
commit
ae2d54828f
12 changed files with 79 additions and 55 deletions
|
|
@ -1,9 +0,0 @@
|
|||
[workspace]
|
||||
members = [
|
||||
"drust",
|
||||
"pagetop",
|
||||
"pagetop-admin",
|
||||
"pagetop-user",
|
||||
"pagetop-node",
|
||||
"website",
|
||||
]
|
||||
|
|
@ -45,7 +45,7 @@ pub async fn summary() -> ResultPage<Markup, FatalError> {
|
|||
.with_title("Admin")
|
||||
.add_to("top-menu", top_menu)
|
||||
.add_to(
|
||||
"content",
|
||||
"region-content",
|
||||
grid::Row::new()
|
||||
.with_column(grid::Column::new().with_component(side_menu))
|
||||
.with_column(grid::Column::new().with_component(Html::with(html! {
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ async fn login() -> ResultPage<Markup, FatalError> {
|
|||
Page::new()
|
||||
.with_title("Identificación del usuario")
|
||||
.add_to(
|
||||
"content",
|
||||
"region-content",
|
||||
Container::new()
|
||||
.with_id("welcome")
|
||||
.with_component(form_login()),
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
pub use actix_web::{http, web, App, HttpRequest, HttpResponse, HttpServer, Responder};
|
||||
pub use actix_web::{http, web, App, HttpMessage, HttpRequest, HttpResponse, HttpServer, Responder};
|
||||
pub use actix_web_static_files::ResourceFiles;
|
||||
pub use actix_files::Files as ActixFiles;
|
||||
|
||||
mod banner;
|
||||
|
||||
|
|
|
|||
|
|
@ -6,37 +6,30 @@ use std::fmt;
|
|||
|
||||
#[derive(Debug)]
|
||||
pub enum FatalError {
|
||||
NotFound,
|
||||
NotModified,
|
||||
BadRequest,
|
||||
AccessDenied,
|
||||
NotFound,
|
||||
PreconditionFailed,
|
||||
InternalError,
|
||||
BadClientData,
|
||||
Timeout,
|
||||
}
|
||||
|
||||
impl fmt::Display for FatalError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match *self {
|
||||
FatalError::NotFound => {
|
||||
let mut error_page = Page::new();
|
||||
let error_content = error_page.context().theme().error_404_not_found();
|
||||
if let Ok(page) = error_page
|
||||
.with_title("Error RESOURCE NOT FOUND")
|
||||
.using_template("error")
|
||||
.add_to("content", error_content)
|
||||
.render()
|
||||
{
|
||||
write!(f, "{}", page.into_string())
|
||||
} else {
|
||||
write!(f, "Not Found")
|
||||
}
|
||||
},
|
||||
// Error 304.
|
||||
FatalError::NotModified => write!(f, "Not Modified"),
|
||||
// Error 400.
|
||||
FatalError::BadRequest => write!(f, "Bad Client Data"),
|
||||
// Error 403.
|
||||
FatalError::AccessDenied => {
|
||||
let mut error_page = Page::new();
|
||||
let error_content = error_page.context().theme().error_403_access_denied();
|
||||
if let Ok(page) = error_page
|
||||
.with_title("Error FORBIDDEN")
|
||||
.using_template("error")
|
||||
.add_to("content", error_content)
|
||||
.add_to("region-content", error_content)
|
||||
.render()
|
||||
{
|
||||
write!(f, "{}", page.into_string())
|
||||
|
|
@ -44,9 +37,27 @@ impl fmt::Display for FatalError {
|
|||
write!(f, "Access Denied")
|
||||
}
|
||||
},
|
||||
// Error 404.
|
||||
FatalError::NotFound => {
|
||||
let mut error_page = Page::new();
|
||||
let error_content = error_page.context().theme().error_404_not_found();
|
||||
if let Ok(page) = error_page
|
||||
.with_title("Error RESOURCE NOT FOUND")
|
||||
.using_template("error")
|
||||
.add_to("region-content", error_content)
|
||||
.render()
|
||||
{
|
||||
write!(f, "{}", page.into_string())
|
||||
} else {
|
||||
write!(f, "Not Found")
|
||||
}
|
||||
},
|
||||
// Error 412.
|
||||
FatalError::PreconditionFailed => write!(f, "Precondition Failed"),
|
||||
// Error 500.
|
||||
FatalError::InternalError => write!(f, "Internal Error"),
|
||||
FatalError::BadClientData => write!(f, "Bad Client Data"),
|
||||
FatalError::Timeout => write!(f, "Timeout"),
|
||||
// Error 504.
|
||||
FatalError::Timeout => write!(f, "Timeout"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -60,11 +71,13 @@ impl ResponseError for FatalError {
|
|||
|
||||
fn status_code(&self) -> StatusCode {
|
||||
match *self {
|
||||
FatalError::NotFound => StatusCode::NOT_FOUND,
|
||||
FatalError::AccessDenied => StatusCode::FORBIDDEN,
|
||||
FatalError::InternalError => StatusCode::INTERNAL_SERVER_ERROR,
|
||||
FatalError::BadClientData => StatusCode::BAD_REQUEST,
|
||||
FatalError::Timeout => StatusCode::GATEWAY_TIMEOUT,
|
||||
FatalError::NotModified => StatusCode::NOT_MODIFIED,
|
||||
FatalError::BadRequest => StatusCode::BAD_REQUEST,
|
||||
FatalError::AccessDenied => StatusCode::FORBIDDEN,
|
||||
FatalError::NotFound => StatusCode::NOT_FOUND,
|
||||
FatalError::PreconditionFailed => StatusCode::PRECONDITION_FAILED,
|
||||
FatalError::InternalError => StatusCode::INTERNAL_SERVER_ERROR,
|
||||
FatalError::Timeout => StatusCode::GATEWAY_TIMEOUT,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,11 +30,11 @@ async fn demo() -> ResultPage<Markup, FatalError> {
|
|||
.with_context(InContextOp::StyleSheet(AssetsOp::Add(StyleSheet::located(
|
||||
"/theme/module/homepage/styles.css",
|
||||
))))
|
||||
.add_to("content", hello_world())
|
||||
.add_to("content", welcome())
|
||||
.add_to("content", about_pagetop())
|
||||
.add_to("content", promo_pagetop())
|
||||
.add_to("content", reporting_problems())
|
||||
.add_to("region-content", hello_world())
|
||||
.add_to("region-content", welcome())
|
||||
.add_to("region-content", about_pagetop())
|
||||
.add_to("region-content", promo_pagetop())
|
||||
.add_to("region-content", reporting_problems())
|
||||
.render()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -63,16 +63,12 @@ pub trait ThemeTrait: BaseTheme + Send + Sync {
|
|||
body class=[page.body_classes().get()] {
|
||||
@match page.template() {
|
||||
"admin" => {
|
||||
@for region in &["top-menu", "side-menu", "content"] {
|
||||
#(region) {
|
||||
(page.render_region(region))
|
||||
}
|
||||
}
|
||||
(page.render_region("top-menu"))
|
||||
(page.render_region("side-menu"))
|
||||
(page.render_region("region-content"))
|
||||
},
|
||||
_ => {
|
||||
#content {
|
||||
(page.render_region("content"))
|
||||
}
|
||||
(page.render_region("region-content"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ pub use maud::{html, Markup, PreEscaped, DOCTYPE};
|
|||
|
||||
mod assets;
|
||||
pub use assets::javascript::{JSMode, JavaScript};
|
||||
pub use assets::stylesheet::StyleSheet;
|
||||
pub use assets::stylesheet::{StyleSheet, TargetMedia};
|
||||
pub use assets::{Assets, AssetsOp, SourceValue};
|
||||
|
||||
mod favicon;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,13 @@
|
|||
use super::{AssetsTrait, SourceValue};
|
||||
use crate::html::{html, Markup};
|
||||
|
||||
pub enum TargetMedia {Default, Print, Screen, Speech}
|
||||
|
||||
pub struct StyleSheet {
|
||||
source : SourceValue,
|
||||
prefix : &'static str,
|
||||
version: &'static str,
|
||||
media : Option<&'static str>,
|
||||
weight : isize,
|
||||
}
|
||||
|
||||
|
|
@ -21,7 +24,8 @@ impl AssetsTrait for StyleSheet {
|
|||
html! {
|
||||
link
|
||||
rel="stylesheet"
|
||||
href=(crate::concat_string!(self.source, self.prefix, self.version));
|
||||
href=(crate::concat_string!(self.source, self.prefix, self.version))
|
||||
media=[self.media];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -32,6 +36,7 @@ impl StyleSheet {
|
|||
source,
|
||||
prefix : "",
|
||||
version: "",
|
||||
media : None,
|
||||
weight : 0,
|
||||
}
|
||||
}
|
||||
|
|
@ -49,4 +54,14 @@ impl StyleSheet {
|
|||
self.weight = weight;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn for_media(mut self, media: TargetMedia) -> Self {
|
||||
self.media = match media {
|
||||
TargetMedia::Print => Some("print"),
|
||||
TargetMedia::Screen => Some("screen"),
|
||||
TargetMedia::Speech => Some("speech"),
|
||||
_ => None,
|
||||
};
|
||||
self
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ pub use crate::{db, db::*, migration_item, pub_migration};
|
|||
pub use crate::app;
|
||||
pub use crate::app::application::Application;
|
||||
pub use crate::app::fatal_error::FatalError;
|
||||
pub use crate::app::AppTrait;
|
||||
pub use crate::app::{AppTrait, HttpMessage};
|
||||
|
||||
pub use crate::core::{component::*, hook::*, module::*, theme::*};
|
||||
|
||||
|
|
|
|||
|
|
@ -219,7 +219,11 @@ impl Page {
|
|||
|
||||
pub fn render_region(&mut self, region: &str) -> Markup {
|
||||
match self.regions.get_mut(region) {
|
||||
Some(components) => components.render(&mut self.context),
|
||||
Some(components) => html! {
|
||||
#(region) {
|
||||
(components.render(&mut self.context))
|
||||
}
|
||||
},
|
||||
None => html! {},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,10 +23,13 @@ macro_rules! theme_static_files {
|
|||
( $cfg:ident, $dir:expr ) => {{
|
||||
let static_files = &$crate::config::SETTINGS.dev.static_files;
|
||||
if static_files.is_empty() {
|
||||
$cfg.service(actix_web_static_files::ResourceFiles::new($dir, generate()));
|
||||
$cfg.service($crate::app::ResourceFiles::new($dir, generate()));
|
||||
} else {
|
||||
$cfg.service(
|
||||
actix_files::Files::new($dir, &[static_files, $dir].join("")).show_files_listing(),
|
||||
$crate::app::ActixFiles::new(
|
||||
$dir, $crate::concat_string!(static_files, $dir)
|
||||
)
|
||||
.show_files_listing(),
|
||||
);
|
||||
}
|
||||
}};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue