Actualiza formato del código aplicando cargo fmt

This commit is contained in:
Manuel Cillero 2022-07-30 06:56:36 +02:00
parent 31daf11faa
commit 592cd9ccda
42 changed files with 210 additions and 167 deletions

View file

@ -44,7 +44,7 @@ fluent-templates = "0.7.1"
unic-langid = "0.9.0" unic-langid = "0.9.0"
actix-web = "4.1.0" actix-web = "4.1.0"
actix-files = "0.6.1" actix-web-files = { package = "actix-files", version = "0.6.1" }
actix-web-static-files = "4.0.0" actix-web-static-files = "4.0.0"
static-files = "0.2.3" static-files = "0.2.3"

View file

@ -1,6 +1,8 @@
pub use actix_web::{http, web, App, HttpMessage, HttpRequest, HttpResponse, HttpServer, Responder}; pub use actix_web::{
http, web, App, HttpMessage, HttpRequest, HttpResponse, HttpServer, Responder,
};
pub use actix_web_files::Files as ActixFiles;
pub use actix_web_static_files::ResourceFiles; pub use actix_web_static_files::ResourceFiles;
pub use actix_files::Files as ActixFiles;
mod banner; mod banner;
@ -16,4 +18,4 @@ pub use definition::AppTrait;
pub mod application; pub mod application;
pub mod fatal_error; pub mod fatal_error;

View file

