Actualiza para cumplir recomendaciones de clippy

Básicamente a todos los componentes y elementos principales se les
implementa Default() y se adaptan los constructores para inicializar los
campos de sus estructuras de datos.
This commit is contained in:
Manuel Cillero 2022-07-30 18:32:32 +02:00
parent 0e974d6d59
commit 261cea6c2f
30 changed files with 372 additions and 448 deletions

View file

@ -2,23 +2,28 @@ use crate::prelude::*;
pub_const_handler!(COMPONENT_ANCHOR); pub_const_handler!(COMPONENT_ANCHOR);
#[derive(Default)]
pub enum AnchorType { pub enum AnchorType {
Button, #[default]
Link, Link,
Button,
Location, Location,
} }
#[derive(Default)]
pub enum AnchorTarget { pub enum AnchorTarget {
Blank, #[default]
Context(String),
Default, Default,
Blank,
Parent, Parent,
Top, Top,
Context(String),
} }
pub type AnchorIcon = ComponentsBundle; pub type AnchorIcon = ComponentsBundle;
#[rustfmt::skip] #[rustfmt::skip]
#[derive(Default)]
pub struct Anchor { pub struct Anchor {
weight : isize, weight : isize,
renderable : Renderable, renderable : Renderable,
@ -26,7 +31,7 @@ pub struct Anchor {
classes : Classes, classes : Classes,
anchor_type: AnchorType, anchor_type: AnchorType,
href : AttributeValue, href : AttributeValue,
html : Markup, html : HtmlMarkup,
left_icon : AnchorIcon, left_icon : AnchorIcon,
right_icon : AnchorIcon, right_icon : AnchorIcon,
target : AnchorTarget, target : AnchorTarget,
@ -34,21 +39,8 @@ pub struct Anchor {
} }
impl ComponentTrait for Anchor { impl ComponentTrait for Anchor {
#[rustfmt::skip]
fn new() -> Self { fn new() -> Self {
Anchor { Anchor::default()
weight : 0,
renderable : render_always,
id : IdentifierValue::new(),
classes : Classes::new(),
anchor_type: AnchorType::Link,
href : AttributeValue::new(),
html : html! {},
left_icon : AnchorIcon::new(),
right_icon : AnchorIcon::new(),
target : AnchorTarget::Default,
template : "default".to_owned(),
}
} }
fn handler(&self) -> Handler { fn handler(&self) -> Handler {
@ -60,16 +52,16 @@ impl ComponentTrait for Anchor {
} }
fn is_renderable(&self, context: &PageContext) -> bool { fn is_renderable(&self, context: &PageContext) -> bool {
(self.renderable)(context) (self.renderable.check)(context)
} }
#[rustfmt::skip] #[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"),
AnchorTarget::Context(name) => Some(name.as_str()),
AnchorTarget::Parent => Some("_parent"), AnchorTarget::Parent => Some("_parent"),
AnchorTarget::Top => Some("_top"), AnchorTarget::Top => Some("_top"),
AnchorTarget::Context(name) => Some(name.as_str()),
_ => None, _ => None,
}; };
html! { html! {
@ -118,8 +110,8 @@ impl Anchor {
self self
} }
pub fn with_renderable(mut self, renderable: Renderable) -> Self { pub fn with_renderable(mut self, check: IsRenderable) -> Self {
self.alter_renderable(renderable); self.alter_renderable(check);
self self
} }
@ -175,24 +167,24 @@ impl Anchor {
self self
} }
pub fn alter_renderable(&mut self, renderable: Renderable) -> &mut Self { pub fn alter_renderable(&mut self, check: IsRenderable) -> &mut Self {
self.renderable = renderable; self.renderable.check = check;
self self
} }
pub fn alter_id(&mut self, id: &str) -> &mut Self { pub fn alter_id(&mut self, id: &str) -> &mut Self {
self.id.with_value(id); self.id.alter_value(id);
self self
} }
pub fn alter_classes(&mut self, op: ClassesOp, classes: &str) -> &mut Self { pub fn alter_classes(&mut self, op: ClassesOp, classes: &str) -> &mut Self {
self.classes.alter(op, classes); self.classes.alter_value(op, classes);
self self
} }
pub fn alter_type(&mut self, anchor_type: AnchorType) -> &mut Self { pub fn alter_type(&mut self, anchor_type: AnchorType) -> &mut Self {
self.anchor_type = anchor_type; self.anchor_type = anchor_type;
self.classes.alter( self.classes.alter_value(
ClassesOp::SetDefault, ClassesOp::SetDefault,
match self.anchor_type { match self.anchor_type {
AnchorType::Button => "btn btn-primary", AnchorType::Button => "btn btn-primary",
@ -203,12 +195,12 @@ impl Anchor {
} }
pub fn alter_href(&mut self, href: &str) -> &mut Self { pub fn alter_href(&mut self, href: &str) -> &mut Self {
self.href.with_value(href); self.href.alter_value(href);
self self
} }
pub fn alter_html(&mut self, html: Markup) -> &mut Self { pub fn alter_html(&mut self, html: Markup) -> &mut Self {
self.html = html; self.html.markup = html;
self self
} }
@ -253,7 +245,7 @@ impl Anchor {
} }
pub fn html(&self) -> &Markup { pub fn html(&self) -> &Markup {
&self.html &self.html.markup
} }
pub fn left_icon(&self) -> &AnchorIcon { pub fn left_icon(&self) -> &AnchorIcon {

View file

@ -5,6 +5,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] #[rustfmt::skip]
#[derive(Default)]
pub struct Block { pub struct Block {
weight : isize, weight : isize,
renderable: Renderable, renderable: Renderable,
@ -16,17 +17,8 @@ pub struct Block {
} }
impl ComponentTrait for Block { impl ComponentTrait for Block {
#[rustfmt::skip]
fn new() -> Self { fn new() -> Self {
Block { Block::default().with_classes(ClassesOp::SetDefault, "block")
weight : 0,
renderable: render_always,
id : IdentifierValue::new(),
classes : Classes::new_with_default("block"),
title : AttributeValue::new(),
components: ComponentsBundle::new(),
template : "default".to_owned(),
}
} }
fn handler(&self) -> Handler { fn handler(&self) -> Handler {
@ -38,7 +30,7 @@ impl ComponentTrait for Block {
} }
fn is_renderable(&self, context: &PageContext) -> bool { fn is_renderable(&self, context: &PageContext) -> bool {
(self.renderable)(context) (self.renderable.check)(context)
} }
fn before_render(&mut self, context: &mut PageContext) { fn before_render(&mut self, context: &mut PageContext) {
@ -77,8 +69,8 @@ impl Block {
self self
} }
pub fn with_renderable(mut self, renderable: Renderable) -> Self { pub fn with_renderable(mut self, check: IsRenderable) -> Self {
self.alter_renderable(renderable); self.alter_renderable(check);
self self
} }
@ -114,23 +106,23 @@ impl Block {
self self
} }
pub fn alter_renderable(&mut self, renderable: Renderable) -> &mut Self { pub fn alter_renderable(&mut self, check: IsRenderable) -> &mut Self {
self.renderable = renderable; self.renderable.check = check;
self self
} }
pub fn alter_id(&mut self, id: &str) -> &mut Self { pub fn alter_id(&mut self, id: &str) -> &mut Self {
self.id.with_value(id); self.id.alter_value(id);
self self
} }
pub fn alter_classes(&mut self, op: ClassesOp, classes: &str) -> &mut Self { pub fn alter_classes(&mut self, op: ClassesOp, classes: &str) -> &mut Self {
self.classes.alter(op, classes); self.classes.alter_value(op, classes);
self self
} }
pub fn alter_title(&mut self, title: &str) -> &mut Self { pub fn alter_title(&mut self, title: &str) -> &mut Self {
self.title.with_value(title); self.title.alter_value(title);
self self
} }

View file

@ -4,15 +4,18 @@ pub_const_handler!(COMPONENT_CONTAINER);
hook_before_render_component!(HOOK_BEFORE_RENDER_CONTAINER, Container); hook_before_render_component!(HOOK_BEFORE_RENDER_CONTAINER, Container);
#[derive(Default)]
pub enum ContainerType { pub enum ContainerType {
#[default]
Wrapper,
Header, Header,
Footer, Footer,
Main, Main,
Section, Section,
Wrapper,
} }
#[rustfmt::skip] #[rustfmt::skip]
#[derive(Default)]
pub struct Container { pub struct Container {
weight : isize, weight : isize,
renderable : Renderable, renderable : Renderable,
@ -25,18 +28,10 @@ pub struct Container {
} }
impl ComponentTrait for Container { impl ComponentTrait for Container {
#[rustfmt::skip]
fn new() -> Self { fn new() -> Self {
Container { Container::default()
weight : 0, .with_classes(ClassesOp::SetDefault, "container")
renderable : render_always, .with_inner_classes(ClassesOp::SetDefault, "container")
id : IdentifierValue::new(),
classes : Classes::new_with_default("container"),
inner_classes : Classes::new_with_default("container"),
container_type: ContainerType::Wrapper,
components : ComponentsBundle::new(),
template : "default".to_owned(),
}
} }
fn handler(&self) -> Handler { fn handler(&self) -> Handler {
@ -48,7 +43,7 @@ impl ComponentTrait for Container {
} }
fn is_renderable(&self, context: &PageContext) -> bool { fn is_renderable(&self, context: &PageContext) -> bool {
(self.renderable)(context) (self.renderable.check)(context)
} }
fn before_render(&mut self, context: &mut PageContext) { fn before_render(&mut self, context: &mut PageContext) {
@ -134,8 +129,8 @@ impl Container {
self self
} }
pub fn with_renderable(mut self, renderable: Renderable) -> Self { pub fn with_renderable(mut self, check: IsRenderable) -> Self {
self.alter_renderable(renderable); self.alter_renderable(check);
self self
} }
@ -171,23 +166,23 @@ impl Container {
self self
} }
pub fn alter_renderable(&mut self, renderable: Renderable) -> &mut Self { pub fn alter_renderable(&mut self, check: IsRenderable) -> &mut Self {
self.renderable = renderable; self.renderable.check = check;
self self
} }
pub fn alter_id(&mut self, id: &str) -> &mut Self { pub fn alter_id(&mut self, id: &str) -> &mut Self {
self.id.with_value(id); self.id.alter_value(id);
self self
} }
pub fn alter_classes(&mut self, op: ClassesOp, classes: &str) -> &mut Self { pub fn alter_classes(&mut self, op: ClassesOp, classes: &str) -> &mut Self {
self.classes.alter(op, classes); self.classes.alter_value(op, classes);
self self
} }
pub fn alter_inner_classes(&mut self, op: ClassesOp, classes: &str) -> &mut Self { pub fn alter_inner_classes(&mut self, op: ClassesOp, classes: &str) -> &mut Self {
self.inner_classes.alter(op, classes); self.inner_classes.alter_value(op, classes);
self self
} }

View file

@ -2,13 +2,16 @@ use crate::prelude::*;
pub_const_handler!(COMPONENT_BUTTON); pub_const_handler!(COMPONENT_BUTTON);
#[derive(Default)]
pub enum ButtonType { pub enum ButtonType {
#[default]
Button, Button,
Reset,
Submit, Submit,
Reset,
} }
#[rustfmt::skip] #[rustfmt::skip]
#[derive(Default)]
pub struct Button { pub struct Button {
weight : isize, weight : isize,
renderable : Renderable, renderable : Renderable,
@ -22,20 +25,10 @@ pub struct Button {
} }
impl ComponentTrait for Button { impl ComponentTrait for Button {
#[rustfmt::skip]
fn new() -> Self { fn new() -> Self {
Button { Button::default()
weight : 0, .with_classes(ClassesOp::SetDefault, "btn btn-primary")
renderable : render_always, .with_classes(ClassesOp::AddFirst, "form-button")
classes : Classes::new_with_default("btn btn-primary"),
button_type: ButtonType::Button,
name : AttributeValue::new(),
value : AttributeValue::new(),
autofocus : AttributeValue::new(),
disabled : AttributeValue::new(),
template : "default".to_owned(),
}
.with_classes(ClassesOp::AddFirst, "form-button")
} }
fn handler(&self) -> Handler { fn handler(&self) -> Handler {
@ -47,15 +40,14 @@ impl ComponentTrait for Button {
} }
fn is_renderable(&self, context: &PageContext) -> bool { fn is_renderable(&self, context: &PageContext) -> bool {
(self.renderable)(context) (self.renderable.check)(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",
ButtonType::Reset => "reset",
ButtonType::Submit => "submit", ButtonType::Submit => "submit",
ButtonType::Reset => "reset",
}; };
let id = self.name().get().map(|name| concat_string!("edit-", name)); let id = self.name().get().map(|name| concat_string!("edit-", name));
html! { html! {
@ -90,14 +82,6 @@ impl Button {
Button::new().with_value(value) Button::new().with_value(value)
} }
pub fn reset(value: &str) -> Self {
let mut button = Button::new()
.with_classes(ClassesOp::Replace("form-button"), "form-reset")
.with_value(value);
button.button_type = ButtonType::Reset;
button
}
pub fn submit(value: &str) -> Self { pub fn submit(value: &str) -> Self {
let mut button = Button::new() let mut button = Button::new()
.with_classes(ClassesOp::Replace("form-button"), "form-submit") .with_classes(ClassesOp::Replace("form-button"), "form-submit")
@ -106,6 +90,14 @@ impl Button {
button button
} }
pub fn reset(value: &str) -> Self {
let mut button = Button::new()
.with_classes(ClassesOp::Replace("form-button"), "form-reset")
.with_value(value);
button.button_type = ButtonType::Reset;
button
}
// Button BUILDER. // Button BUILDER.
pub fn with_weight(mut self, weight: isize) -> Self { pub fn with_weight(mut self, weight: isize) -> Self {
@ -113,8 +105,8 @@ impl Button {
self self
} }
pub fn with_renderable(mut self, renderable: Renderable) -> Self { pub fn with_renderable(mut self, check: IsRenderable) -> Self {
self.alter_renderable(renderable); self.alter_renderable(check);
self self
} }
@ -155,28 +147,28 @@ impl Button {
self self
} }
pub fn alter_renderable(&mut self, renderable: Renderable) -> &mut Self { pub fn alter_renderable(&mut self, check: IsRenderable) -> &mut Self {
self.renderable = renderable; self.renderable.check = check;
self self
} }
pub fn alter_classes(&mut self, op: ClassesOp, classes: &str) -> &mut Self { pub fn alter_classes(&mut self, op: ClassesOp, classes: &str) -> &mut Self {
self.classes.alter(op, classes); self.classes.alter_value(op, classes);
self self
} }
pub fn alter_name(&mut self, name: &str) -> &mut Self { pub fn alter_name(&mut self, name: &str) -> &mut Self {
self.name.with_value(name); self.name.alter_value(name);
self self
} }
pub fn alter_value(&mut self, value: &str) -> &mut Self { pub fn alter_value(&mut self, value: &str) -> &mut Self {
self.value.with_value(value); self.value.alter_value(value);
self self
} }
pub fn alter_autofocus(&mut self, toggle: bool) -> &mut Self { pub fn alter_autofocus(&mut self, toggle: bool) -> &mut Self {
self.autofocus.with_value(match toggle { self.autofocus.alter_value(match toggle {
true => "autofocus", true => "autofocus",
false => "", false => "",
}); });
@ -184,7 +176,7 @@ impl Button {
} }
pub fn alter_disabled(&mut self, toggle: bool) -> &mut Self { pub fn alter_disabled(&mut self, toggle: bool) -> &mut Self {
self.disabled.with_value(match toggle { self.disabled.alter_value(match toggle {
true => "disabled", true => "disabled",
false => "", false => "",
}); });

View file

@ -3,6 +3,7 @@ use crate::prelude::*;
pub_const_handler!(COMPONENT_DATE); pub_const_handler!(COMPONENT_DATE);
#[rustfmt::skip] #[rustfmt::skip]
#[derive(Default)]
pub struct Date { pub struct Date {
weight : isize, weight : isize,
renderable : Renderable, renderable : Renderable,
@ -21,25 +22,10 @@ pub struct Date {
} }
impl ComponentTrait for Date { impl ComponentTrait for Date {
#[rustfmt::skip]
fn new() -> Self { fn new() -> Self {
Date { Date::default()
weight : 0, .with_classes(ClassesOp::SetDefault,"form-item")
renderable : render_always, .with_classes(ClassesOp::AddFirst, "form-type-date")
classes : Classes::new_with_default("form-item"),
name : AttributeValue::new(),
value : AttributeValue::new(),
label : AttributeValue::new(),
placeholder : AttributeValue::new(),
autofocus : AttributeValue::new(),
autocomplete: AttributeValue::new(),
disabled : AttributeValue::new(),
readonly : AttributeValue::new(),
required : AttributeValue::new(),
help_text : AttributeValue::new(),
template : "default".to_owned(),
}
.with_classes(ClassesOp::AddFirst, "form-type-date")
} }
fn handler(&self) -> Handler { fn handler(&self) -> Handler {
@ -51,7 +37,7 @@ impl ComponentTrait for Date {
} }
fn is_renderable(&self, context: &PageContext) -> bool { fn is_renderable(&self, context: &PageContext) -> bool {
(self.renderable)(context) (self.renderable.check)(context)
} }
fn default_render(&self, _: &mut PageContext) -> Markup { fn default_render(&self, _: &mut PageContext) -> Markup {
@ -107,8 +93,8 @@ impl Date {
self self
} }
pub fn with_renderable(mut self, renderable: Renderable) -> Self { pub fn with_renderable(mut self, check: IsRenderable) -> Self {
self.alter_renderable(renderable); self.alter_renderable(check);
self self
} }
@ -179,38 +165,38 @@ impl Date {
self self
} }
pub fn alter_renderable(&mut self, renderable: Renderable) -> &mut Self { pub fn alter_renderable(&mut self, check: IsRenderable) -> &mut Self {
self.renderable = renderable; self.renderable.check = check;
self self
} }
pub fn alter_classes(&mut self, op: ClassesOp, classes: &str) -> &mut Self { pub fn alter_classes(&mut self, op: ClassesOp, classes: &str) -> &mut Self {
self.classes.alter(op, classes); self.classes.alter_value(op, classes);
self self
} }
pub fn alter_name(&mut self, name: &str) -> &mut Self { pub fn alter_name(&mut self, name: &str) -> &mut Self {
self.name.with_value(name); self.name.alter_value(name);
self self
} }
pub fn alter_value(&mut self, value: &str) -> &mut Self { pub fn alter_value(&mut self, value: &str) -> &mut Self {
self.value.with_value(value); self.value.alter_value(value);
self self
} }
pub fn alter_label(&mut self, label: &str) -> &mut Self { pub fn alter_label(&mut self, label: &str) -> &mut Self {
self.label.with_value(label); self.label.alter_value(label);
self self
} }
pub fn alter_placeholder(&mut self, placeholder: &str) -> &mut Self { pub fn alter_placeholder(&mut self, placeholder: &str) -> &mut Self {
self.placeholder.with_value(placeholder); self.placeholder.alter_value(placeholder);
self self
} }
pub fn alter_autofocus(&mut self, toggle: bool) -> &mut Self { pub fn alter_autofocus(&mut self, toggle: bool) -> &mut Self {
self.autofocus.with_value(match toggle { self.autofocus.alter_value(match toggle {
true => "autofocus", true => "autofocus",
false => "", false => "",
}); });
@ -218,7 +204,7 @@ impl Date {
} }
pub fn alter_autocomplete(&mut self, toggle: bool) -> &mut Self { pub fn alter_autocomplete(&mut self, toggle: bool) -> &mut Self {
self.autocomplete.with_value(match toggle { self.autocomplete.alter_value(match toggle {
true => "", true => "",
false => "off", false => "off",
}); });
@ -226,7 +212,7 @@ impl Date {
} }
pub fn alter_disabled(&mut self, toggle: bool) -> &mut Self { pub fn alter_disabled(&mut self, toggle: bool) -> &mut Self {
self.disabled.with_value(match toggle { self.disabled.alter_value(match toggle {
true => "disabled", true => "disabled",
false => "", false => "",
}); });
@ -234,7 +220,7 @@ impl Date {
} }
pub fn alter_readonly(&mut self, toggle: bool) -> &mut Self { pub fn alter_readonly(&mut self, toggle: bool) -> &mut Self {
self.readonly.with_value(match toggle { self.readonly.alter_value(match toggle {
true => "readonly", true => "readonly",
false => "", false => "",
}); });
@ -242,7 +228,7 @@ impl Date {
} }
pub fn alter_required(&mut self, toggle: bool) -> &mut Self { pub fn alter_required(&mut self, toggle: bool) -> &mut Self {
self.required.with_value(match toggle { self.required.alter_value(match toggle {
true => "required", true => "required",
false => "", false => "",
}); });
@ -250,7 +236,7 @@ impl Date {
} }
pub fn alter_help_text(&mut self, help_text: &str) -> &mut Self { pub fn alter_help_text(&mut self, help_text: &str) -> &mut Self {
self.help_text.with_value(help_text); self.help_text.alter_value(help_text);
self self
} }

View file

@ -4,12 +4,15 @@ pub_const_handler!(COMPONENT_FORM);
hook_before_render_component!(HOOK_BEFORE_RENDER_FORM, Form); hook_before_render_component!(HOOK_BEFORE_RENDER_FORM, Form);
#[derive(Default)]
pub enum FormMethod { pub enum FormMethod {
Get, #[default]
Post, Post,
Get,
} }
#[rustfmt::skip] #[rustfmt::skip]
#[derive(Default)]
pub struct Form { pub struct Form {
weight : isize, weight : isize,
renderable: Renderable, renderable: Renderable,
@ -23,19 +26,10 @@ pub struct Form {
} }
impl ComponentTrait for Form { impl ComponentTrait for Form {
#[rustfmt::skip]
fn new() -> Self { fn new() -> Self {
Form { Form::default()
weight : 0, .with_classes(ClassesOp::SetDefault, "form")
renderable: render_always, .with_charset("UTF-8")
id : IdentifierValue::new(),
classes : Classes::new_with_default("form"),
action : AttributeValue::new(),
charset : AttributeValue::new_with_value("UTF-8"),
method : FormMethod::Post,
elements : ComponentsBundle::new(),
template : "default".to_owned(),
}
} }
fn handler(&self) -> Handler { fn handler(&self) -> Handler {
@ -47,7 +41,7 @@ impl ComponentTrait for Form {
} }
fn is_renderable(&self, context: &PageContext) -> bool { fn is_renderable(&self, context: &PageContext) -> bool {
(self.renderable)(context) (self.renderable.check)(context)
} }
fn before_render(&mut self, context: &mut PageContext) { fn before_render(&mut self, context: &mut PageContext) {
@ -56,8 +50,8 @@ impl ComponentTrait for Form {
fn default_render(&self, context: &mut PageContext) -> Markup { fn default_render(&self, context: &mut PageContext) -> Markup {
let method = match self.method() { let method = match self.method() {
FormMethod::Get => None,
FormMethod::Post => Some("post".to_owned()), FormMethod::Post => Some("post".to_owned()),
FormMethod::Get => None,
}; };
html! { html! {
form form
@ -89,8 +83,8 @@ impl Form {
self self
} }
pub fn with_renderable(mut self, renderable: Renderable) -> Self { pub fn with_renderable(mut self, check: IsRenderable) -> Self {
self.alter_renderable(renderable); self.alter_renderable(check);
self self
} }
@ -136,28 +130,28 @@ impl Form {
self self
} }
pub fn alter_renderable(&mut self, renderable: Renderable) -> &mut Self { pub fn alter_renderable(&mut self, check: IsRenderable) -> &mut Self {
self.renderable = renderable; self.renderable.check = check;
self self
} }
pub fn alter_id(&mut self, id: &str) -> &mut Self { pub fn alter_id(&mut self, id: &str) -> &mut Self {
self.id.with_value(id); self.id.alter_value(id);
self self
} }
pub fn alter_classes(&mut self, op: ClassesOp, classes: &str) -> &mut Self { pub fn alter_classes(&mut self, op: ClassesOp, classes: &str) -> &mut Self {
self.classes.alter(op, classes); self.classes.alter_value(op, classes);
self self
} }
pub fn alter_action(&mut self, action: &str) -> &mut Self { pub fn alter_action(&mut self, action: &str) -> &mut Self {
self.action.with_value(action); self.action.alter_value(action);
self self
} }
pub fn alter_charset(&mut self, charset: &str) -> &mut Self { pub fn alter_charset(&mut self, charset: &str) -> &mut Self {
self.charset.with_value(charset); self.charset.alter_value(charset);
self self
} }

View file

@ -3,6 +3,7 @@ use crate::prelude::*;
pub_const_handler!(COMPONENT_HIDDEN); pub_const_handler!(COMPONENT_HIDDEN);
#[rustfmt::skip] #[rustfmt::skip]
#[derive(Default)]
pub struct Hidden { pub struct Hidden {
weight: isize, weight: isize,
name : IdentifierValue, name : IdentifierValue,
@ -10,13 +11,8 @@ pub struct Hidden {
} }
impl ComponentTrait for Hidden { impl ComponentTrait for Hidden {
#[rustfmt::skip]
fn new() -> Self { fn new() -> Self {
Hidden { Hidden::default()
weight: 0,
name : IdentifierValue::new(),
value : AttributeValue::new(),
}
} }
fn handler(&self) -> Handler { fn handler(&self) -> Handler {
@ -73,12 +69,12 @@ impl Hidden {
} }
pub fn alter_name(&mut self, name: &str) -> &mut Self { pub fn alter_name(&mut self, name: &str) -> &mut Self {
self.name.with_value(name); self.name.alter_value(name);
self self
} }
pub fn alter_value(&mut self, value: &str) -> &mut Self { pub fn alter_value(&mut self, value: &str) -> &mut Self {
self.value.with_value(value); self.value.alter_value(value);
self self
} }

View file

@ -2,16 +2,19 @@ use crate::prelude::*;
pub_const_handler!(COMPONENT_INPUT); pub_const_handler!(COMPONENT_INPUT);
#[derive(Default)]
pub enum InputType { pub enum InputType {
Email, #[default]
Textfield,
Password, Password,
Search, Search,
Email,
Telephone, Telephone,
Textfield,
Url, Url,
} }
#[rustfmt::skip] #[rustfmt::skip]
#[derive(Default)]
pub struct Input { pub struct Input {
weight : isize, weight : isize,
renderable : Renderable, renderable : Renderable,
@ -34,29 +37,12 @@ pub struct Input {
} }
impl ComponentTrait for Input { impl ComponentTrait for Input {
#[rustfmt::skip]
fn new() -> Self { fn new() -> Self {
Input { Input::default()
weight : 0, .with_classes(ClassesOp::SetDefault, "form-item")
renderable : render_always, .with_classes(ClassesOp::AddFirst, "form-type-textfield")
classes : Classes::new_with_default("form-item"), .with_size(Some(60))
input_type : InputType::Textfield, .with_maxlength(Some(128))
name : IdentifierValue::new(),
value : AttributeValue::new(),
label : AttributeValue::new(),
size : Some(60),
minlength : None,
maxlength : Some(128),
placeholder : AttributeValue::new(),
autofocus : AttributeValue::new(),
autocomplete: AttributeValue::new(),
disabled : AttributeValue::new(),
readonly : AttributeValue::new(),
required : AttributeValue::new(),
help_text : AttributeValue::new(),
template : "default".to_owned(),
}
.with_classes(ClassesOp::AddFirst, "form-type-textfield")
} }
fn handler(&self) -> Handler { fn handler(&self) -> Handler {
@ -68,17 +54,17 @@ impl ComponentTrait for Input {
} }
fn is_renderable(&self, context: &PageContext) -> bool { fn is_renderable(&self, context: &PageContext) -> bool {
(self.renderable)(context) (self.renderable.check)(context)
} }
#[rustfmt::skip] #[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::Textfield => "text",
InputType::Password => "password", InputType::Password => "password",
InputType::Search => "search", InputType::Search => "search",
InputType::Email => "email",
InputType::Telephone => "tel", InputType::Telephone => "tel",
InputType::Textfield => "text",
InputType::Url => "url", InputType::Url => "url",
}; };
let id = self.name().get().map(|name| concat_string!("edit-", name)); let id = self.name().get().map(|name| concat_string!("edit-", name));
@ -190,8 +176,8 @@ impl Input {
self self
} }
pub fn with_renderable(mut self, renderable: Renderable) -> Self { pub fn with_renderable(mut self, check: IsRenderable) -> Self {
self.alter_renderable(renderable); self.alter_renderable(check);
self self
} }
@ -277,18 +263,18 @@ impl Input {
self self
} }
pub fn alter_renderable(&mut self, renderable: Renderable) -> &mut Self { pub fn alter_renderable(&mut self, check: IsRenderable) -> &mut Self {
self.renderable = renderable; self.renderable.check = check;
self self
} }
pub fn alter_classes(&mut self, op: ClassesOp, classes: &str) -> &mut Self { pub fn alter_classes(&mut self, op: ClassesOp, classes: &str) -> &mut Self {
self.classes.alter(op, classes); self.classes.alter_value(op, classes);
self self
} }
pub fn alter_name(&mut self, name: &str) -> &mut Self { pub fn alter_name(&mut self, name: &str) -> &mut Self {
self.name.with_value(name); self.name.alter_value(name);
self.alter_classes( self.alter_classes(
ClassesOp::SetDefault, ClassesOp::SetDefault,
concat_string!("form-item form-item-", name).as_str(), concat_string!("form-item form-item-", name).as_str(),
@ -297,12 +283,12 @@ impl Input {
} }
pub fn alter_value(&mut self, value: &str) -> &mut Self { pub fn alter_value(&mut self, value: &str) -> &mut Self {
self.value.with_value(value); self.value.alter_value(value);
self self
} }
pub fn alter_label(&mut self, label: &str) -> &mut Self { pub fn alter_label(&mut self, label: &str) -> &mut Self {
self.label.with_value(label); self.label.alter_value(label);
self self
} }
@ -322,12 +308,12 @@ impl Input {
} }
pub fn alter_placeholder(&mut self, placeholder: &str) -> &mut Self { pub fn alter_placeholder(&mut self, placeholder: &str) -> &mut Self {
self.placeholder.with_value(placeholder); self.placeholder.alter_value(placeholder);
self self
} }
pub fn alter_autofocus(&mut self, toggle: bool) -> &mut Self { pub fn alter_autofocus(&mut self, toggle: bool) -> &mut Self {
self.autofocus.with_value(match toggle { self.autofocus.alter_value(match toggle {
true => "autofocus", true => "autofocus",
false => "", false => "",
}); });
@ -335,7 +321,7 @@ impl Input {
} }
pub fn alter_autocomplete(&mut self, toggle: bool) -> &mut Self { pub fn alter_autocomplete(&mut self, toggle: bool) -> &mut Self {
self.autocomplete.with_value(match toggle { self.autocomplete.alter_value(match toggle {
true => "", true => "",
false => "off", false => "off",
}); });
@ -343,7 +329,7 @@ impl Input {
} }
pub fn alter_disabled(&mut self, toggle: bool) -> &mut Self { pub fn alter_disabled(&mut self, toggle: bool) -> &mut Self {
self.disabled.with_value(match toggle { self.disabled.alter_value(match toggle {
true => "disabled", true => "disabled",
false => "", false => "",
}); });
@ -351,7 +337,7 @@ impl Input {
} }
pub fn alter_readonly(&mut self, toggle: bool) -> &mut Self { pub fn alter_readonly(&mut self, toggle: bool) -> &mut Self {
self.readonly.with_value(match toggle { self.readonly.alter_value(match toggle {
true => "readonly", true => "readonly",
false => "", false => "",
}); });
@ -359,7 +345,7 @@ impl Input {
} }
pub fn alter_required(&mut self, toggle: bool) -> &mut Self { pub fn alter_required(&mut self, toggle: bool) -> &mut Self {
self.required.with_value(match toggle { self.required.alter_value(match toggle {
true => "required", true => "required",
false => "", false => "",
}); });
@ -367,7 +353,7 @@ impl Input {
} }
pub fn alter_help_text(&mut self, help_text: &str) -> &mut Self { pub fn alter_help_text(&mut self, help_text: &str) -> &mut Self {
self.help_text.with_value(help_text); self.help_text.alter_value(help_text);
self self
} }

View file

@ -18,7 +18,9 @@ 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";
#[derive(Default)]
pub enum ColumnSize { pub enum ColumnSize {
#[default]
Default, Default,
Is1of12, Is1of12,
Is2of12, Is2of12,
@ -35,6 +37,7 @@ pub enum ColumnSize {
} }
#[rustfmt::skip] #[rustfmt::skip]
#[derive(Default)]
pub struct Column { pub struct Column {
weight : isize, weight : isize,
renderable: Renderable, renderable: Renderable,
@ -46,17 +49,8 @@ pub struct Column {
} }
impl ComponentTrait for Column { impl ComponentTrait for Column {
#[rustfmt::skip]
fn new() -> Self { fn new() -> Self {
Column { Column::default().with_classes(ClassesOp::SetDefault, SIZE__DEFAULT)
weight : 0,
renderable: render_always,
id : IdentifierValue::new(),
classes : Classes::new_with_default(SIZE__DEFAULT),
size : ColumnSize::Default,
components: ComponentsBundle::new(),
template : "default".to_owned(),
}
} }
fn handler(&self) -> Handler { fn handler(&self) -> Handler {
@ -68,7 +62,7 @@ impl ComponentTrait for Column {
} }
fn is_renderable(&self, context: &PageContext) -> bool { fn is_renderable(&self, context: &PageContext) -> bool {
(self.renderable)(context) (self.renderable.check)(context)
} }
fn before_render(&mut self, context: &mut PageContext) { fn before_render(&mut self, context: &mut PageContext) {
@ -100,8 +94,8 @@ impl Column {
self self
} }
pub fn with_renderable(mut self, renderable: Renderable) -> Self { pub fn with_renderable(mut self, check: IsRenderable) -> Self {
self.alter_renderable(renderable); self.alter_renderable(check);
self self
} }
@ -137,18 +131,18 @@ impl Column {
self self
} }
pub fn alter_renderable(&mut self, renderable: Renderable) -> &mut Self { pub fn alter_renderable(&mut self, check: IsRenderable) -> &mut Self {
self.renderable = renderable; self.renderable.check = check;
self self
} }
pub fn alter_id(&mut self, id: &str) -> &mut Self { pub fn alter_id(&mut self, id: &str) -> &mut Self {
self.id.with_value(id); self.id.alter_value(id);
self self
} }
pub fn alter_classes(&mut self, op: ClassesOp, classes: &str) -> &mut Self { pub fn alter_classes(&mut self, op: ClassesOp, classes: &str) -> &mut Self {
self.classes.alter(op, classes); self.classes.alter_value(op, classes);
self self
} }

View file

@ -5,6 +5,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] #[rustfmt::skip]
#[derive(Default)]
pub struct Row { pub struct Row {
weight : isize, weight : isize,
renderable: Renderable, renderable: Renderable,
@ -15,16 +16,8 @@ pub struct Row {
} }
impl ComponentTrait for Row { impl ComponentTrait for Row {
#[rustfmt::skip]
fn new() -> Self { fn new() -> Self {
Row { Row::default().with_classes(ClassesOp::SetDefault, "row")
weight : 0,
renderable: render_always,
id : IdentifierValue::new(),
classes : Classes::new_with_default("row"),
columns : ComponentsBundle::new(),
template : "default".to_owned(),
}
} }
fn handler(&self) -> Handler { fn handler(&self) -> Handler {
@ -36,7 +29,7 @@ impl ComponentTrait for Row {
} }
fn is_renderable(&self, context: &PageContext) -> bool { fn is_renderable(&self, context: &PageContext) -> bool {
(self.renderable)(context) (self.renderable.check)(context)
} }
fn before_render(&mut self, context: &mut PageContext) { fn before_render(&mut self, context: &mut PageContext) {
@ -68,8 +61,8 @@ impl Row {
self self
} }
pub fn with_renderable(mut self, renderable: Renderable) -> Self { pub fn with_renderable(mut self, check: IsRenderable) -> Self {
self.alter_renderable(renderable); self.alter_renderable(check);
self self
} }
@ -100,18 +93,18 @@ impl Row {
self self
} }
pub fn alter_renderable(&mut self, renderable: Renderable) -> &mut Self { pub fn alter_renderable(&mut self, check: IsRenderable) -> &mut Self {
self.renderable = renderable; self.renderable.check = check;
self self
} }
pub fn alter_id(&mut self, id: &str) -> &mut Self { pub fn alter_id(&mut self, id: &str) -> &mut Self {
self.id.with_value(id); self.id.alter_value(id);
self self
} }
pub fn alter_classes(&mut self, op: ClassesOp, classes: &str) -> &mut Self { pub fn alter_classes(&mut self, op: ClassesOp, classes: &str) -> &mut Self {
self.classes.alter(op, classes); self.classes.alter_value(op, classes);
self self
} }

View file

@ -2,7 +2,9 @@ use crate::prelude::*;
pub_const_handler!(COMPONENT_HEADING); pub_const_handler!(COMPONENT_HEADING);
#[derive(Default)]
pub enum HeadingType { pub enum HeadingType {
#[default]
H1, H1,
H2, H2,
H3, H3,
@ -11,41 +13,34 @@ pub enum HeadingType {
H6, H6,
} }
#[derive(Default)]
pub enum HeadingDisplay { pub enum HeadingDisplay {
#[default]
Normal,
XxLarge, XxLarge,
Large, Large,
Medium, Medium,
Small, Small,
XxSmall, XxSmall,
Normal,
Subtitle, Subtitle,
} }
#[rustfmt::skip] #[rustfmt::skip]
#[derive(Default)]
pub struct Heading { pub struct Heading {
weight : isize, weight : isize,
renderable : Renderable, renderable : Renderable,
id : IdentifierValue, id : IdentifierValue,
classes : Classes, classes : Classes,
heading_type: HeadingType, heading_type: HeadingType,
html : Markup, html : HtmlMarkup,
display : HeadingDisplay, display : HeadingDisplay,
template : String, template : String,
} }
impl ComponentTrait for Heading { impl ComponentTrait for Heading {
#[rustfmt::skip]
fn new() -> Self { fn new() -> Self {
Heading { Heading::default()
weight : 0,
renderable : render_always,
id : IdentifierValue::new(),
classes : Classes::new(),
heading_type: HeadingType::H1,
html : html! {},
display : HeadingDisplay::Normal,
template : "default".to_owned(),
}
} }
fn handler(&self) -> Handler { fn handler(&self) -> Handler {
@ -57,7 +52,7 @@ impl ComponentTrait for Heading {
} }
fn is_renderable(&self, context: &PageContext) -> bool { fn is_renderable(&self, context: &PageContext) -> bool {
(self.renderable)(context) (self.renderable.check)(context)
} }
fn default_render(&self, _: &mut PageContext) -> Markup { fn default_render(&self, _: &mut PageContext) -> Markup {
@ -126,8 +121,8 @@ impl Heading {
self self
} }
pub fn with_renderable(mut self, renderable: Renderable) -> Self { pub fn with_renderable(mut self, check: IsRenderable) -> Self {
self.alter_renderable(renderable); self.alter_renderable(check);
self self
} }
@ -168,18 +163,18 @@ impl Heading {
self self
} }
pub fn alter_renderable(&mut self, renderable: Renderable) -> &mut Self { pub fn alter_renderable(&mut self, check: IsRenderable) -> &mut Self {
self.renderable = renderable; self.renderable.check = check;
self self
} }
pub fn alter_id(&mut self, id: &str) -> &mut Self { pub fn alter_id(&mut self, id: &str) -> &mut Self {
self.id.with_value(id); self.id.alter_value(id);
self self
} }
pub fn alter_classes(&mut self, op: ClassesOp, classes: &str) -> &mut Self { pub fn alter_classes(&mut self, op: ClassesOp, classes: &str) -> &mut Self {
self.classes.alter(op, classes); self.classes.alter_value(op, classes);
self self
} }
@ -189,14 +184,14 @@ impl Heading {
} }
pub fn alter_html(&mut self, html: Markup) -> &mut Self { pub fn alter_html(&mut self, html: Markup) -> &mut Self {
self.html = html; self.html.markup = html;
self self
} }
#[rustfmt::skip] #[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_value(
ClassesOp::SetDefault, ClassesOp::SetDefault,
match &self.display() { match &self.display() {
HeadingDisplay::XxLarge => "display-2", HeadingDisplay::XxLarge => "display-2",
@ -231,7 +226,7 @@ impl Heading {
} }
pub fn html(&self) -> &Markup { pub fn html(&self) -> &Markup {
&self.html &self.html.markup
} }
pub fn display(&self) -> &HeadingDisplay { pub fn display(&self) -> &HeadingDisplay {

View file

@ -3,22 +3,17 @@ use crate::prelude::*;
pub_const_handler!(COMPONENT_HTML); pub_const_handler!(COMPONENT_HTML);
#[rustfmt::skip] #[rustfmt::skip]
#[derive(Default)]
pub struct Html { pub struct Html {
weight : isize, weight : isize,
renderable: Renderable, renderable: Renderable,
html : Markup, html : HtmlMarkup,
template : String, template : String,
} }
impl ComponentTrait for Html { impl ComponentTrait for Html {
#[rustfmt::skip]
fn new() -> Self { fn new() -> Self {
Html { Html::default()
weight : 0,
renderable: render_always,
html : html! {},
template : "default".to_owned(),
}
} }
fn handler(&self) -> Handler { fn handler(&self) -> Handler {
@ -30,7 +25,7 @@ impl ComponentTrait for Html {
} }
fn is_renderable(&self, context: &PageContext) -> bool { fn is_renderable(&self, context: &PageContext) -> bool {
(self.renderable)(context) (self.renderable.check)(context)
} }
fn default_render(&self, _: &mut PageContext) -> Markup { fn default_render(&self, _: &mut PageContext) -> Markup {
@ -58,8 +53,8 @@ impl Html {
self self
} }
pub fn with_renderable(mut self, renderable: Renderable) -> Self { pub fn with_renderable(mut self, check: IsRenderable) -> Self {
self.alter_renderable(renderable); self.alter_renderable(check);
self self
} }
@ -80,13 +75,13 @@ impl Html {
self self
} }
pub fn alter_renderable(&mut self, renderable: Renderable) -> &mut Self { pub fn alter_renderable(&mut self, check: IsRenderable) -> &mut Self {
self.renderable = renderable; self.renderable.check = check;
self self
} }
pub fn alter_html(&mut self, html: Markup) -> &mut Self { pub fn alter_html(&mut self, html: Markup) -> &mut Self {
self.html = html; self.html.markup = html;
self self
} }
@ -98,7 +93,7 @@ impl Html {
// Html GETTERS. // Html GETTERS.
pub fn html(&self) -> &Markup { pub fn html(&self) -> &Markup {
&self.html &self.html.markup
} }
pub fn template(&self) -> &str { pub fn template(&self) -> &str {

View file

@ -3,6 +3,7 @@ use crate::prelude::*;
pub_const_handler!(COMPONENT_ICON); pub_const_handler!(COMPONENT_ICON);
#[rustfmt::skip] #[rustfmt::skip]
#[derive(Default)]
pub struct Icon { pub struct Icon {
weight : isize, weight : isize,
renderable: Renderable, renderable: Renderable,
@ -11,14 +12,8 @@ pub struct Icon {
} }
impl ComponentTrait for Icon { impl ComponentTrait for Icon {
#[rustfmt::skip]
fn new() -> Self { fn new() -> Self {
Icon { Icon::default().with_classes(ClassesOp::SetDefault, "bi-question-circle-fill")
weight : 0,
renderable: render_always,
icon_name : "question-circle-fill".to_owned(),
classes : Classes::new_with_default("bi-question-circle-fill"),
}
} }
fn handler(&self) -> Handler { fn handler(&self) -> Handler {
@ -30,7 +25,7 @@ impl ComponentTrait for Icon {
} }
fn is_renderable(&self, context: &PageContext) -> bool { fn is_renderable(&self, context: &PageContext) -> bool {
(self.renderable)(context) (self.renderable.check)(context)
} }
fn before_render(&mut self, context: &mut PageContext) { fn before_render(&mut self, context: &mut PageContext) {
@ -64,8 +59,8 @@ impl Icon {
self self
} }
pub fn with_renderable(mut self, renderable: Renderable) -> Self { pub fn with_renderable(mut self, check: IsRenderable) -> Self {
self.alter_renderable(renderable); self.alter_renderable(check);
self self
} }
@ -86,8 +81,8 @@ impl Icon {
self self
} }
pub fn alter_renderable(&mut self, renderable: Renderable) -> &mut Self { pub fn alter_renderable(&mut self, check: IsRenderable) -> &mut Self {
self.renderable = renderable; self.renderable.check = check;
self self
} }
@ -101,7 +96,7 @@ impl Icon {
} }
pub fn alter_classes(&mut self, op: ClassesOp, classes: &str) -> &mut Self { pub fn alter_classes(&mut self, op: ClassesOp, classes: &str) -> &mut Self {
self.classes.alter(op, classes); self.classes.alter_value(op, classes);
self self
} }

View file

@ -3,6 +3,7 @@ use crate::prelude::*;
pub_const_handler!(COMPONENT_IMAGE); pub_const_handler!(COMPONENT_IMAGE);
#[rustfmt::skip] #[rustfmt::skip]
#[derive(Default)]
pub struct Image { pub struct Image {
weight : isize, weight : isize,
renderable: Renderable, renderable: Renderable,
@ -13,16 +14,8 @@ pub struct Image {
} }
impl ComponentTrait for Image { impl ComponentTrait for Image {
#[rustfmt::skip]
fn new() -> Self { fn new() -> Self {
Image { Image::default().with_classes(ClassesOp::SetDefault, "img-fluid")
weight : 0,
renderable: render_always,
id : IdentifierValue::new(),
classes : Classes::new_with_default("img-fluid"),
source : AttributeValue::new(),
template : "default".to_owned(),
}
} }
fn handler(&self) -> Handler { fn handler(&self) -> Handler {
@ -34,7 +27,7 @@ impl ComponentTrait for Image {
} }
fn is_renderable(&self, context: &PageContext) -> bool { fn is_renderable(&self, context: &PageContext) -> bool {
(self.renderable)(context) (self.renderable.check)(context)
} }
fn default_render(&self, _: &mut PageContext) -> Markup { fn default_render(&self, _: &mut PageContext) -> Markup {
@ -67,8 +60,8 @@ impl Image {
self self
} }
pub fn with_renderable(mut self, renderable: Renderable) -> Self { pub fn with_renderable(mut self, check: IsRenderable) -> Self {
self.alter_renderable(renderable); self.alter_renderable(check);
self self
} }
@ -99,23 +92,23 @@ impl Image {
self self
} }
pub fn alter_renderable(&mut self, renderable: Renderable) -> &mut Self { pub fn alter_renderable(&mut self, check: IsRenderable) -> &mut Self {
self.renderable = renderable; self.renderable.check = check;
self self
} }
pub fn alter_id(&mut self, id: &str) -> &mut Self { pub fn alter_id(&mut self, id: &str) -> &mut Self {
self.id.with_value(id); self.id.alter_value(id);
self self
} }
pub fn alter_classes(&mut self, op: ClassesOp, classes: &str) -> &mut Self { pub fn alter_classes(&mut self, op: ClassesOp, classes: &str) -> &mut Self {
self.classes.alter(op, classes); self.classes.alter_value(op, classes);
self self
} }
pub fn alter_source(&mut self, source: &str) -> &mut Self { pub fn alter_source(&mut self, source: &str) -> &mut Self {
self.source.with_value(source); self.source.alter_value(source);
self self
} }

View file

@ -2,19 +2,22 @@ use crate::prelude::*;
pub_const_handler!(COMPONENT_MENUITEM); pub_const_handler!(COMPONENT_MENUITEM);
#[derive(Default)]
pub enum MenuItemType { pub enum MenuItemType {
#[default]
Void,
Label(String), Label(String),
Link(String, String), Link(String, String),
LinkBlank(String, String), LinkBlank(String, String),
Html(Markup), Html(Markup),
Separator,
Submenu(String, Menu), Submenu(String, Menu),
Void, Separator,
} }
// MenuItem. // MenuItem.
#[rustfmt::skip] #[rustfmt::skip]
#[derive(Default)]
pub struct MenuItem { pub struct MenuItem {
weight : isize, weight : isize,
renderable: Renderable, renderable: Renderable,
@ -22,13 +25,8 @@ pub struct MenuItem {
} }
impl ComponentTrait for MenuItem { impl ComponentTrait for MenuItem {
#[rustfmt::skip]
fn new() -> Self { fn new() -> Self {
MenuItem { MenuItem::default()
weight : 0,
renderable: render_always,
item_type : MenuItemType::Void,
}
} }
fn handler(&self) -> Handler { fn handler(&self) -> Handler {
@ -40,11 +38,13 @@ impl ComponentTrait for MenuItem {
} }
fn is_renderable(&self, context: &PageContext) -> bool { fn is_renderable(&self, context: &PageContext) -> bool {
(self.renderable)(context) (self.renderable.check)(context)
} }
fn default_render(&self, context: &mut PageContext) -> Markup { fn default_render(&self, context: &mut PageContext) -> Markup {
match self.item_type() { match self.item_type() {
MenuItemType::Void => html! {
},
MenuItemType::Label(label) => html! { MenuItemType::Label(label) => html! {
li class="label" { a href="#" { (label) } } li class="label" { a href="#" { (label) } }
}, },
@ -70,7 +70,6 @@ impl ComponentTrait for MenuItem {
MenuItemType::Separator => html! { MenuItemType::Separator => html! {
li class="separator" { } li class="separator" { }
}, },
MenuItemType::Void => html! {},
} }
} }
@ -88,7 +87,7 @@ impl MenuItem {
pub fn label(label: &str) -> Self { pub fn label(label: &str) -> Self {
MenuItem { MenuItem {
weight : 0, weight : 0,
renderable: render_always, renderable: Renderable::default(),
item_type : MenuItemType::Label(label.to_owned()), item_type : MenuItemType::Label(label.to_owned()),
} }
} }
@ -97,7 +96,7 @@ impl MenuItem {
pub fn link(label: &str, path: &str) -> Self { pub fn link(label: &str, path: &str) -> Self {
MenuItem { MenuItem {
weight : 0, weight : 0,
renderable: render_always, renderable: Renderable::default(),
item_type : MenuItemType::Link(label.to_owned(), path.to_owned()), item_type : MenuItemType::Link(label.to_owned(), path.to_owned()),
} }
} }
@ -106,7 +105,7 @@ impl MenuItem {
pub fn link_blank(label: &str, path: &str) -> Self { pub fn link_blank(label: &str, path: &str) -> Self {
MenuItem { MenuItem {
weight : 0, weight : 0,
renderable: render_always, renderable: Renderable::default(),
item_type : MenuItemType::LinkBlank(label.to_owned(), path.to_owned()), item_type : MenuItemType::LinkBlank(label.to_owned(), path.to_owned()),
} }
} }
@ -115,29 +114,29 @@ impl MenuItem {
pub fn html(html: Markup) -> Self { pub fn html(html: Markup) -> Self {
MenuItem { MenuItem {
weight : 0, weight : 0,
renderable: render_always, renderable: Renderable::default(),
item_type : MenuItemType::Html(html), item_type : MenuItemType::Html(html),
} }
} }
#[rustfmt::skip]
pub fn separator() -> Self {
MenuItem {
weight : 0,
renderable: render_always,
item_type : MenuItemType::Separator,
}
}
#[rustfmt::skip] #[rustfmt::skip]
pub fn submenu(label: &str, menu: Menu) -> Self { pub fn submenu(label: &str, menu: Menu) -> Self {
MenuItem { MenuItem {
weight : 0, weight : 0,
renderable: render_always, renderable: Renderable::default(),
item_type : MenuItemType::Submenu(label.to_owned(), menu), item_type : MenuItemType::Submenu(label.to_owned(), menu),
} }
} }
#[rustfmt::skip]
pub fn separator() -> Self {
MenuItem {
weight : 0,
renderable: Renderable::default(),
item_type : MenuItemType::Separator,
}
}
// MenuItem BUILDER. // MenuItem BUILDER.
pub fn with_weight(mut self, weight: isize) -> Self { pub fn with_weight(mut self, weight: isize) -> Self {
@ -145,8 +144,8 @@ impl MenuItem {
self self
} }
pub fn with_renderable(mut self, renderable: Renderable) -> Self { pub fn with_renderable(mut self, check: IsRenderable) -> Self {
self.alter_renderable(renderable); self.alter_renderable(check);
self self
} }
@ -157,8 +156,8 @@ impl MenuItem {
self self
} }
pub fn alter_renderable(&mut self, renderable: Renderable) -> &mut Self { pub fn alter_renderable(&mut self, check: IsRenderable) -> &mut Self {
self.renderable = renderable; self.renderable.check = check;
self self
} }
@ -176,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] #[rustfmt::skip]
#[derive(Default)]
pub struct Menu { pub struct Menu {
weight : isize, weight : isize,
renderable: Renderable, renderable: Renderable,
@ -186,16 +186,8 @@ pub struct Menu {
} }
impl ComponentTrait for Menu { impl ComponentTrait for Menu {
#[rustfmt::skip]
fn new() -> Self { fn new() -> Self {
Menu { Menu::default().with_classes(ClassesOp::SetDefault, "sm sm-clean")
weight : 0,
renderable: render_always,
items : ComponentsBundle::new(),
id : IdentifierValue::new(),
classes : Classes::new_with_default("sm sm-clean"),
template : "default".to_owned(),
}
} }
fn handler(&self) -> Handler { fn handler(&self) -> Handler {
@ -207,7 +199,7 @@ impl ComponentTrait for Menu {
} }
fn is_renderable(&self, context: &PageContext) -> bool { fn is_renderable(&self, context: &PageContext) -> bool {
(self.renderable)(context) (self.renderable.check)(context)
} }
fn before_render(&mut self, context: &mut PageContext) { fn before_render(&mut self, context: &mut PageContext) {
@ -259,8 +251,8 @@ impl Menu {
self self
} }
pub fn with_renderable(mut self, renderable: Renderable) -> Self { pub fn with_renderable(mut self, check: IsRenderable) -> Self {
self.alter_renderable(renderable); self.alter_renderable(check);
self self
} }
@ -291,18 +283,18 @@ impl Menu {
self self
} }
pub fn alter_renderable(&mut self, renderable: Renderable) -> &mut Self { pub fn alter_renderable(&mut self, check: IsRenderable) -> &mut Self {
self.renderable = renderable; self.renderable.check = check;
self self
} }
pub fn alter_id(&mut self, id: &str) -> &mut Self { pub fn alter_id(&mut self, id: &str) -> &mut Self {
self.id.with_value(id); self.id.alter_value(id);
self self
} }
pub fn alter_classes(&mut self, op: ClassesOp, classes: &str) -> &mut Self { pub fn alter_classes(&mut self, op: ClassesOp, classes: &str) -> &mut Self {
self.classes.alter(op, classes); self.classes.alter_value(op, classes);
self self
} }

View file

@ -2,38 +2,32 @@ use crate::prelude::*;
pub_const_handler!(COMPONENT_PARAGRAPH); pub_const_handler!(COMPONENT_PARAGRAPH);
#[derive(Default)]
pub enum ParagraphDisplay { pub enum ParagraphDisplay {
#[default]
Normal,
XxLarge, XxLarge,
Large, Large,
Medium, Medium,
Small, Small,
XxSmall, XxSmall,
Normal,
} }
#[rustfmt::skip] #[rustfmt::skip]
#[derive(Default)]
pub struct Paragraph { pub struct Paragraph {
weight : isize, weight : isize,
renderable: Renderable, renderable: Renderable,
id : IdentifierValue, id : IdentifierValue,
classes : Classes, classes : Classes,
html : Markup, html : HtmlMarkup,
display : ParagraphDisplay, display : ParagraphDisplay,
template : String, template : String,
} }
impl ComponentTrait for Paragraph { impl ComponentTrait for Paragraph {
#[rustfmt::skip]
fn new() -> Self { fn new() -> Self {
Paragraph { Paragraph::default()
weight : 0,
renderable: render_always,
id : IdentifierValue::new(),
classes : Classes::new(),
html : html! {},
display : ParagraphDisplay::Normal,
template : "default".to_owned(),
}
} }
fn handler(&self) -> Handler { fn handler(&self) -> Handler {
@ -45,7 +39,7 @@ impl ComponentTrait for Paragraph {
} }
fn is_renderable(&self, context: &PageContext) -> bool { fn is_renderable(&self, context: &PageContext) -> bool {
(self.renderable)(context) (self.renderable.check)(context)
} }
fn default_render(&self, _: &mut PageContext) -> Markup { fn default_render(&self, _: &mut PageContext) -> Markup {
@ -75,8 +69,8 @@ impl Paragraph {
self self
} }
pub fn with_renderable(mut self, renderable: Renderable) -> Self { pub fn with_renderable(mut self, check: IsRenderable) -> Self {
self.alter_renderable(renderable); self.alter_renderable(check);
self self
} }
@ -112,30 +106,30 @@ impl Paragraph {
self self
} }
pub fn alter_renderable(&mut self, renderable: Renderable) -> &mut Self { pub fn alter_renderable(&mut self, check: IsRenderable) -> &mut Self {
self.renderable = renderable; self.renderable.check = check;
self self
} }
pub fn alter_id(&mut self, id: &str) -> &mut Self { pub fn alter_id(&mut self, id: &str) -> &mut Self {
self.id.with_value(id); self.id.alter_value(id);
self self
} }
pub fn alter_classes(&mut self, op: ClassesOp, classes: &str) -> &mut Self { pub fn alter_classes(&mut self, op: ClassesOp, classes: &str) -> &mut Self {
self.classes.alter(op, classes); self.classes.alter_value(op, classes);
self self
} }
pub fn alter_html(&mut self, html: Markup) -> &mut Self { pub fn alter_html(&mut self, html: Markup) -> &mut Self {
self.html = html; self.html.markup = html;
self self
} }
#[rustfmt::skip] #[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_value(
ClassesOp::SetDefault, ClassesOp::SetDefault,
match &self.display() { match &self.display() {
ParagraphDisplay::XxLarge => "fs-2", ParagraphDisplay::XxLarge => "fs-2",
@ -165,7 +159,7 @@ impl Paragraph {
} }
pub fn html(&self) -> &Markup { pub fn html(&self) -> &Markup {
&self.html &self.html.markup
} }
pub fn display(&self) -> &ParagraphDisplay { pub fn display(&self) -> &ParagraphDisplay {

View file

@ -8,14 +8,8 @@ mod all;
pub use all::add_component_to; pub use all::add_component_to;
pub(crate) use all::common_components; pub(crate) use all::common_components;
use crate::response::page::PageContext; mod renderable;
pub use renderable::{IsRenderable, Renderable};
pub type Renderable = fn(_: &PageContext) -> bool; mod html_markup;
pub use html_markup::HtmlMarkup;
pub fn render_always(_: &PageContext) -> bool {
true
}
pub fn render_never(_: &PageContext) -> bool {
false
}

View file

@ -9,7 +9,7 @@ pub struct ComponentsBundle(Vec<Arc<RwLock<dyn ComponentTrait>>>);
impl ComponentsBundle { impl ComponentsBundle {
pub fn new() -> Self { pub fn new() -> Self {
ComponentsBundle(Vec::new()) ComponentsBundle::default()
} }
pub fn new_with(component: impl ComponentTrait) -> Self { pub fn new_with(component: impl ComponentTrait) -> Self {

View file

@ -0,0 +1,13 @@
use crate::html::{html, Markup};
pub struct HtmlMarkup {
pub markup: Markup,
}
impl Default for HtmlMarkup {
fn default() -> Self {
HtmlMarkup {
markup: html! {},
}
}
}

View file

@ -0,0 +1,19 @@
use crate::response::page::PageContext;
pub type IsRenderable = fn(&PageContext) -> bool;
pub struct Renderable {
pub check: IsRenderable,
}
impl Default for Renderable {
fn default() -> Self {
Renderable {
check: render_always,
}
}
}
fn render_always(_: &PageContext) -> bool {
true
}

View file

@ -15,4 +15,4 @@ mod identifier;
pub use identifier::IdentifierValue; pub use identifier::IdentifierValue;
mod classes; mod classes;
pub use classes::{ClassValue, Classes, ClassesOp}; pub use classes::{Classes, ClassesOp};

View file

@ -1,14 +1,16 @@
use super::AssetsTrait; use super::AssetsTrait;
use crate::html::{html, Markup}; use crate::html::{html, Markup};
#[derive(PartialEq)] #[derive(Default, PartialEq)]
pub enum ModeJS { pub enum ModeJS {
Async, Async,
#[default]
Defer, Defer,
Normal, Normal,
} }
#[rustfmt::skip] #[rustfmt::skip]
#[derive(Default)]
pub struct JavaScript { pub struct JavaScript {
source : &'static str, source : &'static str,
prefix : &'static str, prefix : &'static str,
@ -38,14 +40,10 @@ impl AssetsTrait for JavaScript {
} }
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 : "", ..Default::default()
version: "",
weight : 0,
mode : ModeJS::Defer,
} }
} }

View file

@ -9,6 +9,7 @@ pub enum TargetMedia {
} }
#[rustfmt::skip] #[rustfmt::skip]
#[derive(Default)]
pub struct StyleSheet { pub struct StyleSheet {
source : &'static str, source : &'static str,
prefix : &'static str, prefix : &'static str,
@ -37,14 +38,10 @@ 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,
prefix : "", ..Default::default()
version: "",
media : None,
weight : 0,
} }
} }

View file

@ -3,20 +3,25 @@ pub struct AttributeValue(String);
impl AttributeValue { impl AttributeValue {
pub fn new() -> Self { pub fn new() -> Self {
AttributeValue("".to_owned()) AttributeValue::default()
} }
pub fn new_with_value(value: &str) -> Self { // AttributeValue BUILDER.
let mut attr = Self::new();
attr.with_value(value); pub fn with_value(mut self, value: &str) -> Self {
attr self.alter_value(value);
self
} }
pub fn with_value(&mut self, value: &str) -> &mut Self { // AttributeValue ALTER.
pub fn alter_value(&mut self, value: &str) -> &mut Self {
self.0 = value.trim().to_owned(); self.0 = value.trim().to_owned();
self self
} }
// AttributeValue GETTERS.
pub fn get(&self) -> Option<String> { pub fn get(&self) -> Option<String> {
if self.0.is_empty() { if self.0.is_empty() {
None None

View file

@ -1,14 +1,12 @@
use crate::concat_string; use crate::concat_string;
pub type ClassValue = &'static str;
pub enum ClassesOp { pub enum ClassesOp {
Add, Add,
AddAfter(ClassValue), AddAfter(&'static str),
AddBefore(ClassValue), AddBefore(&'static str),
AddFirst, AddFirst,
Remove, Remove,
Replace(ClassValue), Replace(&'static str),
Reset, Reset,
SetDefault, SetDefault,
SetDefaultIfEmpty, SetDefaultIfEmpty,
@ -22,21 +20,20 @@ pub struct Classes {
} }
impl Classes { impl Classes {
#[rustfmt::skip]
pub fn new() -> Self { pub fn new() -> Self {
Classes { Classes::default()
default: "".to_owned(),
added : "".to_owned(),
}
} }
pub fn new_with_default(default: &str) -> Self { // Classes BUILDER.
let mut classes = Self::new();
classes.alter(ClassesOp::SetDefault, default); pub fn with_value(mut self, op: ClassesOp, classes: &str) -> Self {
classes self.alter_value(op, classes);
self
} }
pub fn alter(&mut self, op: ClassesOp, classes: &str) -> &mut Self { // Classes ALTER.
pub fn alter_value(&mut self, op: ClassesOp, classes: &str) -> &mut Self {
let classes = classes.trim(); let classes = classes.trim();
match op { match op {
ClassesOp::Add => { ClassesOp::Add => {
@ -101,6 +98,8 @@ impl Classes {
self self
} }
// Classes GETTERS.
pub fn get(&self) -> Option<String> { pub fn get(&self) -> Option<String> {
if self.default.is_empty() && self.added.is_empty() { if self.default.is_empty() && self.added.is_empty() {
None None

View file

@ -5,9 +5,11 @@ pub struct Favicon(Vec<String>);
impl Favicon { impl Favicon {
pub fn new() -> Self { pub fn new() -> Self {
Favicon(Vec::new()) Favicon::default()
} }
// Favicon BUILDER.
pub fn with_icon(self, image: &str) -> Self { pub fn with_icon(self, image: &str) -> Self {
self.add_item("icon", image, "", "") self.add_item("icon", image, "", "")
} }
@ -72,6 +74,8 @@ impl Favicon {
self self
} }
// Favicon RENDER.
pub(crate) fn render(&self) -> Markup { pub(crate) fn render(&self) -> Markup {
html! { html! {
@for item in &self.0 { @for item in &self.0 {

View file

@ -3,20 +3,25 @@ pub struct IdentifierValue(String);
impl IdentifierValue { impl IdentifierValue {
pub fn new() -> Self { pub fn new() -> Self {
IdentifierValue("".to_owned()) IdentifierValue::default()
} }
pub fn new_with_value(value: &str) -> Self { // IdentifierValue BUILDER.
let mut id = Self::new();
id.with_value(value); pub fn with_value(mut self, value: &str) -> Self {
id self.alter_value(value);
self
} }
pub fn with_value(&mut self, value: &str) -> &Self { // IdentifierValue ALTER.
pub fn alter_value(&mut self, value: &str) -> &mut Self {
self.0 = value.trim().replace(' ', "_"); self.0 = value.trim().replace(' ', "_");
self self
} }
// IdentifierValue GETTERS.
pub fn get(&self) -> Option<String> { pub fn get(&self) -> Option<String> {
if self.0.is_empty() { if self.0.is_empty() {
None None

View file

@ -23,9 +23,9 @@ pub struct PageContext {
id_counter : usize, id_counter : usize,
} }
impl PageContext { impl Default for PageContext {
#[rustfmt::skip] #[rustfmt::skip]
pub fn new() -> Self { fn default() -> Self {
PageContext { PageContext {
theme : *DEFAULT_THEME, theme : *DEFAULT_THEME,
favicon : None, favicon : None,
@ -37,6 +37,12 @@ impl PageContext {
id_counter : 0, id_counter : 0,
} }
} }
}
impl PageContext {
pub fn new() -> Self {
PageContext::default()
}
pub fn alter(&mut self, op: PageOp) -> &mut Self { pub fn alter(&mut self, op: PageOp) -> &mut Self {
match op { match op {

View file

@ -53,26 +53,32 @@ pub struct Page {
template : String, template : String,
} }
impl Page { impl Default for Page {
#[rustfmt::skip] #[rustfmt::skip]
pub fn new() -> Self { fn default() -> Self {
Page { Page {
context : PageContext::new(), context : PageContext::new(),
language : match &*DEFAULT_LANGUAGE { language : match &*DEFAULT_LANGUAGE {
Some(language) => AttributeValue::new_with_value(language), Some(language) => AttributeValue::new().with_value(language),
_ => AttributeValue::new(), _ => AttributeValue::new(),
}, },
direction : match &*DEFAULT_DIRECTION { direction : match &*DEFAULT_DIRECTION {
Some(direction) => AttributeValue::new_with_value(direction), Some(direction) => AttributeValue::new().with_value(direction),
_ => AttributeValue::new(), _ => AttributeValue::new(),
}, },
title : AttributeValue::new(), title : AttributeValue::new(),
description : AttributeValue::new(), description : AttributeValue::new(),
body_classes: Classes::new_with_default("body"), body_classes: Classes::new().with_value(ClassesOp::SetDefault, "body"),
regions : common_components(), regions : common_components(),
template : "default".to_owned(), template : "default".to_owned(),
} }
} }
}
impl Page {
pub fn new() -> Self {
Page::default()
}
// Page BUILDER. // Page BUILDER.
@ -129,12 +135,12 @@ impl Page {
} }
pub fn alter_language(&mut self, language: &str) -> &mut Self { pub fn alter_language(&mut self, language: &str) -> &mut Self {
self.language.with_value(language); self.language.alter_value(language);
self self
} }
pub fn alter_direction(&mut self, dir: TextDirection) -> &mut Self { pub fn alter_direction(&mut self, dir: TextDirection) -> &mut Self {
self.direction.with_value(match dir { self.direction.alter_value(match dir {
TextDirection::Auto => "auto", TextDirection::Auto => "auto",
TextDirection::LeftToRight => "ltr", TextDirection::LeftToRight => "ltr",
TextDirection::RightToLeft => "rtl", TextDirection::RightToLeft => "rtl",
@ -143,17 +149,17 @@ impl Page {
} }
pub fn alter_title(&mut self, title: &str) -> &mut Self { pub fn alter_title(&mut self, title: &str) -> &mut Self {
self.title.with_value(title); self.title.alter_value(title);
self self
} }
pub fn alter_description(&mut self, description: &str) -> &mut Self { pub fn alter_description(&mut self, description: &str) -> &mut Self {
self.description.with_value(description); self.description.alter_value(description);
self self
} }
pub fn alter_body_classes(&mut self, op: ClassesOp, classes: &str) -> &mut Self { pub fn alter_body_classes(&mut self, op: ClassesOp, classes: &str) -> &mut Self {
self.body_classes.alter(op, classes); self.body_classes.alter_value(op, classes);
self self
} }

View file

@ -7,7 +7,7 @@ use std::collections::HashMap;
include!(concat!(env!("OUT_DIR"), "/mdbook.rs")); include!(concat!(env!("OUT_DIR"), "/mdbook.rs"));
static MDBOOK: LazyStatic<HashMap<&'static str, Resource>> = LazyStatic::new(|| generate()); static MDBOOK: LazyStatic<HashMap<&'static str, Resource>> = LazyStatic::new(generate);
pub_const_handler!(MODULE_MDBOOK); pub_const_handler!(MODULE_MDBOOK);
@ -38,14 +38,8 @@ async fn mdbook_page(request: app::HttpRequest) -> ResultPage<Markup, FatalError
Some(title) => title, Some(title) => title,
_ => "Documentación", _ => "Documentación",
}; };
let _print = match extract("Print", html) { let _print = matches!(extract("Print", html), Some("enabled"));
Some("enabled") => true, let _mathjax = matches!(extract("MathJax", html), Some("supported"));
_ => false,
};
let _mathjax = match extract("MathJax", html) {
Some("supported") => true,
_ => false,
};
let beginning = { let beginning = {
let separator = "<!-- mdBook -->"; let separator = "<!-- mdBook -->";
match html.find(separator) { match html.find(separator) {