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")
|
.with_title("Admin")
|
||||||
.add_to("top-menu", top_menu)
|
.add_to("top-menu", top_menu)
|
||||||
.add_to(
|
.add_to(
|
||||||
"content",
|
"region-content",
|
||||||
grid::Row::new()
|
grid::Row::new()
|
||||||
.with_column(grid::Column::new().with_component(side_menu))
|
.with_column(grid::Column::new().with_component(side_menu))
|
||||||
.with_column(grid::Column::new().with_component(Html::with(html! {
|
.with_column(grid::Column::new().with_component(Html::with(html! {
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ async fn login() -> ResultPage<Markup, FatalError> {
|
||||||
Page::new()
|
Page::new()
|
||||||
.with_title("Identificación del usuario")
|
.with_title("Identificación del usuario")
|
||||||
.add_to(
|
.add_to(
|
||||||
"content",
|
"region-content",
|
||||||
Container::new()
|
Container::new()
|
||||||
.with_id("welcome")
|
.with_id("welcome")
|
||||||
.with_component(form_login()),
|
.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;
|
mod banner;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,37 +6,30 @@ use std::fmt;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum FatalError {
|
pub enum FatalError {
|
||||||
NotFound,
|
NotModified,
|
||||||
|
BadRequest,
|
||||||
AccessDenied,
|
AccessDenied,
|
||||||
|
NotFound,
|
||||||
|
PreconditionFailed,
|
||||||
InternalError,
|
InternalError,
|
||||||
BadClientData,
|
|
||||||
Timeout,
|
Timeout,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for FatalError {
|
impl fmt::Display for FatalError {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match *self {
|
match *self {
|
||||||
FatalError::NotFound => {
|
// Error 304.
|
||||||
let mut error_page = Page::new();
|
FatalError::NotModified => write!(f, "Not Modified"),
|
||||||
let error_content = error_page.context().theme().error_404_not_found();
|
// Error 400.
|
||||||
if let Ok(page) = error_page
|
FatalError::BadRequest => write!(f, "Bad Client Data"),
|
||||||
.with_title("Error RESOURCE NOT FOUND")
|
// Error 403.
|
||||||
.using_template("error")
|
|
||||||
.add_to("content", error_content)
|
|
||||||
.render()
|
|
||||||
{
|
|
||||||
write!(f, "{}", page.into_string())
|
|
||||||
} else {
|
|
||||||
write!(f, "Not Found")
|
|
||||||
}
|
|
||||||
},
|
|
||||||
FatalError::AccessDenied => {
|
FatalError::AccessDenied => {
|
||||||
let mut error_page = Page::new();
|
let mut error_page = Page::new();
|
||||||
let error_content = error_page.context().theme().error_403_access_denied();
|
let error_content = error_page.context().theme().error_403_access_denied();
|
||||||
if let Ok(page) = error_page
|
if let Ok(page) = error_page
|
||||||
.with_title("Error FORBIDDEN")
|
.with_title("Error FORBIDDEN")
|
||||||
.using_template("error")
|
.using_template("error")
|
||||||
.add_to("content", error_content)
|
.add_to("region-content", error_content)
|
||||||
.render()
|
.render()
|
||||||
{
|
{
|
||||||
write!(f, "{}", page.into_string())
|
write!(f, "{}", page.into_string())
|
||||||
|
|
@ -44,9 +37,27 @@ impl fmt::Display for FatalError {
|
||||||
write!(f, "Access Denied")
|
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::InternalError => write!(f, "Internal Error"),
|
||||||
FatalError::BadClientData => write!(f, "Bad Client Data"),
|
// Error 504.
|
||||||
FatalError::Timeout => write!(f, "Timeout"),
|
FatalError::Timeout => write!(f, "Timeout"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -60,11 +71,13 @@ impl ResponseError for FatalError {
|
||||||
|
|
||||||
fn status_code(&self) -> StatusCode {
|
fn status_code(&self) -> StatusCode {
|
||||||
match *self {
|
match *self {
|
||||||
FatalError::NotFound => StatusCode::NOT_FOUND,
|
FatalError::NotModified => StatusCode::NOT_MODIFIED,
|
||||||
FatalError::AccessDenied => StatusCode::FORBIDDEN,
|
FatalError::BadRequest => StatusCode::BAD_REQUEST,
|
||||||
FatalError::InternalError => StatusCode::INTERNAL_SERVER_ERROR,
|
FatalError::AccessDenied => StatusCode::FORBIDDEN,
|
||||||
FatalError::BadClientData => StatusCode::BAD_REQUEST,
|
FatalError::NotFound => StatusCode::NOT_FOUND,
|
||||||
FatalError::Timeout => StatusCode::GATEWAY_TIMEOUT,
|
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(
|
.with_context(InContextOp::StyleSheet(AssetsOp::Add(StyleSheet::located(
|
||||||
"/theme/module/homepage/styles.css",
|
"/theme/module/homepage/styles.css",
|
||||||
))))
|
))))
|
||||||
.add_to("content", hello_world())
|
.add_to("region-content", hello_world())
|
||||||
.add_to("content", welcome())
|
.add_to("region-content", welcome())
|
||||||
.add_to("content", about_pagetop())
|
.add_to("region-content", about_pagetop())
|
||||||
.add_to("content", promo_pagetop())
|
.add_to("region-content", promo_pagetop())
|
||||||
.add_to("content", reporting_problems())
|
.add_to("region-content", reporting_problems())
|
||||||
.render()
|
.render()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -63,16 +63,12 @@ pub trait ThemeTrait: BaseTheme + Send + Sync {
|
||||||
body class=[page.body_classes().get()] {
|
body class=[page.body_classes().get()] {
|
||||||
@match page.template() {
|
@match page.template() {
|
||||||
"admin" => {
|
"admin" => {
|
||||||
@for region in &["top-menu", "side-menu", "content"] {
|
(page.render_region("top-menu"))
|
||||||
#(region) {
|
(page.render_region("side-menu"))
|
||||||
(page.render_region(region))
|
(page.render_region("region-content"))
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
#content {
|
(page.render_region("region-content"))
|
||||||
(page.render_region("content"))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ pub use maud::{html, Markup, PreEscaped, DOCTYPE};
|
||||||
|
|
||||||
mod assets;
|
mod assets;
|
||||||
pub use assets::javascript::{JSMode, JavaScript};
|
pub use assets::javascript::{JSMode, JavaScript};
|
||||||
pub use assets::stylesheet::StyleSheet;
|
pub use assets::stylesheet::{StyleSheet, TargetMedia};
|
||||||
pub use assets::{Assets, AssetsOp, SourceValue};
|
pub use assets::{Assets, AssetsOp, SourceValue};
|
||||||
|
|
||||||
mod favicon;
|
mod favicon;
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,13 @@
|
||||||
use super::{AssetsTrait, SourceValue};
|
use super::{AssetsTrait, SourceValue};
|
||||||
use crate::html::{html, Markup};
|
use crate::html::{html, Markup};
|
||||||
|
|
||||||
|
pub enum TargetMedia {Default, Print, Screen, Speech}
|
||||||
|
|
||||||
pub struct StyleSheet {
|
pub struct StyleSheet {
|
||||||
source : SourceValue,
|
source : SourceValue,
|
||||||
prefix : &'static str,
|
prefix : &'static str,
|
||||||
version: &'static str,
|
version: &'static str,
|
||||||
|
media : Option<&'static str>,
|
||||||
weight : isize,
|
weight : isize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -21,7 +24,8 @@ impl AssetsTrait for StyleSheet {
|
||||||
html! {
|
html! {
|
||||||
link
|
link
|
||||||
rel="stylesheet"
|
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,
|
source,
|
||||||
prefix : "",
|
prefix : "",
|
||||||
version: "",
|
version: "",
|
||||||
|
media : None,
|
||||||
weight : 0,
|
weight : 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -49,4 +54,14 @@ impl StyleSheet {
|
||||||
self.weight = weight;
|
self.weight = weight;
|
||||||
self
|
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;
|
||||||
pub use crate::app::application::Application;
|
pub use crate::app::application::Application;
|
||||||
pub use crate::app::fatal_error::FatalError;
|
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::*};
|
pub use crate::core::{component::*, hook::*, module::*, theme::*};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -219,7 +219,11 @@ impl Page {
|
||||||
|
|
||||||
pub fn render_region(&mut self, region: &str) -> Markup {
|
pub fn render_region(&mut self, region: &str) -> Markup {
|
||||||
match self.regions.get_mut(region) {
|
match self.regions.get_mut(region) {
|
||||||
Some(components) => components.render(&mut self.context),
|
Some(components) => html! {
|
||||||
|
#(region) {
|
||||||
|
(components.render(&mut self.context))
|
||||||
|
}
|
||||||
|
},
|
||||||
None => html! {},
|
None => html! {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,10 +23,13 @@ macro_rules! theme_static_files {
|
||||||
( $cfg:ident, $dir:expr ) => {{
|
( $cfg:ident, $dir:expr ) => {{
|
||||||
let static_files = &$crate::config::SETTINGS.dev.static_files;
|
let static_files = &$crate::config::SETTINGS.dev.static_files;
|
||||||
if static_files.is_empty() {
|
if static_files.is_empty() {
|
||||||
$cfg.service(actix_web_static_files::ResourceFiles::new($dir, generate()));
|
$cfg.service($crate::app::ResourceFiles::new($dir, generate()));
|
||||||
} else {
|
} else {
|
||||||
$cfg.service(
|
$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