@ -1,5 +1,5 @@
use crate::app::HttpResponse;
use crate::app::http::{header::ContentType, StatusCode}; use crate::app::http::{header::ContentType, StatusCode};
use crate::app::HttpResponse;
use crate::response::{page::Page, ResponseError}; use crate::response::{page::Page, ResponseError};
use std::fmt; use std::fmt;
@ -36,7 +36,7 @@ impl fmt::Display for FatalError {
} else { } else {
write!(f, "Access Denied") write!(f, "Access Denied")
} }
}, }
// Error 404. // Error 404.
FatalError::NotFound => { FatalError::NotFound => {
let mut error_page = Page::new(); let mut error_page = Page::new();
@ -51,7 +51,7 @@ impl fmt::Display for FatalError {
} else { } else {
write!(f, "Not Found") write!(f, "Not Found")
} }
}, }
// Error 412. // Error 412.
FatalError::PreconditionFailed => write!(f, "Precondition Failed"), FatalError::PreconditionFailed => write!(f, "Precondition Failed"),
// Error 500. // Error 500.
@ -69,6 +69,7 @@ impl ResponseError for FatalError {
.body(self.to_string()) .body(self.to_string())
} }
#[rustfmt::skip]
fn status_code(&self) -> StatusCode { fn status_code(&self) -> StatusCode {
match *self { match *self {
FatalError::NotModified => StatusCode::NOT_MODIFIED, FatalError::NotModified => StatusCode::NOT_MODIFIED,

View file

@ -6,8 +6,8 @@ use unic_langid::LanguageIdentifier;
/// Almacena el Identificador de Idioma Unicode ([Unicode Language Identifier] /// Almacena el Identificador de Idioma Unicode ([Unicode Language Identifier]
/// (https://unicode.org/reports/tr35/tr35.html#Unicode_language_identifier)) de /// (https://unicode.org/reports/tr35/tr35.html#Unicode_language_identifier)) de
/// la aplicación, obtenido de `SETTINGS.app.language`. /// la aplicación, obtenido de `SETTINGS.app.language`.
pub static LANGID: LazyStatic<LanguageIdentifier> = LazyStatic::new(|| pub static LANGID: LazyStatic<LanguageIdentifier> =
match SETTINGS.app.language.parse() { LazyStatic::new(|| match SETTINGS.app.language.parse() {
Ok(language) => language, Ok(language) => language,
Err(_) => { Err(_) => {
trace::warn!( trace::warn!(
@ -20,5 +20,4 @@ pub static LANGID: LazyStatic<LanguageIdentifier> = LazyStatic::new(||
); );
"en-US".parse().unwrap() "en-US".parse().unwrap()
} }
} });
);

View file

@ -17,8 +17,10 @@ use tracing_subscriber::EnvFilter;
/// `Lazy<WorkerGuard>` se garantiza que todos los registros almacenados se /// `Lazy<WorkerGuard>` se garantiza que todos los registros almacenados se
/// enviarán antes de terminar la ejecución. /// enviarán antes de terminar la ejecución.
#[rustfmt::skip]
pub static TRACING: LazyStatic<WorkerGuard> = LazyStatic::new(|| { pub static TRACING: LazyStatic<WorkerGuard> = LazyStatic::new(|| {
let env_filter = EnvFilter::try_new(&SETTINGS.log.tracing).unwrap_or_else(|_| EnvFilter::new("Info")); let env_filter =
EnvFilter::try_new(&SETTINGS.log.tracing).unwrap_or_else(|_| EnvFilter::new("Info"));
let rolling = SETTINGS.log.rolling.to_lowercase(); let rolling = SETTINGS.log.rolling.to_lowercase();
let (non_blocking, guard) = match rolling.as_str() { let (non_blocking, guard) = match rolling.as_str() {

View file

@ -18,6 +18,7 @@ pub enum AnchorTarget {
pub type AnchorIcon = ComponentsBundle; pub type AnchorIcon = ComponentsBundle;
#[rustfmt::skip]
pub struct Anchor { pub struct Anchor {
weight : isize, weight : isize,
renderable : Renderable, renderable : Renderable,
@ -33,6 +34,7 @@ pub struct Anchor {
} }
impl ComponentTrait for Anchor { impl ComponentTrait for Anchor {
#[rustfmt::skip]
fn new() -> Self { fn new() -> Self {
Anchor { Anchor {
weight : 0, weight : 0,
@ -61,6 +63,7 @@ impl ComponentTrait for Anchor {
(self.renderable)(context) (self.renderable)(context)
} }
#[rustfmt::skip]
fn default_render(&self, context: &mut PageContext) -> Markup { fn default_render(&self, context: &mut PageContext) -> Markup {
let target = match &self.target() { let target = match &self.target() {
AnchorTarget::Blank => Some("_blank"), AnchorTarget::Blank => Some("_blank"),

View file

@ -4,6 +4,7 @@ pub_const_handler!(COMPONENT_BLOCK);
hook_before_render_component!(HOOK_BEFORE_RENDER_BLOCK, Block); hook_before_render_component!(HOOK_BEFORE_RENDER_BLOCK, Block);
#[rustfmt::skip]
pub struct Block { pub struct Block {
weight : isize, weight : isize,
renderable: Renderable, renderable: Renderable,
@ -15,6 +16,7 @@ pub struct Block {
} }
impl ComponentTrait for Block { impl ComponentTrait for Block {
#[rustfmt::skip]
fn new() -> Self { fn new() -> Self {
Block { Block {
weight : 0, weight : 0,

View file

@ -12,6 +12,7 @@ pub enum ContainerType {
Wrapper, Wrapper,
} }
#[rustfmt::skip]
pub struct Container { pub struct Container {
weight : isize, weight : isize,
renderable : Renderable, renderable : Renderable,
@ -24,6 +25,7 @@ pub struct Container {
} }
impl ComponentTrait for Container { impl ComponentTrait for Container {
#[rustfmt::skip]
fn new() -> Self { fn new() -> Self {
Container { Container {
weight : 0, weight : 0,

View file

@ -8,6 +8,7 @@ pub enum ButtonType {
Submit, Submit,
} }
#[rustfmt::skip]
pub struct Button { pub struct Button {
weight : isize, weight : isize,
renderable : Renderable, renderable : Renderable,
@ -21,6 +22,7 @@ pub struct Button {
} }
impl ComponentTrait for Button { impl ComponentTrait for Button {
#[rustfmt::skip]
fn new() -> Self { fn new() -> Self {
Button { Button {
weight : 0, weight : 0,
@ -48,6 +50,7 @@ impl ComponentTrait for Button {
(self.renderable)(context) (self.renderable)(context)
} }
#[rustfmt::skip]
fn default_render(&self, _: &mut PageContext) -> Markup { fn default_render(&self, _: &mut PageContext) -> Markup {
let button_type = match self.button_type() { let button_type = match self.button_type() {
ButtonType::Button => "button", ButtonType::Button => "button",

View file

@ -2,6 +2,7 @@ use crate::prelude::*;
pub_const_handler!(COMPONENT_DATE); pub_const_handler!(COMPONENT_DATE);
#[rustfmt::skip]
pub struct Date { pub struct Date {
weight : isize, weight : isize,
renderable : Renderable, renderable : Renderable,
@ -20,6 +21,7 @@ pub struct Date {
} }
impl ComponentTrait for Date { impl ComponentTrait for Date {
#[rustfmt::skip]
fn new() -> Self { fn new() -> Self {
Date { Date {
weight : 0, weight : 0,

View file

@ -9,6 +9,7 @@ pub enum FormMethod {
Post, Post,
} }
#[rustfmt::skip]
pub struct Form { pub struct Form {
weight : isize, weight : isize,
renderable: Renderable, renderable: Renderable,
@ -22,6 +23,7 @@ pub struct Form {
} }
impl ComponentTrait for Form { impl ComponentTrait for Form {
#[rustfmt::skip]
fn new() -> Self { fn new() -> Self {
Form { Form {
weight : 0, weight : 0,

View file

@ -2,6 +2,7 @@ use crate::prelude::*;
pub_const_handler!(COMPONENT_HIDDEN); pub_const_handler!(COMPONENT_HIDDEN);
#[rustfmt::skip]
pub struct Hidden { pub struct Hidden {
weight: isize, weight: isize,
name : IdentifierValue, name : IdentifierValue,
@ -9,6 +10,7 @@ pub struct Hidden {
} }
impl ComponentTrait for Hidden { impl ComponentTrait for Hidden {
#[rustfmt::skip]
fn new() -> Self { fn new() -> Self {
Hidden { Hidden {
weight: 0, weight: 0,

View file

@ -11,6 +11,7 @@ pub enum InputType {
Url, Url,
} }
#[rustfmt::skip]
pub struct Input { pub struct Input {
weight : isize, weight : isize,
renderable : Renderable, renderable : Renderable,
@ -33,6 +34,7 @@ pub struct Input {
} }
impl ComponentTrait for Input { impl ComponentTrait for Input {
#[rustfmt::skip]
fn new() -> Self { fn new() -> Self {
Input { Input {
weight : 0, weight : 0,
@ -69,6 +71,7 @@ impl ComponentTrait for Input {
(self.renderable)(context) (self.renderable)(context)
} }
#[rustfmt::skip]
fn default_render(&self, _: &mut PageContext) -> Markup { fn default_render(&self, _: &mut PageContext) -> Markup {
let type_input = match self.input_type() { let type_input = match self.input_type() {
InputType::Email => "email", InputType::Email => "email",
@ -130,6 +133,7 @@ impl Input {
Input::new() Input::new()
} }
#[rustfmt::skip]
pub fn password() -> Self { pub fn password() -> Self {
let mut input = Input::new().with_classes( let mut input = Input::new().with_classes(
ClassesOp::Replace("form-type-textfield"), ClassesOp::Replace("form-type-textfield"),
@ -139,6 +143,7 @@ impl Input {
input input
} }
#[rustfmt::skip]
pub fn search() -> Self { pub fn search() -> Self {
let mut input = Input::new().with_classes( let mut input = Input::new().with_classes(
ClassesOp::Replace("form-type-textfield"), ClassesOp::Replace("form-type-textfield"),
@ -148,6 +153,7 @@ impl Input {
input input
} }
#[rustfmt::skip]
pub fn email() -> Self { pub fn email() -> Self {
let mut input = Input::new().with_classes( let mut input = Input::new().with_classes(
ClassesOp::Replace("form-type-textfield"), ClassesOp::Replace("form-type-textfield"),
@ -157,6 +163,7 @@ impl Input {
input input
} }
#[rustfmt::skip]
pub fn telephone() -> Self { pub fn telephone() -> Self {
let mut input = Input::new().with_classes( let mut input = Input::new().with_classes(
ClassesOp::Replace("form-type-textfield"), ClassesOp::Replace("form-type-textfield"),
@ -166,6 +173,7 @@ impl Input {
input input
} }
#[rustfmt::skip]
pub fn url() -> Self { pub fn url() -> Self {
let mut input = Input::new().with_classes( let mut input = Input::new().with_classes(
ClassesOp::Replace("form-type-textfield"), ClassesOp::Replace("form-type-textfield"),

View file

@ -4,16 +4,16 @@ pub_const_handler!(COMPONENT_COLUMN);
hook_before_render_component!(HOOK_BEFORE_RENDER_COLUMN, Column); hook_before_render_component!(HOOK_BEFORE_RENDER_COLUMN, Column);
const SIZE_DEFAULT: &str = "col-md"; const SIZE__DEFAULT: &str = "col-md";
const SIZE_1_OF_12: &str = "col-md-1"; const SIZE__1_OF_12: &str = "col-md-1";
const SIZE_2_OF_12: &str = "col-md-2"; const SIZE__2_OF_12: &str = "col-md-2";
const SIZE_3_OF_12: &str = "col-md-3"; const SIZE__3_OF_12: &str = "col-md-3";
const SIZE_4_OF_12: &str = "col-md-4"; const SIZE__4_OF_12: &str = "col-md-4";
const SIZE_5_OF_12: &str = "col-md-5"; const SIZE__5_OF_12: &str = "col-md-5";
const SIZE_6_OF_12: &str = "col-md-6"; const SIZE__6_OF_12: &str = "col-md-6";
const SIZE_7_OF_12: &str = "col-md-7"; const SIZE__7_OF_12: &str = "col-md-7";
const SIZE_8_OF_12: &str = "col-md-8"; const SIZE__8_OF_12: &str = "col-md-8";
const SIZE_9_OF_12: &str = "col-md-9"; const SIZE__9_OF_12: &str = "col-md-9";
const SIZE_10_OF_12: &str = "col-md-10"; const SIZE_10_OF_12: &str = "col-md-10";
const SIZE_11_OF_12: &str = "col-md-11"; const SIZE_11_OF_12: &str = "col-md-11";
const SIZE_12_OF_12: &str = "col-md-12"; const SIZE_12_OF_12: &str = "col-md-12";
@ -33,6 +33,8 @@ pub enum ColumnSize {
Is11of12, Is11of12,
IsFull, IsFull,
} }
#[rustfmt::skip]
pub struct Column { pub struct Column {
weight : isize, weight : isize,
renderable: Renderable, renderable: Renderable,
@ -44,12 +46,13 @@ pub struct Column {
} }
impl ComponentTrait for Column { impl ComponentTrait for Column {
#[rustfmt::skip]
fn new() -> Self { fn new() -> Self {
Column { Column {
weight : 0, weight : 0,
renderable: render_always, renderable: render_always,
id : IdentifierValue::new(), id : IdentifierValue::new(),
classes : Classes::new_with_default(SIZE_DEFAULT), classes : Classes::new_with_default(SIZE__DEFAULT),
size : ColumnSize::Default, size : ColumnSize::Default,
components: ComponentsBundle::new(), components: ComponentsBundle::new(),
template : "default".to_owned(), template : "default".to_owned(),
@ -149,18 +152,19 @@ impl Column {
self self
} }
#[rustfmt::skip]
pub fn alter_size(&mut self, size: ColumnSize) -> &mut Self { pub fn alter_size(&mut self, size: ColumnSize) -> &mut Self {
match size { match size {
ColumnSize::Default => self.alter_classes(ClassesOp::SetDefault, SIZE_DEFAULT), ColumnSize::Default => self.alter_classes(ClassesOp::SetDefault, SIZE__DEFAULT),
ColumnSize::Is1of12 => self.alter_classes(ClassesOp::SetDefault, SIZE_1_OF_12), ColumnSize::Is1of12 => self.alter_classes(ClassesOp::SetDefault, SIZE__1_OF_12),
ColumnSize::Is2of12 => self.alter_classes(ClassesOp::SetDefault, SIZE_2_OF_12), ColumnSize::Is2of12 => self.alter_classes(ClassesOp::SetDefault, SIZE__2_OF_12),
ColumnSize::Is3of12 => self.alter_classes(ClassesOp::SetDefault, SIZE_3_OF_12), ColumnSize::Is3of12 => self.alter_classes(ClassesOp::SetDefault, SIZE__3_OF_12),
ColumnSize::Is4of12 => self.alter_classes(ClassesOp::SetDefault, SIZE_4_OF_12), ColumnSize::Is4of12 => self.alter_classes(ClassesOp::SetDefault, SIZE__4_OF_12),
ColumnSize::Is5of12 => self.alter_classes(ClassesOp::SetDefault, SIZE_5_OF_12), ColumnSize::Is5of12 => self.alter_classes(ClassesOp::SetDefault, SIZE__5_OF_12),
ColumnSize::Is6of12 => self.alter_classes(ClassesOp::SetDefault, SIZE_6_OF_12), ColumnSize::Is6of12 => self.alter_classes(ClassesOp::SetDefault, SIZE__6_OF_12),
ColumnSize::Is7of12 => self.alter_classes(ClassesOp::SetDefault, SIZE_7_OF_12), ColumnSize::Is7of12 => self.alter_classes(ClassesOp::SetDefault, SIZE__7_OF_12),
ColumnSize::Is8of12 => self.alter_classes(ClassesOp::SetDefault, SIZE_8_OF_12), ColumnSize::Is8of12 => self.alter_classes(ClassesOp::SetDefault, SIZE__8_OF_12),
ColumnSize::Is9of12 => self.alter_classes(ClassesOp::SetDefault, SIZE_9_OF_12), ColumnSize::Is9of12 => self.alter_classes(ClassesOp::SetDefault, SIZE__9_OF_12),
ColumnSize::Is10of12 => self.alter_classes(ClassesOp::SetDefault, SIZE_10_OF_12), ColumnSize::Is10of12 => self.alter_classes(ClassesOp::SetDefault, SIZE_10_OF_12),
ColumnSize::Is11of12 => self.alter_classes(ClassesOp::SetDefault, SIZE_11_OF_12), ColumnSize::Is11of12 => self.alter_classes(ClassesOp::SetDefault, SIZE_11_OF_12),
ColumnSize::IsFull => self.alter_classes(ClassesOp::SetDefault, SIZE_12_OF_12), ColumnSize::IsFull => self.alter_classes(ClassesOp::SetDefault, SIZE_12_OF_12),

View file

@ -4,6 +4,7 @@ pub_const_handler!(COMPONENT_ROW);
hook_before_render_component!(HOOK_BEFORE_RENDER_ROW, Row); hook_before_render_component!(HOOK_BEFORE_RENDER_ROW, Row);
#[rustfmt::skip]
pub struct Row { pub struct Row {
weight : isize, weight : isize,
renderable: Renderable, renderable: Renderable,
@ -14,6 +15,7 @@ pub struct Row {
} }
impl ComponentTrait for Row { impl ComponentTrait for Row {
#[rustfmt::skip]
fn new() -> Self { fn new() -> Self {
Row { Row {
weight : 0, weight : 0,

View file

@ -21,6 +21,7 @@ pub enum HeadingDisplay {
Subtitle, Subtitle,
} }
#[rustfmt::skip]
pub struct Heading { pub struct Heading {
weight : isize, weight : isize,
renderable : Renderable, renderable : Renderable,
@ -33,6 +34,7 @@ pub struct Heading {
} }
impl ComponentTrait for Heading { impl ComponentTrait for Heading {
#[rustfmt::skip]
fn new() -> Self { fn new() -> Self {
Heading { Heading {
weight : 0, weight : 0,
@ -191,6 +193,7 @@ impl Heading {
self self
} }
#[rustfmt::skip]
pub fn alter_display(&mut self, display: HeadingDisplay) -> &mut Self { pub fn alter_display(&mut self, display: HeadingDisplay) -> &mut Self {
self.display = display; self.display = display;
self.classes.alter( self.classes.alter(

View file

@ -2,6 +2,7 @@ use crate::prelude::*;
pub_const_handler!(COMPONENT_HTML); pub_const_handler!(COMPONENT_HTML);
#[rustfmt::skip]
pub struct Html { pub struct Html {
weight : isize, weight : isize,
renderable: Renderable, renderable: Renderable,
@ -10,6 +11,7 @@ pub struct Html {
} }
impl ComponentTrait for Html { impl ComponentTrait for Html {
#[rustfmt::skip]
fn new() -> Self { fn new() -> Self {
Html { Html {
weight : 0, weight : 0,

View file

@ -2,6 +2,7 @@ use crate::prelude::*;
pub_const_handler!(COMPONENT_ICON); pub_const_handler!(COMPONENT_ICON);
#[rustfmt::skip]
pub struct Icon { pub struct Icon {
weight : isize, weight : isize,
renderable: Renderable, renderable: Renderable,
@ -10,6 +11,7 @@ pub struct Icon {
} }
impl ComponentTrait for Icon { impl ComponentTrait for Icon {
#[rustfmt::skip]
fn new() -> Self { fn new() -> Self {
Icon { Icon {
weight : 0, weight : 0,

View file

@ -2,6 +2,7 @@ use crate::prelude::*;
pub_const_handler!(COMPONENT_IMAGE); pub_const_handler!(COMPONENT_IMAGE);
#[rustfmt::skip]
pub struct Image { pub struct Image {
weight : isize, weight : isize,
renderable: Renderable, renderable: Renderable,
@ -12,6 +13,7 @@ pub struct Image {
} }
impl ComponentTrait for Image { impl ComponentTrait for Image {
#[rustfmt::skip]
fn new() -> Self { fn new() -> Self {
Image { Image {
weight : 0, weight : 0,

View file

@ -14,6 +14,7 @@ pub enum MenuItemType {
// MenuItem. // MenuItem.
#[rustfmt::skip]
pub struct MenuItem { pub struct MenuItem {
weight : isize, weight : isize,
renderable: Renderable, renderable: Renderable,
@ -21,6 +22,7 @@ pub struct MenuItem {
} }
impl ComponentTrait for MenuItem { impl ComponentTrait for MenuItem {
#[rustfmt::skip]
fn new() -> Self { fn new() -> Self {
MenuItem { MenuItem {
weight : 0, weight : 0,
@ -82,6 +84,7 @@ impl ComponentTrait for MenuItem {
} }
impl MenuItem { impl MenuItem {
#[rustfmt::skip]
pub fn label(label: &str) -> Self { pub fn label(label: &str) -> Self {
MenuItem { MenuItem {
weight : 0, weight : 0,
@ -90,6 +93,7 @@ impl MenuItem {
} }
} }
#[rustfmt::skip]
pub fn link(label: &str, path: &str) -> Self { pub fn link(label: &str, path: &str) -> Self {
MenuItem { MenuItem {
weight : 0, weight : 0,
@ -98,6 +102,7 @@ impl MenuItem {
} }
} }
#[rustfmt::skip]
pub fn link_blank(label: &str, path: &str) -> Self { pub fn link_blank(label: &str, path: &str) -> Self {
MenuItem { MenuItem {
weight : 0, weight : 0,
@ -106,6 +111,7 @@ impl MenuItem {
} }
} }
#[rustfmt::skip]
pub fn html(html: Markup) -> Self { pub fn html(html: Markup) -> Self {
MenuItem { MenuItem {
weight : 0, weight : 0,
@ -114,6 +120,7 @@ impl MenuItem {
} }
} }
#[rustfmt::skip]
pub fn separator() -> Self { pub fn separator() -> Self {
MenuItem { MenuItem {
weight : 0, weight : 0,
@ -122,6 +129,7 @@ impl MenuItem {
} }
} }
#[rustfmt::skip]
pub fn submenu(label: &str, menu: Menu) -> Self { pub fn submenu(label: &str, menu: Menu) -> Self {
MenuItem { MenuItem {
weight : 0, weight : 0,
@ -167,6 +175,7 @@ pub_const_handler!(COMPONENT_MENU);
hook_before_render_component!(HOOK_BEFORE_RENDER_MENU, Menu); hook_before_render_component!(HOOK_BEFORE_RENDER_MENU, Menu);
#[rustfmt::skip]
pub struct Menu { pub struct Menu {
weight : isize, weight : isize,
renderable: Renderable, renderable: Renderable,
@ -177,6 +186,7 @@ pub struct Menu {
} }
impl ComponentTrait for Menu { impl ComponentTrait for Menu {
#[rustfmt::skip]
fn new() -> Self { fn new() -> Self {
Menu { Menu {
weight : 0, weight : 0,

View file

@ -11,6 +11,7 @@ pub enum ParagraphDisplay {
Normal, Normal,
} }
#[rustfmt::skip]
pub struct Paragraph { pub struct Paragraph {
weight : isize, weight : isize,
renderable: Renderable, renderable: Renderable,
@ -22,6 +23,7 @@ pub struct Paragraph {
} }
impl ComponentTrait for Paragraph { impl ComponentTrait for Paragraph {
#[rustfmt::skip]
fn new() -> Self { fn new() -> Self {
Paragraph { Paragraph {
weight : 0, weight : 0,
@ -130,6 +132,7 @@ impl Paragraph {
self self
} }
#[rustfmt::skip]
pub fn alter_display(&mut self, display: ParagraphDisplay) -> &mut Self { pub fn alter_display(&mut self, display: ParagraphDisplay) -> &mut Self {
self.display = display; self.display = display;
self.classes.alter( self.classes.alter(

View file

@ -27,8 +27,8 @@ impl ModuleTrait for DefaultHomePage {
async fn demo() -> ResultPage<Markup, FatalError> { async fn demo() -> ResultPage<Markup, FatalError> {
Page::new() Page::new()
.with_title(l("page_title").as_str()) .with_title(l("page_title").as_str())
.with_context(PageOp::AddStyleSheet( .with_context(PageOp::AddStyleSheet(StyleSheet::located(
StyleSheet::located("/theme/module/homepage/styles.css" "/theme/module/homepage/styles.css",
))) )))
.add_to("region-content", hello_world()) .add_to("region-content", hello_world())
.add_to("region-content", welcome()) .add_to("region-content", welcome())

View file

@ -16,12 +16,11 @@ impl ThemeTrait for Aliner {
} }
fn before_render_page(&self, page: &mut Page) { fn before_render_page(&self, page: &mut Page) {
page page.alter_context(PageOp::AddFavicon(
.alter_context(PageOp::AddFavicon( Favicon::new().with_icon("/theme/favicon.png"),
Favicon::new().with_icon("/theme/favicon.png"), ))
)) .alter_context(PageOp::AddStyleSheet(
.alter_context(PageOp::AddStyleSheet( StyleSheet::located("/aliner/css/styles.css").with_weight(-99),
StyleSheet::located("/aliner/css/styles.css").with_weight(-99), ));
));
} }
} }

View file

@ -18,50 +18,46 @@ impl ThemeTrait for Bootsier {
} }
fn before_render_page(&self, page: &mut Page) { fn before_render_page(&self, page: &mut Page) {
page page.alter_context(PageOp::AddFavicon(
.alter_context(PageOp::AddFavicon( Favicon::new().with_icon("/theme/favicon.png"),
Favicon::new().with_icon("/theme/favicon.png"), ))
)) .alter_context(PageOp::AddStyleSheet(
.alter_context(PageOp::AddStyleSheet( StyleSheet::located("/bootsier/css/bootstrap.min.css")
StyleSheet::located("/bootsier/css/bootstrap.min.css") .with_version("5.1.3")
.with_version("5.1.3") .with_weight(-99),
.with_weight(-99), ))
)) .alter_context(PageOp::AddJavaScript(
.alter_context(PageOp::AddJavaScript( JavaScript::located("/bootsier/js/bootstrap.bundle.min.js")
JavaScript::located("/bootsier/js/bootstrap.bundle.min.js") .with_version("5.1.3")
.with_version("5.1.3") .with_weight(-99),
.with_weight(-99), ))
)) .alter_context(PageOp::AddJQuery);
.alter_context(PageOp::AddJQuery);
} }
fn error_404_not_found(&self) -> Container { fn error_404_not_found(&self) -> Container {
Container::new() Container::new().with_component(Html::with(html! {
.with_component( div class="jumbotron" {
Html::with(html! { div class="media" {
div class="jumbotron" { img
div class="media" { src="/bootsier/images/caution.png"
img class="mr-4"
src="/bootsier/images/caution.png" style="width: 20%; max-width: 188px"
class="mr-4" alt="Caution!";
style="width: 20%; max-width: 188px" div class="media-body" {
alt="Caution!"; h1 class="display-4" { ("RESOURCE NOT FOUND") }
div class="media-body" { p class="lead" { (l("e404-description")) }
h1 class="display-4" { ("RESOURCE NOT FOUND") } hr class="my-4";
p class="lead" { (l("e404-description")) } p { (l("e404-description")) }
hr class="my-4"; a
p { (l("e404-description")) } class="btn btn-primary btn-lg"
a href="/"
class="btn btn-primary btn-lg" role="button"
href="/" {
role="button" (l("back-homepage"))
{
(l("back-homepage"))
}
}
} }
} }
}) }
) }
}))
} }
} }

View file

@ -16,18 +16,18 @@ impl ThemeTrait for Bulmix {
} }
fn before_render_page(&self, page: &mut Page) { fn before_render_page(&self, page: &mut Page) {
page page.alter_context(PageOp::AddFavicon(
.alter_context(PageOp::AddFavicon( Favicon::new().with_icon("/theme/favicon.png"),
Favicon::new().with_icon("/theme/favicon.png"), ))
)) .alter_context(PageOp::AddStyleSheet(
.alter_context(PageOp::AddStyleSheet( StyleSheet::located("/bulmix/css/bulma.min.css")
StyleSheet::located("/bulmix/css/bulma.min.css") .with_version("0.9.4")
.with_version("0.9.4") .with_weight(-99),
.with_weight(-99), ))
)) .alter_context(PageOp::AddJQuery);
.alter_context(PageOp::AddJQuery);
} }
#[rustfmt::skip]
fn before_render_component( fn before_render_component(
&self, &self,
component: &mut dyn ComponentTrait, component: &mut dyn ComponentTrait,

View file

@ -62,6 +62,7 @@ macro_rules! config_map {
}; };
} }
#[rustfmt::skip]
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
pub struct App { pub struct App {
pub name : String, pub name : String,
@ -73,6 +74,7 @@ pub struct App {
pub run_mode : String, pub run_mode : String,
} }
#[rustfmt::skip]
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
pub struct Log { pub struct Log {
pub tracing : String, pub tracing : String,
@ -82,6 +84,7 @@ pub struct Log {
pub format : String, pub format : String,
} }
#[rustfmt::skip]
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
pub struct Database { pub struct Database {
pub db_type : String, pub db_type : String,
@ -93,17 +96,20 @@ pub struct Database {
pub max_pool_size : u32, pub max_pool_size : u32,
} }
#[rustfmt::skip]
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
pub struct Webserver { pub struct Webserver {
pub bind_address : String, pub bind_address : String,
pub bind_port : u16, pub bind_port : u16,
} }
#[rustfmt::skip]
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
pub struct Dev { pub struct Dev {
pub static_files : String, pub static_files : String,
} }
#[rustfmt::skip]
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
pub struct Settings { pub struct Settings {
pub app : App, pub app : App,

View file

@ -4,9 +4,8 @@ use crate::LazyStatic;
use std::collections::HashMap; use std::collections::HashMap;
use std::sync::RwLock; use std::sync::RwLock;
static COMPONENTS: LazyStatic<RwLock<HashMap<&str, ComponentsBundle>>> = LazyStatic::new(|| static COMPONENTS: LazyStatic<RwLock<HashMap<&str, ComponentsBundle>>> =
RwLock::new(HashMap::new()) LazyStatic::new(|| RwLock::new(HashMap::new()));
);
pub fn add_component_to(region: &'static str, component: impl ComponentTrait) { pub fn add_component_to(region: &'static str, component: impl ComponentTrait) {
let mut hmap = COMPONENTS.write().unwrap(); let mut hmap = COMPONENTS.write().unwrap();

View file

@ -2,8 +2,8 @@ mod definition;
pub use definition::{action_ref, AnyHookAction, HookActionTrait}; pub use definition::{action_ref, AnyHookAction, HookActionTrait};
mod holder; mod holder;
pub use holder::HookAction;
use holder::ActionsHolder; use holder::ActionsHolder;
pub use holder::HookAction;
mod all; mod all;
pub(crate) use all::add_action; pub(crate) use all::add_action;

View file

@ -1,14 +1,13 @@
use super::{HookAction, ActionsHolder}; use super::{ActionsHolder, HookAction};
use crate::LazyStatic;
use crate::util::Handler; use crate::util::Handler;
use crate::LazyStatic;
use std::collections::HashMap; use std::collections::HashMap;
use std::sync::RwLock; use std::sync::RwLock;
// Registered actions. // Registered actions.
static ACTIONS: LazyStatic<RwLock<HashMap<Handler, ActionsHolder>>> = LazyStatic::new(|| static ACTIONS: LazyStatic<RwLock<HashMap<Handler, ActionsHolder>>> =
RwLock::new(HashMap::new()) LazyStatic::new(|| RwLock::new(HashMap::new()));
);
pub fn add_action(action: HookAction) { pub fn add_action(action: HookAction) {
let mut actions = ACTIONS.write().unwrap(); let mut actions = ACTIONS.write().unwrap();

View file

@ -8,9 +8,8 @@ use crate::{db::*, run_now};
use std::sync::RwLock; use std::sync::RwLock;
// Enabled modules. // Enabled modules.
static ENABLED_MODULES: LazyStatic<RwLock<Vec<&dyn ModuleTrait>>> = LazyStatic::new(|| static ENABLED_MODULES: LazyStatic<RwLock<Vec<&dyn ModuleTrait>>> =
RwLock::new(Vec::new()) LazyStatic::new(|| RwLock::new(Vec::new()));
);
/* Disabled modules. /* Disabled modules.
static DISABLED_MODULES: Lazy<RwLock<Vec<&dyn ModuleTrait>>> = Lazy::new(|| { static DISABLED_MODULES: Lazy<RwLock<Vec<&dyn ModuleTrait>>> = Lazy::new(|| {
@ -35,7 +34,8 @@ fn add_to(list: &mut Vec<&dyn ModuleTrait>, module: &'static dyn ModuleTrait) {
.read() .read()
.unwrap() .unwrap()
.iter() .iter()
.any(|m| m.handler() == module.handler()) && !list.iter().any(|m| m.handler() == module.handler()) .any(|m| m.handler() == module.handler())
&& !list.iter().any(|m| m.handler() == module.handler())
{ {
trace::debug!("Enabling module \"{}\"", module.single_name()); trace::debug!("Enabling module \"{}\"", module.single_name());
list.push(module); list.push(module);

View file

@ -6,9 +6,8 @@ use std::sync::RwLock;
include!(concat!(env!("OUT_DIR"), "/theme.rs")); include!(concat!(env!("OUT_DIR"), "/theme.rs"));
// Temas registrados. // Temas registrados.
static THEMES: LazyStatic<RwLock<Vec<&dyn ThemeTrait>>> = LazyStatic::new(|| static THEMES: LazyStatic<RwLock<Vec<&dyn ThemeTrait>>> =
RwLock::new(Vec::new()) LazyStatic::new(|| RwLock::new(Vec::new()));
);
pub fn register_themes(themes: Vec<&'static dyn ThemeTrait>) { pub fn register_themes(themes: Vec<&'static dyn ThemeTrait>) {
for t in themes { for t in themes {

View file

@ -125,25 +125,19 @@ pub trait ThemeTrait: BaseTheme + Send + Sync {
} }
fn error_404_not_found(&self) -> Container { fn error_404_not_found(&self) -> Container {
Container::new() Container::new().with_component(Html::with(html! {
.with_component( div {
Html::with(html! { h1 { ("RESOURCE NOT FOUND") }
div { }
h1 { ("RESOURCE NOT FOUND") } }))
}
})
)
} }
fn error_403_access_denied(&self) -> Container { fn error_403_access_denied(&self) -> Container {
Container::new() Container::new().with_component(Html::with(html! {
.with_component( div {
Html::with(html! { h1 { ("FORBIDDEN ACCESS") }
div { }
h1 { ("FORBIDDEN ACCESS") } }))
}
})
)
} }
} }

View file

@ -1,7 +1,7 @@
pub use maud::{html, Markup, PreEscaped, DOCTYPE}; pub use maud::{html, Markup, PreEscaped, DOCTYPE};
mod assets; mod assets;
pub use assets::javascript::{JavaScript, JSMode}; pub use assets::javascript::{JavaScript, ModeJS};
pub use assets::stylesheet::{StyleSheet, TargetMedia}; pub use assets::stylesheet::{StyleSheet, TargetMedia};
pub use assets::Assets; pub use assets::Assets;

View file

@ -2,18 +2,19 @@ use super::AssetsTrait;
use crate::html::{html, Markup}; use crate::html::{html, Markup};
#[derive(PartialEq)] #[derive(PartialEq)]
pub enum JSMode { pub enum ModeJS {
Async, Async,
Defer, Defer,
Normal, Normal,
} }
#[rustfmt::skip]
pub struct JavaScript { pub struct JavaScript {
source : &'static str, source : &'static str,
prefix : &'static str, prefix : &'static str,
version: &'static str, version: &'static str,
weight : isize, weight : isize,
mode : JSMode, mode : ModeJS,
} }
impl AssetsTrait for JavaScript { impl AssetsTrait for JavaScript {
@ -29,21 +30,22 @@ impl AssetsTrait for JavaScript {
html! { html! {
script type="text/javascript" script type="text/javascript"
src=(crate::concat_string!(self.source, self.prefix, self.version)) src=(crate::concat_string!(self.source, self.prefix, self.version))
async[self.mode == JSMode::Async] async[self.mode == ModeJS::Async]
defer[self.mode == JSMode::Defer] defer[self.mode == ModeJS::Defer]
{}; {};
} }
} }
} }
impl JavaScript { impl JavaScript {
#[rustfmt::skip]
pub fn located(source: &'static str) -> Self { pub fn located(source: &'static str) -> Self {
JavaScript { JavaScript {
source, source,
prefix : "", prefix : "",
version: "", version: "",
weight : 0, weight : 0,
mode : JSMode::Defer, mode : ModeJS::Defer,
} }
} }
@ -61,7 +63,7 @@ impl JavaScript {
self self
} }
pub fn with_mode(mut self, mode: JSMode) -> Self { pub fn with_mode(mut self, mode: ModeJS) -> Self {
self.mode = mode; self.mode = mode;
self self
} }

View file

@ -1,8 +1,14 @@
use super::AssetsTrait; use super::AssetsTrait;
use crate::html::{html, Markup}; use crate::html::{html, Markup};
pub enum TargetMedia {Default, Print, Screen, Speech} pub enum TargetMedia {
Default,
Print,
Screen,
Speech,
}
#[rustfmt::skip]
pub struct StyleSheet { pub struct StyleSheet {
source : &'static str, source : &'static str,
prefix : &'static str, prefix : &'static str,
@ -31,6 +37,7 @@ impl AssetsTrait for StyleSheet {
} }
impl StyleSheet { impl StyleSheet {
#[rustfmt::skip]
pub fn located(source: &'static str) -> Self { pub fn located(source: &'static str) -> Self {
StyleSheet { StyleSheet {
source, source,
@ -55,6 +62,7 @@ impl StyleSheet {
self self
} }
#[rustfmt::skip]
pub fn for_media(mut self, media: TargetMedia) -> Self { pub fn for_media(mut self, media: TargetMedia) -> Self {
self.media = match media { self.media = match media {
TargetMedia::Print => Some("print"), TargetMedia::Print => Some("print"),

View file

@ -14,6 +14,7 @@ pub enum ClassesOp {
SetDefaultIfEmpty, SetDefaultIfEmpty,
} }
#[rustfmt::skip]
#[derive(Default)] #[derive(Default)]
pub struct Classes { pub struct Classes {
default: String, default: String,
@ -21,6 +22,7 @@ pub struct Classes {
} }
impl Classes { impl Classes {
#[rustfmt::skip]
pub fn new() -> Self { pub fn new() -> Self {
Classes { Classes {
default: "".to_owned(), default: "".to_owned(),

View file

@ -29,10 +29,8 @@ impl Favicon {
} }
pub fn with_theme_color(mut self, color: &str) -> Self { pub fn with_theme_color(mut self, color: &str) -> Self {
self.0.push(format!( self.0
"<meta name=\"theme-color\" content=\"{}\">", .push(format!("<meta name=\"theme-color\" content=\"{}\">", color));
color
));
self self
} }

View file

@ -1,15 +1,9 @@
//! Re-exporta recursos comunes. //! Re-exporta recursos comunes.
// Global macros and helpers. // Global macros and helpers.
pub use crate::{
args,
concat_string,
pub_const_handler,
theme_static_files,
LazyStatic
};
pub use crate::util; pub use crate::util;
pub use crate::util::Handler; pub use crate::util::Handler;
pub use crate::{args, concat_string, pub_const_handler, theme_static_files, LazyStatic};
pub use crate::config::SETTINGS; pub use crate::config::SETTINGS;

View file

@ -1,4 +1,4 @@
use crate::html::{Favicon, StyleSheet, JavaScript}; use crate::html::{Favicon, JavaScript, StyleSheet};
pub use actix_web::Result as ResultPage; pub use actix_web::Result as ResultPage;

View file

@ -2,16 +2,16 @@ use super::PageOp;
use crate::config::SETTINGS; use crate::config::SETTINGS;
use crate::core::theme::all::theme_by_single_name; use crate::core::theme::all::theme_by_single_name;
use crate::core::theme::ThemeTrait; use crate::core::theme::ThemeTrait;
use crate::html::{html, Assets, Favicon, StyleSheet, JavaScript, JSMode, Markup, IdentifierValue}; use crate::html::{html, Assets, Favicon, IdentifierValue, JavaScript, Markup, ModeJS, StyleSheet};
use crate::{base, concat_string, util, LazyStatic}; use crate::{base, concat_string, util, LazyStatic};
static DEFAULT_THEME: LazyStatic<&dyn ThemeTrait> = LazyStatic::new(|| static DEFAULT_THEME: LazyStatic<&dyn ThemeTrait> =
match theme_by_single_name(&SETTINGS.app.theme) { LazyStatic::new(|| match theme_by_single_name(&SETTINGS.app.theme) {
Some(theme) => theme, Some(theme) => theme,
None => &base::theme::bootsier::Bootsier, None => &base::theme::bootsier::Bootsier,
} });
);
#[rustfmt::skip]
pub struct PageContext { pub struct PageContext {
theme : &'static dyn ThemeTrait, theme : &'static dyn ThemeTrait,
favicon : Option<Favicon>, favicon : Option<Favicon>,
@ -24,6 +24,7 @@ pub struct PageContext {
} }
impl PageContext { impl PageContext {
#[rustfmt::skip]
pub fn new() -> Self { pub fn new() -> Self {
PageContext { PageContext {
theme : *DEFAULT_THEME, theme : *DEFAULT_THEME,
@ -76,7 +77,7 @@ impl PageContext {
JavaScript::located("/theme/js/jquery.min.js") JavaScript::located("/theme/js/jquery.min.js")
.with_version("3.6.0") .with_version("3.6.0")
.with_weight(isize::MIN) .with_weight(isize::MIN)
.with_mode(JSMode::Normal), .with_mode(ModeJS::Normal),
); );
self.with_jquery = true; self.with_jquery = true;
} }

View file

@ -1,10 +1,4 @@
use super::{ use super::{BeforeRenderPageHook, PageContext, PageOp, ResultPage, HOOK_BEFORE_RENDER_PAGE};
BeforeRenderPageHook,
PageContext,
PageOp,
ResultPage,
HOOK_BEFORE_RENDER_PAGE,
};
use crate::app::fatal_error::FatalError; use crate::app::fatal_error::FatalError;
use crate::config::SETTINGS; use crate::config::SETTINGS;
use crate::core::component::*; use crate::core::component::*;
@ -47,6 +41,7 @@ pub enum TextDirection {
RightToLeft, RightToLeft,
} }
#[rustfmt::skip]
pub struct Page { pub struct Page {
context : PageContext, context : PageContext,
language : AttributeValue, language : AttributeValue,
@ -59,6 +54,7 @@ pub struct Page {
} }
impl Page { impl Page {
#[rustfmt::skip]
pub fn new() -> Self { pub fn new() -> Self {
Page { Page {
context : PageContext::new(), context : PageContext::new(),

View file

@ -37,12 +37,8 @@ pub const fn handler(
#[macro_export] #[macro_export]
macro_rules! pub_const_handler { macro_rules! pub_const_handler {
( $HANDLER:ident ) => { ( $HANDLER:ident ) => {
pub const $HANDLER: $crate::util::Handler = $crate::util::handler( pub const $HANDLER: $crate::util::Handler =
module_path!(), $crate::util::handler(module_path!(), file!(), line!(), column!());
file!(),
line!(),
column!(),
);
}; };
} }
@ -89,10 +85,8 @@ macro_rules! theme_static_files {
$cfg.service($crate::app::ResourceFiles::new($dir, generate())); $cfg.service($crate::app::ResourceFiles::new($dir, generate()));
} else { } else {
$cfg.service( $cfg.service(
$crate::app::ActixFiles::new( $crate::app::ActixFiles::new($dir, $crate::concat_string!(static_files, $dir))
$dir, $crate::concat_string!(static_files, $dir) .show_files_listing(),
)
.show_files_listing(),
); );
} }
}}; }};