Mejora disposición de propiedades de componentes

This commit is contained in:
Manuel Cillero 2022-07-08 01:21:33 +02:00
parent 743e32b0f6
commit 88a59780c3
21 changed files with 554 additions and 453 deletions

View file

@ -3,34 +3,34 @@ use super::l;
pub async fn summary() -> app::Result<Markup> { pub async fn summary() -> app::Result<Markup> {
let top_menu = Menu::new() let top_menu = Menu::new()
.add(MenuItem::label(l("module_name").as_str())) .with_item(MenuItem::label(l("module_name").as_str()))
.add(MenuItem::link("Opción 2", "https://www.google.es")) .with_item(MenuItem::link("Opción 2", "https://www.google.es"))
.add(MenuItem::link_blank("Opción 3", "https://www.google.es")) .with_item(MenuItem::link_blank("Opción 3", "https://www.google.es"))
.add(MenuItem::submenu("Submenú 1", Menu::new() .with_item(MenuItem::submenu("Submenú 1", Menu::new()
.add(MenuItem::label("Opción 1")) .with_item(MenuItem::label("Opción 1"))
.add(MenuItem::label("Opción 2")) .with_item(MenuItem::label("Opción 2"))
)) ))
.add(MenuItem::separator()) .with_item(MenuItem::separator())
.add(MenuItem::submenu("Submenú 2", Menu::new() .with_item(MenuItem::submenu("Submenú 2", Menu::new()
.add(MenuItem::label("Opción 1")) .with_item(MenuItem::label("Opción 1"))
.add(MenuItem::label("Opción 2")) .with_item(MenuItem::label("Opción 2"))
)) ))
.add(MenuItem::label("Opción 4")); .with_item(MenuItem::label("Opción 4"));
let side_menu = Menu::new() let side_menu = Menu::new()
.add(MenuItem::label("Opción 1")) .with_item(MenuItem::label("Opción 1"))
.add(MenuItem::link("Opción 2", "https://www.google.es")) .with_item(MenuItem::link("Opción 2", "https://www.google.es"))
.add(MenuItem::link_blank("Opción 3", "https://www.google.es")) .with_item(MenuItem::link_blank("Opción 3", "https://www.google.es"))
.add(MenuItem::submenu("Submenú 1", Menu::new() .with_item(MenuItem::submenu("Submenú 1", Menu::new()
.add(MenuItem::label("Opción 1")) .with_item(MenuItem::label("Opción 1"))
.add(MenuItem::label("Opción 2")) .with_item(MenuItem::label("Opción 2"))
)) ))
.add(MenuItem::separator()) .with_item(MenuItem::separator())
.add(MenuItem::submenu("Submenú 2", Menu::new() .with_item(MenuItem::submenu("Submenú 2", Menu::new()
.add(MenuItem::label("Opción 1")) .with_item(MenuItem::label("Opción 1"))
.add(MenuItem::label("Opción 2")) .with_item(MenuItem::label("Opción 2"))
)) ))
.add(MenuItem::label("Opción 4")); .with_item(MenuItem::label("Opción 4"));
Page::new() Page::new()
@ -41,11 +41,11 @@ pub async fn summary() -> app::Result<Markup> {
.add_to("top-menu", top_menu) .add_to("top-menu", top_menu)
.add_to("content", grid::Row::new() .add_to("content", grid::Row::new()
.add_column(grid::Column::new() .with_column(grid::Column::new()
.add(side_menu) .with_component(side_menu)
) )
.add_column(grid::Column::new() .with_column(grid::Column::new()
.add(Chunck::with(html! { .with_component(Chunck::with(html! {
p { "Columna 2"} p { "Columna 2"}
})) }))
) )

View file

@ -42,7 +42,7 @@ async fn login() -> app::Result<Markup> {
) )
.add_to("content", Container::new() .add_to("content", Container::new()
.with_id("welcome") .with_id("welcome")
.add(form_login()) .with_component(form_login())
) )
.render() .render()
} }
@ -50,7 +50,7 @@ async fn login() -> app::Result<Markup> {
fn form_login() -> Form { fn form_login() -> Form {
Form::new() Form::new()
.with_id("user-login") .with_id("user-login")
.add(form::Input::textfield() .with_element(form::Input::textfield()
.with_name("name") .with_name("name")
.with_label(l("username").as_str()) .with_label(l("username").as_str())
.with_help_text(t("username_help", &args![ .with_help_text(t("username_help", &args![
@ -58,10 +58,10 @@ fn form_login() -> Form {
]).as_str()) ]).as_str())
.with_autofocus(true) .with_autofocus(true)
) )
.add(form::Input::password() .with_element(form::Input::password()
.with_name("pass") .with_name("pass")
.with_label(l("password").as_str()) .with_label(l("password").as_str())
.with_help_text(l("password_help").as_str()) .with_help_text(l("password_help").as_str())
) )
.add(form::Button::submit(l("login").as_str())) .with_element(form::Button::submit(l("login").as_str()))
} }

View file

@ -21,15 +21,15 @@ pub type AnchorIcon = ComponentsBundle;
pub struct Anchor { pub struct Anchor {
renderable : fn() -> bool, renderable : fn() -> bool,
weight : isize, weight : isize,
id : IdentifierValue,
classes : Classes,
spaces : Spaces,
anchor_type: AnchorType, anchor_type: AnchorType,
href : AttributeValue, href : AttributeValue,
html : Markup, html : Markup,
left_icon : AnchorIcon, left_icon : AnchorIcon,
right_icon : AnchorIcon, right_icon : AnchorIcon,
target : AnchorTarget, target : AnchorTarget,
id : IdentifierValue,
classes : Classes,
spaces : Spaces,
template : String, template : String,
} }
@ -38,15 +38,15 @@ impl ComponentTrait for Anchor {
Anchor { Anchor {
renderable : render_always, renderable : render_always,
weight : 0, weight : 0,
id : IdentifierValue::new(),
classes : Classes::new(),
spaces : Spaces::new(),
anchor_type: AnchorType::Link, anchor_type: AnchorType::Link,
href : AttributeValue::new(), href : AttributeValue::new(),
html : html! {}, html : html! {},
left_icon : AnchorIcon::new(), left_icon : AnchorIcon::new(),
right_icon : AnchorIcon::new(), right_icon : AnchorIcon::new(),
target : AnchorTarget::Default, target : AnchorTarget::Default,
id : IdentifierValue::new(),
classes : Classes::new(),
spaces : Spaces::new(),
template : "default".to_owned(), template : "default".to_owned(),
} }
} }
@ -120,6 +120,21 @@ impl Anchor {
self self
} }
pub fn with_id(mut self, id: &str) -> Self {
self.alter_id(id);
self
}
pub fn with_classes(mut self, classes: &str, op: ClassesOp) -> Self {
self.alter_classes(classes, op);
self
}
pub fn with_spaces(mut self, spaces: &[SpaceSet]) -> Self {
self.alter_spaces(spaces);
self
}
pub fn with_type(mut self, anchor_type: AnchorType) -> Self { pub fn with_type(mut self, anchor_type: AnchorType) -> Self {
self.alter_type(anchor_type); self.alter_type(anchor_type);
self self
@ -150,21 +165,6 @@ impl Anchor {
self self
} }
pub fn with_id(mut self, id: &str) -> Self {
self.alter_id(id);
self
}
pub fn with_classes(mut self, classes: &str, op: ClassesOp) -> Self {
self.alter_classes(classes, op);
self
}
pub fn with_spaces(mut self, spaces: &[SpaceSet]) -> Self {
self.alter_spaces(spaces);
self
}
pub fn using_template(mut self, template: &str) -> Self { pub fn using_template(mut self, template: &str) -> Self {
self.alter_template(template); self.alter_template(template);
self self
@ -182,6 +182,21 @@ impl Anchor {
self self
} }
pub fn alter_id(&mut self, id: &str) -> &mut Self {
self.id.with_value(id);
self
}
pub fn alter_classes(&mut self, classes: &str, op: ClassesOp) -> &mut Self {
self.classes.alter(classes, op);
self
}
pub fn alter_spaces(&mut self, spaces: &[SpaceSet]) -> &mut Self {
self.spaces.add(spaces);
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(match self.anchor_type { self.classes.alter(match self.anchor_type {
@ -218,21 +233,6 @@ impl Anchor {
self self
} }
pub fn alter_id(&mut self, id: &str) -> &mut Self {
self.id.with_value(id);
self
}
pub fn alter_classes(&mut self, classes: &str, op: ClassesOp) -> &mut Self {
self.classes.alter(classes, op);
self
}
pub fn alter_spaces(&mut self, spaces: &[SpaceSet]) -> &mut Self {
self.spaces.add(spaces);
self
}
pub fn alter_template(&mut self, template: &str) -> &mut Self { pub fn alter_template(&mut self, template: &str) -> &mut Self {
self.template = template.to_owned(); self.template = template.to_owned();
self self
@ -240,6 +240,18 @@ impl Anchor {
// Anchor GETTERS. // Anchor GETTERS.
pub fn id(&self) -> &IdentifierValue {
&self.id
}
pub fn classes(&self) -> &Classes {
&self.classes
}
pub fn spaces(&self) -> &Spaces {
&self.spaces
}
pub fn anchor_type(&self) -> &AnchorType { pub fn anchor_type(&self) -> &AnchorType {
&self.anchor_type &self.anchor_type
} }
@ -264,18 +276,6 @@ impl Anchor {
&self.target &self.target
} }
pub fn id(&self) -> &IdentifierValue {
&self.id
}
pub fn classes(&self) -> &Classes {
&self.classes
}
pub fn spaces(&self) -> &Spaces {
&self.spaces
}
pub fn template(&self) -> &str { pub fn template(&self) -> &str {
self.template.as_str() self.template.as_str()
} }

View file

@ -5,10 +5,10 @@ pub const BLOCK_COMPONENT: &str = "pagetop::component::block";
pub struct Block { pub struct Block {
renderable: fn() -> bool, renderable: fn() -> bool,
weight : isize, weight : isize,
components: ComponentsBundle,
title : AttributeValue,
id : IdentifierValue, id : IdentifierValue,
classes : Classes, classes : Classes,
title : AttributeValue,
components: ComponentsBundle,
template : String, template : String,
} }
@ -17,10 +17,10 @@ impl ComponentTrait for Block {
Block { Block {
renderable: render_always, renderable: render_always,
weight : 0, weight : 0,
components: ComponentsBundle::new(),
title : AttributeValue::new(),
id : IdentifierValue::new(), id : IdentifierValue::new(),
classes : Classes::new_with_default("block"), classes : Classes::new_with_default("block"),
title : AttributeValue::new(),
components: ComponentsBundle::new(),
template : "default".to_owned(), template : "default".to_owned(),
} }
} }
@ -63,17 +63,6 @@ impl ComponentTrait for Block {
impl Block { impl Block {
// Block CONTAINER.
pub fn add(mut self, component: impl ComponentTrait) -> Self {
self.components.add(component);
self
}
pub fn components(&self) -> &ComponentsBundle {
&self.components
}
// Block BUILDER. // Block BUILDER.
pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self { pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self {
@ -86,11 +75,6 @@ impl Block {
self self
} }
pub fn with_title(mut self, title: &str) -> Self {
self.alter_title(title);
self
}
pub fn with_id(mut self, id: &str) -> Self { pub fn with_id(mut self, id: &str) -> Self {
self.alter_id(id); self.alter_id(id);
self self
@ -101,6 +85,16 @@ impl Block {
self self
} }
pub fn with_title(mut self, title: &str) -> Self {
self.alter_title(title);
self
}
pub fn with_component(mut self, component: impl ComponentTrait) -> Self {
self.alter_component(component);
self
}
pub fn using_template(mut self, template: &str) -> Self { pub fn using_template(mut self, template: &str) -> Self {
self.alter_template(template); self.alter_template(template);
self self
@ -118,11 +112,6 @@ impl Block {
self self
} }
pub fn alter_title(&mut self, title: &str) -> &mut Self {
self.title.with_value(title);
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.with_value(id);
self self
@ -133,6 +122,16 @@ impl Block {
self self
} }
pub fn alter_title(&mut self, title: &str) -> &mut Self {
self.title.with_value(title);
self
}
pub fn alter_component(&mut self, component: impl ComponentTrait) -> &mut Self {
self.components.add(component);
self
}
pub fn alter_template(&mut self, template: &str) -> &mut Self { pub fn alter_template(&mut self, template: &str) -> &mut Self {
self.template = template.to_owned(); self.template = template.to_owned();
self self
@ -140,10 +139,6 @@ impl Block {
// Block GETTERS. // Block GETTERS.
pub fn title(&self) -> &AttributeValue {
&self.title
}
pub fn id(&self) -> &IdentifierValue { pub fn id(&self) -> &IdentifierValue {
&self.id &self.id
} }
@ -152,6 +147,14 @@ impl Block {
&self.classes &self.classes
} }
pub fn title(&self) -> &AttributeValue {
&self.title
}
pub fn components(&self) -> &ComponentsBundle {
&self.components
}
pub fn template(&self) -> &str { pub fn template(&self) -> &str {
self.template.as_str() self.template.as_str()
} }

View file

@ -5,27 +5,27 @@ pub const CONTAINER_COMPONENT: &str = "pagetop::component::container";
pub enum ContainerType { Header, Footer, Main, Section, Wrapper } pub enum ContainerType { Header, Footer, Main, Section, Wrapper }
pub struct Container { pub struct Container {
renderable : fn() -> bool, renderable : fn() -> bool,
weight : isize, weight : isize,
components : ComponentsBundle, id : IdentifierValue,
container : ContainerType, classes : Classes,
id : IdentifierValue, inner_classes : Classes,
classes : Classes, container_type: ContainerType,
inner_classes: Classes, components : ComponentsBundle,
template : String, template : String,
} }
impl ComponentTrait for Container { impl ComponentTrait for Container {
fn new() -> Self { fn new() -> Self {
Container { Container {
renderable : render_always, renderable : render_always,
weight : 0, weight : 0,
components : ComponentsBundle::new(), id : IdentifierValue::new(),
container : ContainerType::Wrapper, classes : Classes::new_with_default("container"),
id : IdentifierValue::new(), inner_classes : Classes::new_with_default("container"),
classes : Classes::new_with_default("container"), container_type: ContainerType::Wrapper,
inner_classes: Classes::new_with_default("container"), components : ComponentsBundle::new(),
template : "default".to_owned(), template : "default".to_owned(),
} }
} }
@ -91,39 +91,28 @@ impl ComponentTrait for Container {
impl Container { impl Container {
pub fn header() -> Self { pub fn header() -> Self {
let mut c = Container::new().with_classes("header", ClassesOp::SetDefault); let mut c = Container::new().with_classes("header", ClassesOp::SetDefault);
c.container = ContainerType::Header; c.container_type = ContainerType::Header;
c c
} }
pub fn footer() -> Self { pub fn footer() -> Self {
let mut c = Container::new().with_classes("footer", ClassesOp::SetDefault); let mut c = Container::new().with_classes("footer", ClassesOp::SetDefault);
c.container = ContainerType::Footer; c.container_type = ContainerType::Footer;
c c
} }
pub fn main() -> Self { pub fn main() -> Self {
let mut c = Container::new().with_classes("main", ClassesOp::SetDefault); let mut c = Container::new().with_classes("main", ClassesOp::SetDefault);
c.container = ContainerType::Main; c.container_type = ContainerType::Main;
c c
} }
pub fn section() -> Self { pub fn section() -> Self {
let mut c = Container::new().with_classes("section", ClassesOp::SetDefault); let mut c = Container::new().with_classes("section", ClassesOp::SetDefault);
c.container = ContainerType::Section; c.container_type = ContainerType::Section;
c c
} }
// Container CONTAINER.
pub fn add(mut self, component: impl ComponentTrait) -> Self {
self.components.add(component);
self
}
pub fn components(&self) -> &ComponentsBundle {
&self.components
}
// Container BUILDER. // Container BUILDER.
pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self { pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self {
@ -151,6 +140,11 @@ impl Container {
self self
} }
pub fn with_component(mut self, component: impl ComponentTrait) -> Self {
self.alter_component(component);
self
}
pub fn using_template(mut self, template: &str) -> Self { pub fn using_template(mut self, template: &str) -> Self {
self.alter_template(template); self.alter_template(template);
self self
@ -183,6 +177,11 @@ impl Container {
self self
} }
pub fn alter_component(&mut self, component: impl ComponentTrait) -> &mut Self {
self.components.add(component);
self
}
pub fn alter_template(&mut self, template: &str) -> &mut Self { pub fn alter_template(&mut self, template: &str) -> &mut Self {
self.template = template.to_owned(); self.template = template.to_owned();
self self
@ -190,10 +189,6 @@ impl Container {
// Container GETTERS. // Container GETTERS.
pub fn container_type(&self) -> &ContainerType {
&self.container
}
pub fn id(&self) -> &IdentifierValue { pub fn id(&self) -> &IdentifierValue {
&self.id &self.id
} }
@ -206,6 +201,14 @@ impl Container {
&self.inner_classes &self.inner_classes
} }
pub fn container_type(&self) -> &ContainerType {
&self.container_type
}
pub fn components(&self) -> &ComponentsBundle {
&self.components
}
pub fn template(&self) -> &str { pub fn template(&self) -> &str {
self.template.as_str() self.template.as_str()
} }

View file

@ -7,12 +7,12 @@ pub enum ButtonType {Button, Reset, Submit}
pub struct Button { pub struct Button {
renderable : fn() -> bool, renderable : fn() -> bool,
weight : isize, weight : isize,
classes : Classes,
button_type: ButtonType, button_type: ButtonType,
name : AttributeValue, name : AttributeValue,
value : AttributeValue, value : AttributeValue,
autofocus : AttributeValue, autofocus : AttributeValue,
disabled : AttributeValue, disabled : AttributeValue,
classes : Classes,
template : String, template : String,
} }
@ -21,12 +21,12 @@ impl ComponentTrait for Button {
Button { Button {
renderable : render_always, renderable : render_always,
weight : 0, weight : 0,
classes : Classes::new_with_default("btn btn-primary"),
button_type: ButtonType::Button, button_type: ButtonType::Button,
name : AttributeValue::new(), name : AttributeValue::new(),
value : AttributeValue::new(), value : AttributeValue::new(),
autofocus : AttributeValue::new(), autofocus : AttributeValue::new(),
disabled : AttributeValue::new(), disabled : AttributeValue::new(),
classes : Classes::new_with_default("btn btn-primary"),
template : "default".to_owned(), template : "default".to_owned(),
} }
.with_classes("form-button", ClassesOp::AddFirst) .with_classes("form-button", ClassesOp::AddFirst)
@ -114,6 +114,11 @@ impl Button {
self self
} }
pub fn with_classes(mut self, classes: &str, op: ClassesOp) -> Self {
self.alter_classes(classes, op);
self
}
pub fn with_name(mut self, name: &str) -> Self { pub fn with_name(mut self, name: &str) -> Self {
self.alter_name(name); self.alter_name(name);
self self
@ -134,11 +139,6 @@ impl Button {
self self
} }
pub fn with_classes(mut self, classes: &str, op: ClassesOp) -> Self {
self.alter_classes(classes, op);
self
}
pub fn using_template(mut self, template: &str) -> Self { pub fn using_template(mut self, template: &str) -> Self {
self.alter_template(template); self.alter_template(template);
self self
@ -156,6 +156,11 @@ impl Button {
self self
} }
pub fn alter_classes(&mut self, classes: &str, op: ClassesOp) -> &mut Self {
self.classes.alter(classes, op);
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.with_value(name);
self self
@ -182,11 +187,6 @@ impl Button {
self self
} }
pub fn alter_classes(&mut self, classes: &str, op: ClassesOp) -> &mut Self {
self.classes.alter(classes, op);
self
}
pub fn alter_template(&mut self, template: &str) -> &mut Self { pub fn alter_template(&mut self, template: &str) -> &mut Self {
self.template = template.to_owned(); self.template = template.to_owned();
self self
@ -194,6 +194,10 @@ impl Button {
// Button GETTERS. // Button GETTERS.
pub fn classes(&self) -> &Classes {
&self.classes
}
pub fn button_type(&self) -> &ButtonType { pub fn button_type(&self) -> &ButtonType {
&self.button_type &self.button_type
} }
@ -214,10 +218,6 @@ impl Button {
&self.disabled &self.disabled
} }
pub fn classes(&self) -> &Classes {
&self.classes
}
pub fn template(&self) -> &str { pub fn template(&self) -> &str {
self.template.as_str() self.template.as_str()
} }

View file

@ -5,6 +5,7 @@ pub const DATE_COMPONENT: &str = "pagetop::component::form::date";
pub struct Date { pub struct Date {
renderable : fn() -> bool, renderable : fn() -> bool,
weight : isize, weight : isize,
classes : Classes,
name : AttributeValue, name : AttributeValue,
value : AttributeValue, value : AttributeValue,
label : AttributeValue, label : AttributeValue,
@ -15,7 +16,6 @@ pub struct Date {
readonly : AttributeValue, readonly : AttributeValue,
required : AttributeValue, required : AttributeValue,
help_text : AttributeValue, help_text : AttributeValue,
classes : Classes,
template : String, template : String,
} }
@ -24,6 +24,7 @@ impl ComponentTrait for Date {
Date { Date {
renderable : render_always, renderable : render_always,
weight : 0, weight : 0,
classes : Classes::new_with_default("form-item"),
name : AttributeValue::new(), name : AttributeValue::new(),
value : AttributeValue::new(), value : AttributeValue::new(),
label : AttributeValue::new(), label : AttributeValue::new(),
@ -34,7 +35,6 @@ impl ComponentTrait for Date {
readonly : AttributeValue::new(), readonly : AttributeValue::new(),
required : AttributeValue::new(), required : AttributeValue::new(),
help_text : AttributeValue::new(), help_text : AttributeValue::new(),
classes : Classes::new_with_default("form-item"),
template : "default".to_owned(), template : "default".to_owned(),
} }
.with_classes("form-type-date", ClassesOp::AddFirst) .with_classes("form-type-date", ClassesOp::AddFirst)
@ -114,6 +114,11 @@ impl Date {
self self
} }
pub fn with_classes(mut self, classes: &str, op: ClassesOp) -> Self {
self.alter_classes(classes, op);
self
}
pub fn with_name(mut self, name: &str) -> Self { pub fn with_name(mut self, name: &str) -> Self {
self.alter_name(name); self.alter_name(name);
self self
@ -164,11 +169,6 @@ impl Date {
self self
} }
pub fn with_classes(mut self, classes: &str, op: ClassesOp) -> Self {
self.alter_classes(classes, op);
self
}
pub fn using_template(mut self, template: &str) -> Self { pub fn using_template(mut self, template: &str) -> Self {
self.alter_template(template); self.alter_template(template);
self self
@ -186,6 +186,11 @@ impl Date {
self self
} }
pub fn alter_classes(&mut self, classes: &str, op: ClassesOp) -> &mut Self {
self.classes.alter(classes, op);
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.with_value(name);
self self
@ -251,11 +256,6 @@ impl Date {
self self
} }
pub fn alter_classes(&mut self, classes: &str, op: ClassesOp) -> &mut Self {
self.classes.alter(classes, op);
self
}
pub fn alter_template(&mut self, template: &str) -> &mut Self { pub fn alter_template(&mut self, template: &str) -> &mut Self {
self.template = template.to_owned(); self.template = template.to_owned();
self self
@ -263,6 +263,10 @@ impl Date {
// Date GETTERS. // Date GETTERS.
pub fn classes(&self) -> &Classes {
&self.classes
}
pub fn name(&self) -> &AttributeValue { pub fn name(&self) -> &AttributeValue {
&self.name &self.name
} }
@ -303,10 +307,6 @@ impl Date {
&self.help_text &self.help_text
} }
pub fn classes(&self) -> &Classes {
&self.classes
}
pub fn template(&self) -> &str { pub fn template(&self) -> &str {
self.template.as_str() self.template.as_str()
} }

View file

@ -7,12 +7,12 @@ pub enum FormMethod {Get, Post}
pub struct Form { pub struct Form {
renderable: fn() -> bool, renderable: fn() -> bool,
weight : isize, weight : isize,
elements : ComponentsBundle, id : IdentifierValue,
classes : Classes,
action : AttributeValue, action : AttributeValue,
charset : AttributeValue, charset : AttributeValue,
method : FormMethod, method : FormMethod,
id : IdentifierValue, elements : ComponentsBundle,
classes : Classes,
template : String, template : String,
} }
@ -21,12 +21,12 @@ impl ComponentTrait for Form {
Form { Form {
renderable: render_always, renderable: render_always,
weight : 0, weight : 0,
elements : ComponentsBundle::new(), id : IdentifierValue::new(),
classes : Classes::new_with_default("form"),
action : AttributeValue::new(), action : AttributeValue::new(),
charset : AttributeValue::new_with_value("UTF-8"), charset : AttributeValue::new_with_value("UTF-8"),
method : FormMethod::Post, method : FormMethod::Post,
id : IdentifierValue::new(), elements : ComponentsBundle::new(),
classes : Classes::new_with_default("form"),
template : "default".to_owned(), template : "default".to_owned(),
} }
} }
@ -72,17 +72,6 @@ impl ComponentTrait for Form {
impl Form { impl Form {
// Form CONTAINER.
pub fn add(mut self, element: impl ComponentTrait) -> Self {
self.elements.add(element);
self
}
pub fn elements(&self) -> &ComponentsBundle {
&self.elements
}
// Form BUILDER. // Form BUILDER.
pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self { pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self {
@ -95,6 +84,16 @@ impl Form {
self self
} }
pub fn with_id(mut self, id: &str) -> Self {
self.alter_id(id);
self
}
pub fn with_classes(mut self, classes: &str, op: ClassesOp) -> Self {
self.alter_classes(classes, op);
self
}
pub fn with_action(mut self, action: &str) -> Self { pub fn with_action(mut self, action: &str) -> Self {
self.alter_action(action); self.alter_action(action);
self self
@ -110,13 +109,8 @@ impl Form {
self self
} }
pub fn with_id(mut self, id: &str) -> Self { pub fn with_element(mut self, element: impl ComponentTrait) -> Self {
self.alter_id(id); self.alter_element(element);
self
}
pub fn with_classes(mut self, classes: &str, op: ClassesOp) -> Self {
self.alter_classes(classes, op);
self self
} }
@ -137,6 +131,16 @@ impl Form {
self self
} }
pub fn alter_id(&mut self, id: &str) -> &mut Self {
self.id.with_value(id);
self
}
pub fn alter_classes(&mut self, classes: &str, op: ClassesOp) -> &mut Self {
self.classes.alter(classes, op);
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.with_value(action);
self self
@ -152,13 +156,8 @@ impl Form {
self self
} }
pub fn alter_id(&mut self, id: &str) -> &mut Self { pub fn alter_element(&mut self, element: impl ComponentTrait) -> &mut Self {
self.id.with_value(id); self.elements.add(element);
self
}
pub fn alter_classes(&mut self, classes: &str, op: ClassesOp) -> &mut Self {
self.classes.alter(classes, op);
self self
} }
@ -169,6 +168,14 @@ impl Form {
// Form GETTERS. // Form GETTERS.
pub fn id(&self) -> &IdentifierValue {
&self.id
}
pub fn classes(&self) -> &Classes {
&self.classes
}
pub fn action(&self) -> &AttributeValue { pub fn action(&self) -> &AttributeValue {
&self.action &self.action
} }
@ -181,12 +188,8 @@ impl Form {
&self.method &self.method
} }
pub fn id(&self) -> &IdentifierValue { pub fn elements(&self) -> &ComponentsBundle {
&self.id &self.elements
}
pub fn classes(&self) -> &Classes {
&self.classes
} }
pub fn template(&self) -> &str { pub fn template(&self) -> &str {

View file

@ -7,6 +7,7 @@ pub enum InputType {Email, Password, Search, Telephone, Textfield, Url}
pub struct Input { pub struct Input {
renderable : fn() -> bool, renderable : fn() -> bool,
weight : isize, weight : isize,
classes : Classes,
input_type : InputType, input_type : InputType,
name : IdentifierValue, name : IdentifierValue,
value : AttributeValue, value : AttributeValue,
@ -21,7 +22,6 @@ pub struct Input {
readonly : AttributeValue, readonly : AttributeValue,
required : AttributeValue, required : AttributeValue,
help_text : AttributeValue, help_text : AttributeValue,
classes : Classes,
template : String, template : String,
} }
@ -30,6 +30,7 @@ impl ComponentTrait for Input {
Input { Input {
renderable : render_always, renderable : render_always,
weight : 0, weight : 0,
classes : Classes::new_with_default("form-item"),
input_type : InputType::Textfield, input_type : InputType::Textfield,
name : IdentifierValue::new(), name : IdentifierValue::new(),
value : AttributeValue::new(), value : AttributeValue::new(),
@ -44,7 +45,6 @@ impl ComponentTrait for Input {
readonly : AttributeValue::new(), readonly : AttributeValue::new(),
required : AttributeValue::new(), required : AttributeValue::new(),
help_text : AttributeValue::new(), help_text : AttributeValue::new(),
classes : Classes::new_with_default("form-item"),
template : "default".to_owned(), template : "default".to_owned(),
} }
.with_classes("form-type-textfield", ClassesOp::AddFirst) .with_classes("form-type-textfield", ClassesOp::AddFirst)
@ -173,6 +173,11 @@ impl Input {
self self
} }
pub fn with_classes(mut self, classes: &str, op: ClassesOp) -> Self {
self.alter_classes(classes, op);
self
}
pub fn with_name(mut self, name: &str) -> Self { pub fn with_name(mut self, name: &str) -> Self {
self.alter_name(name); self.alter_name(name);
self self
@ -238,11 +243,6 @@ impl Input {
self self
} }
pub fn with_classes(mut self, classes: &str, op: ClassesOp) -> Self {
self.alter_classes(classes, op);
self
}
pub fn using_template(mut self, template: &str) -> Self { pub fn using_template(mut self, template: &str) -> Self {
self.alter_template(template); self.alter_template(template);
self self
@ -260,6 +260,11 @@ impl Input {
self self
} }
pub fn alter_classes(&mut self, classes: &str, op: ClassesOp) -> &mut Self {
self.classes.alter(classes, op);
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.with_value(name);
self.alter_classes( self.alter_classes(
@ -344,11 +349,6 @@ impl Input {
self self
} }
pub fn alter_classes(&mut self, classes: &str, op: ClassesOp) -> &mut Self {
self.classes.alter(classes, op);
self
}
pub fn alter_template(&mut self, template: &str) -> &mut Self { pub fn alter_template(&mut self, template: &str) -> &mut Self {
self.template = template.to_owned(); self.template = template.to_owned();
self self
@ -356,6 +356,10 @@ impl Input {
// Input GETTERS. // Input GETTERS.
pub fn classes(&self) -> &Classes {
&self.classes
}
pub fn input_type(&self) -> &InputType { pub fn input_type(&self) -> &InputType {
&self.input_type &self.input_type
} }
@ -412,10 +416,6 @@ impl Input {
&self.help_text &self.help_text
} }
pub fn classes(&self) -> &Classes {
&self.classes
}
pub fn template(&self) -> &str { pub fn template(&self) -> &str {
self.template.as_str() self.template.as_str()
} }

View file

@ -4,5 +4,5 @@ pub use row::{
}; };
mod column; mod column;
pub use column::{ pub use column::{
COLUMN_COMPONENT, Column COLUMN_COMPONENT, Column, ColumnSize
}; };

View file

@ -2,12 +2,29 @@ use crate::prelude::*;
pub const COLUMN_COMPONENT: &str = "pagetop::component::grid::column"; pub const COLUMN_COMPONENT: &str = "pagetop::component::grid::column";
pub enum ColumnSize {
Default,
Is1of12,
Is2of12,
Is3of12,
Is4of12,
Is5of12,
Is6of12,
Is7of12,
Is8of12,
Is9of12,
Is10of12,
Is11of12,
IsFull,
}
pub struct Column { pub struct Column {
renderable: fn() -> bool, renderable: fn() -> bool,
weight : isize, weight : isize,
components: ComponentsBundle,
id : IdentifierValue, id : IdentifierValue,
classes : Classes, classes : Classes,
spaces : Spaces,
size : ColumnSize,
components: ComponentsBundle,
template : String, template : String,
} }
@ -16,9 +33,11 @@ impl ComponentTrait for Column {
Column { Column {
renderable: render_always, renderable: render_always,
weight : 0, weight : 0,
components: ComponentsBundle::new(),
id : IdentifierValue::new(), id : IdentifierValue::new(),
classes : Classes::new_with_default("col-md"), classes : Classes::new(),
spaces : Spaces::new(),
size : ColumnSize::Default,
components: ComponentsBundle::new(),
template : "default".to_owned(), template : "default".to_owned(),
} }
} }
@ -35,9 +54,27 @@ impl ComponentTrait for Column {
self.weight self.weight
} }
fn before_render(&mut self, _context: &mut InContext) {
match self.size() {
ColumnSize::Default => self.alter_classes("col-sm", ClassesOp::SetDefault),
ColumnSize::Is1of12 => self.alter_classes("col-sm-1", ClassesOp::SetDefault),
ColumnSize::Is2of12 => self.alter_classes("col-sm-2", ClassesOp::SetDefault),
ColumnSize::Is3of12 => self.alter_classes("col-sm-3", ClassesOp::SetDefault),
ColumnSize::Is4of12 => self.alter_classes("col-sm-4", ClassesOp::SetDefault),
ColumnSize::Is5of12 => self.alter_classes("col-sm-5", ClassesOp::SetDefault),
ColumnSize::Is6of12 => self.alter_classes("col-sm-6", ClassesOp::SetDefault),
ColumnSize::Is7of12 => self.alter_classes("col-sm-7", ClassesOp::SetDefault),
ColumnSize::Is8of12 => self.alter_classes("col-sm-8", ClassesOp::SetDefault),
ColumnSize::Is9of12 => self.alter_classes("col-sm-9", ClassesOp::SetDefault),
ColumnSize::Is10of12 => self.alter_classes("col-sm-10", ClassesOp::SetDefault),
ColumnSize::Is11of12 => self.alter_classes("col-sm-11", ClassesOp::SetDefault),
ColumnSize::IsFull => self.alter_classes("col-sm-12", ClassesOp::SetDefault),
};
}
fn default_render(&self, context: &mut InContext) -> Markup { fn default_render(&self, context: &mut InContext) -> Markup {
html! { html! {
div id=[self.id().get()] class=[self.classes().get()] { div id=[self.id().get()] class=[self.classes().get()] style=[self.spaces().get()] {
(self.components().render(context)) (self.components().render(context))
} }
} }
@ -54,17 +91,6 @@ impl ComponentTrait for Column {
impl Column { impl Column {
// Column CONTAINER.
pub fn add(mut self, component: impl ComponentTrait) -> Self {
self.components.add(component);
self
}
pub fn components(&self) -> &ComponentsBundle {
&self.components
}
// Column BUILDER. // Column BUILDER.
pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self { pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self {
@ -87,6 +113,21 @@ impl Column {
self self
} }
pub fn with_spaces(mut self, spaces: &[SpaceSet]) -> Self {
self.alter_spaces(spaces);
self
}
pub fn with_size(mut self, size: ColumnSize) -> Self {
self.alter_size(size);
self
}
pub fn with_component(mut self, component: impl ComponentTrait) -> Self {
self.alter_component(component);
self
}
pub fn using_template(mut self, template: &str) -> Self { pub fn using_template(mut self, template: &str) -> Self {
self.alter_template(template); self.alter_template(template);
self self
@ -114,6 +155,20 @@ impl Column {
self self
} }
pub fn alter_spaces(&mut self, spaces: &[SpaceSet]) -> &mut Self {
self.spaces.add(spaces);
self
}
pub fn alter_size(&mut self, size: ColumnSize) -> &mut Self {
self.size = size;
self
}
pub fn alter_component(&mut self, component: impl ComponentTrait) -> &mut Self {
self.components.add(component);
self
}
pub fn alter_template(&mut self, template: &str) -> &mut Self { pub fn alter_template(&mut self, template: &str) -> &mut Self {
self.template = template.to_owned(); self.template = template.to_owned();
self self
@ -129,6 +184,18 @@ impl Column {
&self.classes &self.classes
} }
pub fn spaces(&self) -> &Spaces {
&self.spaces
}
pub fn size(&self) -> &ColumnSize {
&self.size
}
pub fn components(&self) -> &ComponentsBundle {
&self.components
}
pub fn template(&self) -> &str { pub fn template(&self) -> &str {
self.template.as_str() self.template.as_str()
} }

View file

@ -5,10 +5,10 @@ pub const ROW_COMPONENT: &str = "pagetop::component::grid::row";
pub struct Row { pub struct Row {
renderable: fn() -> bool, renderable: fn() -> bool,
weight : isize, weight : isize,
columns : ComponentsBundle,
id : IdentifierValue, id : IdentifierValue,
classes : Classes, classes : Classes,
spaces : Spaces, spaces : Spaces,
columns : ComponentsBundle,
template : String, template : String,
} }
@ -17,10 +17,10 @@ impl ComponentTrait for Row {
Row { Row {
renderable: render_always, renderable: render_always,
weight : 0, weight : 0,
columns : ComponentsBundle::new(),
id : IdentifierValue::new(), id : IdentifierValue::new(),
classes : Classes::new_with_default("row"), classes : Classes::new_with_default("row"),
spaces : Spaces::new(), spaces : Spaces::new(),
columns : ComponentsBundle::new(),
template : "default".to_owned(), template : "default".to_owned(),
} }
} }
@ -56,17 +56,6 @@ impl ComponentTrait for Row {
impl Row { impl Row {
// Row CONTAINER.
pub fn add_column(mut self, column: grid::Column) -> Self {
self.columns.add(column);
self
}
pub fn columns(&self) -> &ComponentsBundle {
&self.columns
}
// Row BUILDER. // Row BUILDER.
pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self { pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self {
@ -94,6 +83,11 @@ impl Row {
self self
} }
pub fn with_column(mut self, column: grid::Column) -> Self {
self.alter_column(column);
self
}
pub fn using_template(mut self, template: &str) -> Self { pub fn using_template(mut self, template: &str) -> Self {
self.alter_template(template); self.alter_template(template);
self self
@ -126,6 +120,11 @@ impl Row {
self self
} }
pub fn alter_column(&mut self, column: grid::Column) -> &mut Self {
self.columns.add(column);
self
}
pub fn alter_template(&mut self, template: &str) -> &mut Self { pub fn alter_template(&mut self, template: &str) -> &mut Self {
self.template = template.to_owned(); self.template = template.to_owned();
self self
@ -145,6 +144,10 @@ impl Row {
&self.spaces &self.spaces
} }
pub fn columns(&self) -> &ComponentsBundle {
&self.columns
}
pub fn template(&self) -> &str { pub fn template(&self) -> &str {
self.template.as_str() self.template.as_str()
} }

View file

@ -14,27 +14,27 @@ pub enum HeadingDisplay {
} }
pub struct Heading { pub struct Heading {
renderable: fn() -> bool, renderable : fn() -> bool,
weight : isize, weight : isize,
heading : HeadingType, id : IdentifierValue,
html : Markup, classes : Classes,
display : HeadingDisplay, heading_type: HeadingType,
id : IdentifierValue, html : Markup,
classes : Classes, display : HeadingDisplay,
template : String, template : String,
} }
impl ComponentTrait for Heading { impl ComponentTrait for Heading {
fn new() -> Self { fn new() -> Self {
Heading { Heading {
renderable: render_always, renderable : render_always,
weight : 0, weight : 0,
heading : HeadingType::H1, id : IdentifierValue::new(),
html : html! {}, classes : Classes::new(),
display : HeadingDisplay::Normal, heading_type: HeadingType::H1,
id : IdentifierValue::new(), html : html! {},
classes : Classes::new(), display : HeadingDisplay::Normal,
template : "default".to_owned(), template : "default".to_owned(),
} }
} }
@ -53,7 +53,7 @@ impl ComponentTrait for Heading {
fn default_render(&self, _: &mut InContext) -> Markup { fn default_render(&self, _: &mut InContext) -> Markup {
let id = self.id().get(); let id = self.id().get();
let classes = self.classes().get(); let classes = self.classes().get();
html! { @match &self.heading() { html! { @match &self.heading_type() {
HeadingType::H1 => h1 id=[id] class=[classes] { (*self.html()) }, HeadingType::H1 => h1 id=[id] class=[classes] { (*self.html()) },
HeadingType::H2 => h2 id=[id] class=[classes] { (*self.html()) }, HeadingType::H2 => h2 id=[id] class=[classes] { (*self.html()) },
HeadingType::H3 => h3 id=[id] class=[classes] { (*self.html()) }, HeadingType::H3 => h3 id=[id] class=[classes] { (*self.html()) },
@ -74,27 +74,27 @@ impl ComponentTrait for Heading {
impl Heading { impl Heading {
pub fn h1(html: Markup) -> Self { pub fn h1(html: Markup) -> Self {
Heading::new().with_heading(HeadingType::H1).with_html(html) Heading::new().with_heading_type(HeadingType::H1).with_html(html)
} }
pub fn h2(html: Markup) -> Self { pub fn h2(html: Markup) -> Self {
Heading::new().with_heading(HeadingType::H2).with_html(html) Heading::new().with_heading_type(HeadingType::H2).with_html(html)
} }
pub fn h3(html: Markup) -> Self { pub fn h3(html: Markup) -> Self {
Heading::new().with_heading(HeadingType::H3).with_html(html) Heading::new().with_heading_type(HeadingType::H3).with_html(html)
} }
pub fn h4(html: Markup) -> Self { pub fn h4(html: Markup) -> Self {
Heading::new().with_heading(HeadingType::H4).with_html(html) Heading::new().with_heading_type(HeadingType::H4).with_html(html)
} }
pub fn h5(html: Markup) -> Self { pub fn h5(html: Markup) -> Self {
Heading::new().with_heading(HeadingType::H5).with_html(html) Heading::new().with_heading_type(HeadingType::H5).with_html(html)
} }
pub fn h6(html: Markup) -> Self { pub fn h6(html: Markup) -> Self {
Heading::new().with_heading(HeadingType::H6).with_html(html) Heading::new().with_heading_type(HeadingType::H6).with_html(html)
} }
// Heading BUILDER. // Heading BUILDER.
@ -109,8 +109,18 @@ impl Heading {
self self
} }
pub fn with_heading(mut self, heading: HeadingType) -> Self { pub fn with_id(mut self, id: &str) -> Self {
self.alter_heading(heading); self.alter_id(id);
self
}
pub fn with_classes(mut self, classes: &str, op: ClassesOp) -> Self {
self.alter_classes(classes, op);
self
}
pub fn with_heading_type(mut self, heading_type: HeadingType) -> Self {
self.alter_heading_type(heading_type);
self self
} }
@ -124,16 +134,6 @@ impl Heading {
self self
} }
pub fn with_id(mut self, id: &str) -> Self {
self.alter_id(id);
self
}
pub fn with_classes(mut self, classes: &str, op: ClassesOp) -> Self {
self.alter_classes(classes, op);
self
}
pub fn using_template(mut self, template: &str) -> Self { pub fn using_template(mut self, template: &str) -> Self {
self.alter_template(template); self.alter_template(template);
self self
@ -151,8 +151,18 @@ impl Heading {
self self
} }
pub fn alter_heading(&mut self, heading: HeadingType) -> &mut Self { pub fn alter_id(&mut self, id: &str) -> &mut Self {
self.heading = heading; self.id.with_value(id);
self
}
pub fn alter_classes(&mut self, classes: &str, op: ClassesOp) -> &mut Self {
self.classes.alter(classes, op);
self
}
pub fn alter_heading_type(&mut self, heading_type: HeadingType) -> &mut Self {
self.heading_type = heading_type;
self self
} }
@ -174,16 +184,6 @@ impl Heading {
self self
} }
pub fn alter_id(&mut self, id: &str) -> &mut Self {
self.id.with_value(id);
self
}
pub fn alter_classes(&mut self, classes: &str, op: ClassesOp) -> &mut Self {
self.classes.alter(classes, op);
self
}
pub fn alter_template(&mut self, template: &str) -> &mut Self { pub fn alter_template(&mut self, template: &str) -> &mut Self {
self.template = template.to_owned(); self.template = template.to_owned();
self self
@ -191,8 +191,16 @@ impl Heading {
// Paragraph GETTERS. // Paragraph GETTERS.
pub fn heading(&self) -> &HeadingType { pub fn id(&self) -> &IdentifierValue {
&self.heading &self.id
}
pub fn classes(&self) -> &Classes {
&self.classes
}
pub fn heading_type(&self) -> &HeadingType {
&self.heading_type
} }
pub fn html(&self) -> &Markup { pub fn html(&self) -> &Markup {
@ -203,14 +211,6 @@ impl Heading {
&self.display &self.display
} }
pub fn id(&self) -> &IdentifierValue {
&self.id
}
pub fn classes(&self) -> &Classes {
&self.classes
}
pub fn template(&self) -> &str { pub fn template(&self) -> &str {
self.template.as_str() self.template.as_str()
} }

View file

@ -5,8 +5,9 @@ pub const ICON_COMPONENT: &str = "pagetop::component::icon";
pub struct Icon { pub struct Icon {
renderable: fn() -> bool, renderable: fn() -> bool,
weight : isize, weight : isize,
icon_name : String,
classes : Classes, classes : Classes,
spaces : Spaces, spaces : Spaces,
} }
impl ComponentTrait for Icon { impl ComponentTrait for Icon {
@ -14,8 +15,9 @@ impl ComponentTrait for Icon {
Icon { Icon {
renderable: render_always, renderable: render_always,
weight : 0, weight : 0,
classes : Classes::new_with_default("bi-question-circle-fill"), icon_name : "question-circle-fill".to_owned(),
spaces : Spaces::new(), classes : Classes::new(),
spaces : Spaces::new(),
} }
} }
@ -31,12 +33,16 @@ impl ComponentTrait for Icon {
self.weight self.weight
} }
fn default_render(&self, context: &mut InContext) -> Markup { fn before_render(&mut self, context: &mut InContext) {
context context
.add_stylesheet(StyleSheet::with_source( .add_stylesheet(StyleSheet::with_source(
"/theme/icons/bootstrap-icons.css?ver=1.8.2" "/theme/icons/bootstrap-icons.css?ver=1.8.2"
)); ));
self.alter_classes(concat_string!("bi-", self.icon_name()).as_str(), ClassesOp::SetDefault);
}
fn default_render(&self, _context: &mut InContext) -> Markup {
html! { i class=[self.classes().get()] style=[self.spaces().get()] {}; } html! { i class=[self.classes().get()] style=[self.spaces().get()] {}; }
} }
@ -94,7 +100,7 @@ impl Icon {
} }
pub fn alter_icon_name(&mut self, name: &str) -> &mut Self { pub fn alter_icon_name(&mut self, name: &str) -> &mut Self {
self.classes.alter(concat_string!("bi-", name).as_str(), ClassesOp::SetDefault); self.icon_name = name.to_owned();
self self
} }
@ -110,6 +116,10 @@ impl Icon {
// Icon GETTERS. // Icon GETTERS.
pub fn icon_name(&self) -> &str {
self.icon_name.as_str()
}
pub fn classes(&self) -> &Classes { pub fn classes(&self) -> &Classes {
&self.classes &self.classes
} }

View file

@ -5,9 +5,9 @@ pub const IMAGE_COMPONENT: &str = "pagetop::component::image";
pub struct Image { pub struct Image {
renderable: fn() -> bool, renderable: fn() -> bool,
weight : isize, weight : isize,
source : AttributeValue,
id : IdentifierValue, id : IdentifierValue,
classes : Classes, classes : Classes,
source : AttributeValue,
template : String, template : String,
} }
@ -16,9 +16,9 @@ impl ComponentTrait for Image {
Image { Image {
renderable: render_always, renderable: render_always,
weight : 0, weight : 0,
source : AttributeValue::new(),
id : IdentifierValue::new(), id : IdentifierValue::new(),
classes : Classes::new_with_default("img-fluid"), classes : Classes::new_with_default("img-fluid"),
source : AttributeValue::new(),
template : "default".to_owned(), template : "default".to_owned(),
} }
} }
@ -70,11 +70,6 @@ impl Image {
self self
} }
pub fn with_source(mut self, source: &str) -> Self {
self.alter_source(source);
self
}
pub fn with_id(mut self, id: &str) -> Self { pub fn with_id(mut self, id: &str) -> Self {
self.alter_id(id); self.alter_id(id);
self self
@ -85,6 +80,11 @@ impl Image {
self self
} }
pub fn with_source(mut self, source: &str) -> Self {
self.alter_source(source);
self
}
pub fn using_template(mut self, template: &str) -> Self { pub fn using_template(mut self, template: &str) -> Self {
self.alter_template(template); self.alter_template(template);
self self
@ -102,11 +102,6 @@ impl Image {
self self
} }
pub fn alter_source(&mut self, source: &str) -> &mut Self {
self.source.with_value(source);
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.with_value(id);
self self
@ -117,6 +112,11 @@ impl Image {
self self
} }
pub fn alter_source(&mut self, source: &str) -> &mut Self {
self.source.with_value(source);
self
}
pub fn alter_template(&mut self, template: &str) -> &mut Self { pub fn alter_template(&mut self, template: &str) -> &mut Self {
self.template = template.to_owned(); self.template = template.to_owned();
self self
@ -124,10 +124,6 @@ impl Image {
// Image GETTERS. // Image GETTERS.
pub fn source(&self) -> &AttributeValue {
&self.source
}
pub fn id(&self) -> &IdentifierValue { pub fn id(&self) -> &IdentifierValue {
&self.id &self.id
} }
@ -136,6 +132,10 @@ impl Image {
&self.classes &self.classes
} }
pub fn source(&self) -> &AttributeValue {
&self.source
}
pub fn template(&self) -> &str { pub fn template(&self) -> &str {
self.template.as_str() self.template.as_str()
} }

View file

@ -176,9 +176,9 @@ impl MenuItem {
pub struct Menu { pub struct Menu {
renderable: fn() -> bool, renderable: fn() -> bool,
weight : isize, weight : isize,
items : ComponentsBundle,
id : IdentifierValue, id : IdentifierValue,
classes : Classes, classes : Classes,
items : ComponentsBundle,
template : String, template : String,
} }
@ -206,7 +206,7 @@ impl ComponentTrait for Menu {
self.weight self.weight
} }
fn default_render(&self, context: &mut InContext) -> Markup { fn before_render(&mut self, context: &mut InContext) {
context context
.add_stylesheet(StyleSheet::with_source( .add_stylesheet(StyleSheet::with_source(
"/theme/menu/css/menu.css?ver=1.1.1" "/theme/menu/css/menu.css?ver=1.1.1"
@ -218,7 +218,9 @@ impl ComponentTrait for Menu {
"/theme/menu/js/menu.min.js?ver=1.1.1" "/theme/menu/js/menu.min.js?ver=1.1.1"
)) ))
.add_jquery(); .add_jquery();
}
fn default_render(&self, context: &mut InContext) -> Markup {
let id = context.required_id::<Menu>(self.id()); let id = context.required_id::<Menu>(self.id());
html! { html! {
ul id=(id) class=[self.classes().get()] { ul id=(id) class=[self.classes().get()] {
@ -244,17 +246,6 @@ impl ComponentTrait for Menu {
impl Menu { impl Menu {
// Menu CONTAINER.
pub fn add(mut self, item: MenuItem) -> Self {
self.items.add(item);
self
}
pub fn items(&self) -> &ComponentsBundle {
&self.items
}
// Menu BUILDER. // Menu BUILDER.
pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self { pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self {
@ -277,6 +268,11 @@ impl Menu {
self self
} }
pub fn with_item(mut self, item: MenuItem) -> Self {
self.alter_item(item);
self
}
pub fn using_template(mut self, template: &str) -> Self { pub fn using_template(mut self, template: &str) -> Self {
self.alter_template(template); self.alter_template(template);
self self
@ -304,6 +300,11 @@ impl Menu {
self self
} }
pub fn alter_item(&mut self, item: MenuItem) -> &mut Self {
self.items.add(item);
self
}
pub fn alter_template(&mut self, template: &str) -> &mut Self { pub fn alter_template(&mut self, template: &str) -> &mut Self {
self.template = template.to_owned(); self.template = template.to_owned();
self self
@ -319,6 +320,10 @@ impl Menu {
&self.classes &self.classes
} }
pub fn items(&self) -> &ComponentsBundle {
&self.items
}
pub fn template(&self) -> &str { pub fn template(&self) -> &str {
self.template.as_str() self.template.as_str()
} }

View file

@ -14,10 +14,10 @@ pub enum ParagraphDisplay {
pub struct Paragraph { pub struct Paragraph {
renderable: fn() -> bool, renderable: fn() -> bool,
weight : isize, weight : isize,
html : Markup,
display : ParagraphDisplay,
id : IdentifierValue, id : IdentifierValue,
classes : Classes, classes : Classes,
html : Markup,
display : ParagraphDisplay,
template : String, template : String,
} }
@ -26,10 +26,10 @@ impl ComponentTrait for Paragraph {
Paragraph { Paragraph {
renderable: render_always, renderable: render_always,
weight : 0, weight : 0,
html : html! {},
display : ParagraphDisplay::Normal,
id : IdentifierValue::new(), id : IdentifierValue::new(),
classes : Classes::new(), classes : Classes::new(),
html : html! {},
display : ParagraphDisplay::Normal,
template : "default".to_owned(), template : "default".to_owned(),
} }
} }
@ -78,16 +78,6 @@ impl Paragraph {
self self
} }
pub fn with_html(mut self, html: Markup) -> Self {
self.alter_html(html);
self
}
pub fn with_display(mut self, display: ParagraphDisplay) -> Self {
self.alter_display(display);
self
}
pub fn with_id(mut self, id: &str) -> Self { pub fn with_id(mut self, id: &str) -> Self {
self.alter_id(id); self.alter_id(id);
self self
@ -98,6 +88,16 @@ impl Paragraph {
self self
} }
pub fn with_html(mut self, html: Markup) -> Self {
self.alter_html(html);
self
}
pub fn with_display(mut self, display: ParagraphDisplay) -> Self {
self.alter_display(display);
self
}
pub fn using_template(mut self, template: &str) -> Self { pub fn using_template(mut self, template: &str) -> Self {
self.alter_template(template); self.alter_template(template);
self self
@ -115,6 +115,16 @@ impl Paragraph {
self self
} }
pub fn alter_id(&mut self, id: &str) -> &mut Self {
self.id.with_value(id);
self
}
pub fn alter_classes(&mut self, classes: &str, op: ClassesOp) -> &mut Self {
self.classes.alter(classes, op);
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 = html;
self self
@ -133,16 +143,6 @@ impl Paragraph {
self self
} }
pub fn alter_id(&mut self, id: &str) -> &mut Self {
self.id.with_value(id);
self
}
pub fn alter_classes(&mut self, classes: &str, op: ClassesOp) -> &mut Self {
self.classes.alter(classes, op);
self
}
pub fn alter_template(&mut self, template: &str) -> &mut Self { pub fn alter_template(&mut self, template: &str) -> &mut Self {
self.template = template.to_owned(); self.template = template.to_owned();
self self
@ -150,14 +150,6 @@ impl Paragraph {
// Paragraph GETTERS. // Paragraph GETTERS.
pub fn html(&self) -> &Markup {
&self.html
}
pub fn display(&self) -> &ParagraphDisplay {
&self.display
}
pub fn id(&self) -> &IdentifierValue { pub fn id(&self) -> &IdentifierValue {
&self.id &self.id
} }
@ -166,6 +158,14 @@ impl Paragraph {
&self.classes &self.classes
} }
pub fn html(&self) -> &Markup {
&self.html
}
pub fn display(&self) -> &ParagraphDisplay {
&self.display
}
pub fn template(&self) -> &str { pub fn template(&self) -> &str {
self.template.as_str() self.template.as_str()
} }

View file

@ -37,76 +37,68 @@ async fn demo() -> app::Result<Markup> {
fn hello_world() -> Container { fn hello_world() -> Container {
Container::header() Container::header()
.add(grid::Row::new() .with_component(grid::Row::new()
.add_column(grid::Column::new() .with_column(grid::Column::new()
.add(Heading::h1(html! { .with_component(Heading::h1(html! {
(l("page_title")) (l("page_title"))
}).with_display(HeadingDisplay::Large)) })
.add(Paragraph::with(html! { .with_display(HeadingDisplay::Large)
(t("welcome_to", &args![
"app" => SETTINGS.app.name.as_str()
]))
}))
.add(Paragraph::with(html! {
(e("welcome_intro", &args![
"app" => format!("<strong>{}</strong>", &SETTINGS.app.name)
]))
}).with_display(ParagraphDisplay::Small))
.add(Paragraph::with(html! {
(e("welcome_pagetop", &args![
"pagetop" => "<a href=\"https://pagetop-rs\">PageTop</a>"
]))
}))
.add(Anchor::button("#",
html! {
("Offered services")
}).with_left_icon(
Icon::with("card-checklist")
)
) )
.add(Anchor::button("#", .with_component(Paragraph::with(html! {
html! { (t("welcome_to", &args!["app" => SETTINGS.app.name.as_str()]))
})
)
.with_component(Paragraph::with(html! {
(e("welcome_intro", &args![
"app" => format!("<strong>{}</strong>", &SETTINGS.app.name)
]))
})
.with_display(ParagraphDisplay::Small)
)
.with_component(Paragraph::with(html! {
(e("welcome_pagetop", &args![
"pagetop" => "<a href=\"https://pagetop-rs\">PageTop</a>"
]))
})
)
.with_component(Anchor::button("#", html! {
("Offered services")
})
.with_left_icon(Icon::with("card-checklist"))
)
.with_component(Anchor::button("#", html! {
("Get quote") ("Get quote")
}).with_left_icon( })
Icon::with("envelope-open-heart-fill") .with_left_icon(Icon::with("envelope-open-heart-fill"))
)
) )
) )
.add_column(grid::Column::new() .with_column(grid::Column::new()
.add(Image::image("/theme/images/demo-header.svg")) .with_component(Image::image("/theme/images/demo-header.svg"))
) )
.with_spaces(&[SpaceSet::PaddingBoth(SpaceValue::RelEm(2.0), SpaceValue::RelPct(5.0))]) .with_spaces(&[SpaceSet::PaddingBoth(SpaceValue::RelEm(2.0), SpaceValue::RelPct(5.0))])
) )
} }
fn just_visiting() -> Chunck { fn just_visiting() -> Container {
Chunck::with(html! { Container::new()
div id="details" class="basic-1" { .with_component(grid::Row::new()
div class="container" { .with_column(grid::Column::new()
div class="row" { .with_size(grid::ColumnSize::Is5of12)
div class="col-lg-6 col-xl-7" { .with_component(Image::image("/theme/images/demo-visiting.svg"))
div class="image-container" { .with_spaces(&[SpaceSet::PaddingAll(SpaceValue::RelPct(2.0))])
img class="img-fluid" src="/bootsier/images/demo-visiting.svg" alt="alternative" {} )
} .with_column(grid::Column::new()
} .with_component(Heading::h2(html! { (l("visiting_title")) }))
div class="col-lg-6 col-xl-5" { .with_component(Heading::h3(html! { (l("visiting_subtitle")) }))
div class="text-container" { .with_component(Paragraph::with(html! { (l("visiting_text1")) }))
h2 { .with_component(Paragraph::with(html! { (l("visiting_text2")) }))
span { .with_spaces(&[
(l("visiting_title")) SpaceSet::PaddingTop(SpaceValue::RelPct(2.5)),
} SpaceSet::PaddingLeft(SpaceValue::RelPct(5.0)),
br; ])
(l("visiting_subtitle")) )
} .with_spaces(&[SpaceSet::PaddingBoth(SpaceValue::RelEm(1.0), SpaceValue::RelPct(5.0))])
p { (l("visiting_text1")) } )
p { (l("visiting_text2")) }
a class="btn-solid-reg" data-bs-toggle="modal" data-bs-target="#staticBackdrop" { "Modal" }
}
}
}
}
}
})
} }
fn about_pagetop() -> Chunck { fn about_pagetop() -> Chunck {

View file

@ -66,7 +66,21 @@ impl ThemeTrait for Bulmix {
}, },
grid::COLUMN_COMPONENT => { grid::COLUMN_COMPONENT => {
let col = component_mut::<grid::Column>(component); let col = component_mut::<grid::Column>(component);
col.alter_classes("column content", ClassesOp::SetDefault); col.alter_classes(concat_string!("column", match col.size() {
grid::ColumnSize::Default => "",
grid::ColumnSize::Is1of12 => " is-1",
grid::ColumnSize::Is2of12 => " is-2",
grid::ColumnSize::Is3of12 => " is-3",
grid::ColumnSize::Is4of12 => " is-4",
grid::ColumnSize::Is5of12 => " is-5",
grid::ColumnSize::Is6of12 => " is-6",
grid::ColumnSize::Is7of12 => " is-7",
grid::ColumnSize::Is8of12 => " is-8",
grid::ColumnSize::Is9of12 => " is-9",
grid::ColumnSize::Is10of12 => " is-10",
grid::ColumnSize::Is11of12 => " is-11",
grid::ColumnSize::IsFull => " is-12",
}, " content").as_str(), ClassesOp::SetDefault);
}, },
grid::ROW_COMPONENT => { grid::ROW_COMPONENT => {
let row = component_mut::<grid::Row>(component); let row = component_mut::<grid::Row>(component);
@ -79,15 +93,11 @@ impl ThemeTrait for Bulmix {
fn render_component( fn render_component(
&self, &self,
component: &dyn ComponentTrait, component: &dyn ComponentTrait,
context: &mut InContext _context: &mut InContext
) -> Option<Markup> { ) -> Option<Markup> {
match component.handler() { match component.handler() {
ICON_COMPONENT => { ICON_COMPONENT => {
let icon = component_ref::<Icon>(component); let icon = component_ref::<Icon>(component);
context
.add_stylesheet(StyleSheet::with_source(
"/theme/icons/bootstrap-icons.css?ver=1.8.2"
));
Some(html! { Some(html! {
span class="icon" { span class="icon" {
i class=[icon.classes().get()] style=[icon.spaces().get()] {}; i class=[icon.classes().get()] style=[icon.spaces().get()] {};

View file

@ -26,6 +26,10 @@ pub trait ComponentTrait: AnyComponent + Send + Sync {
0 0
} }
#[allow(unused_variables)]
fn before_render(&mut self, context: &mut InContext) {
}
#[allow(unused_variables)] #[allow(unused_variables)]
fn default_render(&self, context: &mut InContext) -> Markup { fn default_render(&self, context: &mut InContext) -> Markup {
html! {} html! {}
@ -45,6 +49,9 @@ pub fn component_mut<C: 'static>(component: &mut dyn ComponentTrait) -> &mut C {
} }
pub fn render_component(component: &mut dyn ComponentTrait, context: &mut InContext) -> Markup { pub fn render_component(component: &mut dyn ComponentTrait, context: &mut InContext) -> Markup {
// Acciones del propio componente antes de renderizarlo.
component.before_render(context);
// Acciones de los módulos antes de renderizar el componente. // Acciones de los módulos antes de renderizar el componente.
run_hooks( run_hooks(
BEFORE_RENDER_COMPONENT_HOOK, BEFORE_RENDER_COMPONENT_HOOK,
@ -55,11 +62,9 @@ pub fn render_component(component: &mut dyn ComponentTrait, context: &mut InCont
context.theme().before_render_component(component, context); context.theme().before_render_component(component, context);
match component.is_renderable() { match component.is_renderable() {
true => { true => match context.theme().render_component(component, context) {
match context.theme().render_component(component, context) { Some(html) => html,
Some(html) => html, None => component.default_render(context)
None => component.default_render(context)
}
}, },
false => html! {} false => html! {}
} }

View file

Before

Width:  |  Height:  |  Size: 33 KiB

After

Width:  |  Height:  |  Size: 33 KiB

Before After
Before After