Actualiza y recupera definición original de comp.
Prácticamente se revierten los últimos cambios realizados en la estructura de componentes.
This commit is contained in:
parent
4dd57eab43
commit
93d6d455c8
21 changed files with 234 additions and 259 deletions
|
|
@ -38,18 +38,17 @@ pub async fn summary() -> app::Result<Markup> {
|
|||
|
||||
.with_title("Admin")
|
||||
|
||||
.add_to("top-menu", top_menu.arc())
|
||||
.add_to("top-menu", top_menu)
|
||||
|
||||
.add_to("content", grid::Row::new()
|
||||
.add_column(grid::Column::new()
|
||||
.add(side_menu.arc())
|
||||
.add(side_menu)
|
||||
)
|
||||
.add_column(grid::Column::new()
|
||||
.add(Chunck::with(html! {
|
||||
p { "Columna 2"}
|
||||
}).arc())
|
||||
}))
|
||||
)
|
||||
.arc()
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -31,8 +31,8 @@ impl ModuleTrait for UserModule {
|
|||
}
|
||||
}
|
||||
|
||||
fn form_login() -> ArcComponent {
|
||||
Form::new()/*
|
||||
fn form_login() -> Form {
|
||||
Form::new()
|
||||
.with_id("user-login")
|
||||
.add(form::Input::textfield()
|
||||
.with_name("name")
|
||||
|
|
@ -41,27 +41,23 @@ fn form_login() -> ArcComponent {
|
|||
"app" => SETTINGS.app.name.to_owned()
|
||||
]).as_str())
|
||||
.with_autofocus(true)
|
||||
.arc()
|
||||
)
|
||||
.add(form::Input::password()
|
||||
.with_name("pass")
|
||||
.with_label(l("password").as_str())
|
||||
.with_help_text(l("password_help").as_str())
|
||||
.arc()
|
||||
)
|
||||
.add(form::Button::submit(l("login").as_str()).arc())*/
|
||||
.arc()
|
||||
.add(form::Button::submit(l("login").as_str()))
|
||||
}
|
||||
|
||||
async fn login() -> app::Result<Markup> {
|
||||
Page::new()
|
||||
.with_title(
|
||||
"Identificación del usuario"
|
||||
)/*
|
||||
)
|
||||
.add_to("content", Container::new()
|
||||
.with_id("welcome")
|
||||
.add(form_login())
|
||||
.arc()
|
||||
)*/
|
||||
)
|
||||
.render()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ use crate::prelude::*;
|
|||
pub struct Block {
|
||||
renderable: fn() -> bool,
|
||||
weight : i8,
|
||||
components: PageContainer,
|
||||
title : OptAttr,
|
||||
html : Vec<Markup>,
|
||||
id : OptIden,
|
||||
classes : Classes,
|
||||
template : String,
|
||||
|
|
@ -15,8 +15,8 @@ impl PageComponent for Block {
|
|||
Block {
|
||||
renderable: always,
|
||||
weight : 0,
|
||||
components: PageContainer::new(),
|
||||
title : OptAttr::none(),
|
||||
html : Vec::new(),
|
||||
id : OptIden::none(),
|
||||
classes : Classes::none(),
|
||||
template : "default".to_owned(),
|
||||
|
|
@ -40,9 +40,7 @@ impl PageComponent for Block {
|
|||
None => {}
|
||||
}
|
||||
div class="block-body" {
|
||||
@for html in self.html().iter() {
|
||||
(*html)
|
||||
}
|
||||
(self.components().render(assets))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -50,50 +48,51 @@ impl PageComponent for Block {
|
|||
}
|
||||
|
||||
impl Block {
|
||||
pub fn with(html: Markup) -> Self {
|
||||
let mut block = Block::new();
|
||||
block.add(html);
|
||||
block
|
||||
|
||||
// Block CONTAINER.
|
||||
|
||||
pub fn add(mut self, component: impl PageComponent) -> Self {
|
||||
self.components.add(component);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn components(&self) -> &PageContainer {
|
||||
&self.components
|
||||
}
|
||||
|
||||
// Block BUILDER.
|
||||
|
||||
pub fn with_renderable(&mut self, renderable: fn() -> bool) -> &Self {
|
||||
pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self {
|
||||
self.renderable = renderable;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_weight(&mut self, weight: i8) -> &Self {
|
||||
pub fn with_weight(mut self, weight: i8) -> Self {
|
||||
self.weight = weight;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_title(&mut self, title: &str) -> &Self {
|
||||
pub fn with_title(mut self, title: &str) -> Self {
|
||||
self.title.with_value(title);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add(&mut self, html: Markup) -> &Self {
|
||||
self.html.push(html);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_id(&mut self, id: &str) -> &Self {
|
||||
pub fn with_id(mut self, id: &str) -> Self {
|
||||
self.id.with_value(id);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn set_classes(&mut self, classes: &str) -> &Self {
|
||||
pub fn set_classes(mut self, classes: &str) -> Self {
|
||||
self.classes.set_classes(classes);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_classes(&mut self, classes: &str) -> &Self {
|
||||
pub fn add_classes(mut self, classes: &str) -> Self {
|
||||
self.classes.add_classes(classes);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn using_template(&mut self, template: &str) -> &Self {
|
||||
pub fn using_template(mut self, template: &str) -> Self {
|
||||
self.template = template.to_owned();
|
||||
self
|
||||
}
|
||||
|
|
@ -104,10 +103,6 @@ impl Block {
|
|||
self.title.option()
|
||||
}
|
||||
|
||||
pub fn html(&self) -> &Vec<Markup> {
|
||||
&self.html
|
||||
}
|
||||
|
||||
pub fn id(&self) -> &Option<String> {
|
||||
self.id.option()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use crate::prelude::*;
|
|||
pub struct Chunck {
|
||||
renderable: fn() -> bool,
|
||||
weight : i8,
|
||||
html : Vec<Markup>,
|
||||
html : Markup,
|
||||
template : String,
|
||||
}
|
||||
|
||||
|
|
@ -12,7 +12,7 @@ impl PageComponent for Chunck {
|
|||
Chunck {
|
||||
renderable: always,
|
||||
weight : 0,
|
||||
html : Vec::new(),
|
||||
html : html! {},
|
||||
template : "default".to_owned(),
|
||||
}
|
||||
}
|
||||
|
|
@ -26,46 +26,37 @@ impl PageComponent for Chunck {
|
|||
}
|
||||
|
||||
fn default_render(&self, _: &mut PageAssets) -> Markup {
|
||||
html! {
|
||||
@for html in self.html().iter() {
|
||||
(*html)
|
||||
}
|
||||
}
|
||||
html! { (*self.html()) }
|
||||
}
|
||||
}
|
||||
|
||||
impl Chunck {
|
||||
pub fn with(html: Markup) -> Self {
|
||||
let mut chunck = Chunck::new();
|
||||
chunck.add(html);
|
||||
chunck.html = html;
|
||||
chunck
|
||||
}
|
||||
|
||||
// Chunck BUILDER.
|
||||
|
||||
pub fn with_renderable(&mut self, renderable: fn() -> bool) -> &Self {
|
||||
pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self {
|
||||
self.renderable = renderable;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_weight(&mut self, weight: i8) -> &Self {
|
||||
pub fn with_weight(mut self, weight: i8) -> Self {
|
||||
self.weight = weight;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add(&mut self, html: Markup) -> &Self {
|
||||
self.html.push(html);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn using_template(&mut self, template: &str) -> &Self {
|
||||
pub fn using_template(mut self, template: &str) -> Self {
|
||||
self.template = template.to_owned();
|
||||
self
|
||||
}
|
||||
|
||||
// Chunck GETTERS.
|
||||
|
||||
pub fn html(&self) -> &Vec<Markup> {
|
||||
pub fn html(&self) -> &Markup {
|
||||
&self.html
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@ pub enum ContainerType { Header, Footer, Main, Section, Wrapper }
|
|||
pub struct Container {
|
||||
renderable: fn() -> bool,
|
||||
weight : i8,
|
||||
container : ContainerType,
|
||||
components: PageContainer,
|
||||
container : ContainerType,
|
||||
id : OptIden,
|
||||
classes : Classes,
|
||||
template : String,
|
||||
|
|
@ -17,8 +17,8 @@ impl PageComponent for Container {
|
|||
Container {
|
||||
renderable: always,
|
||||
weight : 0,
|
||||
container : ContainerType::Wrapper,
|
||||
components: PageContainer::new(),
|
||||
container : ContainerType::Wrapper,
|
||||
id : OptIden::none(),
|
||||
classes : Classes::none(),
|
||||
template : "default".to_owned(),
|
||||
|
|
@ -97,39 +97,45 @@ impl Container {
|
|||
c
|
||||
}
|
||||
|
||||
// Container BUILDER.
|
||||
// Container CONTAINER.
|
||||
|
||||
pub fn with_renderable(&mut self, renderable: fn() -> bool) -> &Self {
|
||||
self.renderable = renderable;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_weight(&mut self, weight: i8) -> &Self {
|
||||
self.weight = weight;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add(mut self, component: ArcComponent) -> Self {
|
||||
pub fn add(mut self, component: impl PageComponent) -> Self {
|
||||
self.components.add(component);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_id(&mut self, id: &str) -> &Self {
|
||||
pub fn components(&self) -> &PageContainer {
|
||||
&self.components
|
||||
}
|
||||
|
||||
// Container BUILDER.
|
||||
|
||||
pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self {
|
||||
self.renderable = renderable;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_weight(mut self, weight: i8) -> Self {
|
||||
self.weight = weight;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_id(mut self, id: &str) -> Self {
|
||||
self.id.with_value(id);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn set_classes(&mut self, classes: &str) -> &Self {
|
||||
pub fn set_classes(mut self, classes: &str) -> Self {
|
||||
self.classes.set_classes(classes);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_classes(&mut self, classes: &str) -> &Self {
|
||||
pub fn add_classes(mut self, classes: &str) -> Self {
|
||||
self.classes.add_classes(classes);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn using_template(&mut self, template: &str) -> &Self {
|
||||
pub fn using_template(mut self, template: &str) -> Self {
|
||||
self.template = template.to_owned();
|
||||
self
|
||||
}
|
||||
|
|
@ -140,10 +146,6 @@ impl Container {
|
|||
&self.container
|
||||
}
|
||||
|
||||
pub fn components(&self) -> &PageContainer {
|
||||
&self.components
|
||||
}
|
||||
|
||||
pub fn id(&self) -> &Option<String> {
|
||||
self.id.option()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,48 +68,44 @@ impl PageComponent for Button {
|
|||
|
||||
impl Button {
|
||||
pub fn button(value: &str) -> Self {
|
||||
let mut button = Button::new();
|
||||
button.with_value(value);
|
||||
button
|
||||
Button::new().with_value(value)
|
||||
}
|
||||
|
||||
pub fn reset(value: &str) -> Self {
|
||||
let mut button = Button::new();
|
||||
button.with_value(value);
|
||||
let mut button = Button::new().with_value(value);
|
||||
button.button_type = ButtonType::Reset;
|
||||
button
|
||||
}
|
||||
|
||||
pub fn submit(value: &str) -> Self {
|
||||
let mut button = Button::new();
|
||||
button.with_value(value);
|
||||
let mut button = Button::new().with_value(value);
|
||||
button.button_type = ButtonType::Submit;
|
||||
button
|
||||
}
|
||||
|
||||
// Button BUILDER.
|
||||
|
||||
pub fn with_renderable(&mut self, renderable: fn() -> bool) -> &Self {
|
||||
pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self {
|
||||
self.renderable = renderable;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_weight(&mut self, weight: i8) -> &Self {
|
||||
pub fn with_weight(mut self, weight: i8) -> Self {
|
||||
self.weight = weight;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_name(&mut self, name: &str) -> &Self {
|
||||
pub fn with_name(mut self, name: &str) -> Self {
|
||||
self.name.with_value(name);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_value(&mut self, value: &str) -> &Self {
|
||||
pub fn with_value(mut self, value: &str) -> Self {
|
||||
self.value.with_value(value);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_autofocus(&mut self, toggle: bool) -> &Self {
|
||||
pub fn with_autofocus(mut self, toggle: bool) -> Self {
|
||||
self.autofocus.with_value(match toggle {
|
||||
true => "autofocus",
|
||||
false => "",
|
||||
|
|
@ -117,7 +113,7 @@ impl Button {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn with_disabled(&mut self, toggle: bool) -> &Self {
|
||||
pub fn with_disabled(mut self, toggle: bool) -> Self {
|
||||
self.disabled.with_value(match toggle {
|
||||
true => "disabled",
|
||||
false => "",
|
||||
|
|
@ -125,17 +121,17 @@ impl Button {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn set_classes(&mut self, classes: &str) -> &Self {
|
||||
pub fn set_classes(mut self, classes: &str) -> Self {
|
||||
self.classes.set_classes(classes);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_classes(&mut self, classes: &str) -> &Self {
|
||||
pub fn add_classes(mut self, classes: &str) -> Self {
|
||||
self.classes.add_classes(classes);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn using_template(&mut self, template: &str) -> &Self {
|
||||
pub fn using_template(mut self, template: &str) -> Self {
|
||||
self.template = template.to_owned();
|
||||
self
|
||||
}
|
||||
|
|
|
|||
|
|
@ -95,37 +95,37 @@ impl Date {
|
|||
|
||||
// Date BUILDER.
|
||||
|
||||
pub fn with_renderable(&mut self, renderable: fn() -> bool) -> &Self {
|
||||
pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self {
|
||||
self.renderable = renderable;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_weight(&mut self, weight: i8) -> &Self {
|
||||
pub fn with_weight(mut self, weight: i8) -> Self {
|
||||
self.weight = weight;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_name(&mut self, name: &str) -> &Self {
|
||||
pub fn with_name(mut self, name: &str) -> Self {
|
||||
self.name.with_value(name);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_value(&mut self, value: &str) -> &Self {
|
||||
pub fn with_value(mut self, value: &str) -> Self {
|
||||
self.value.with_value(value);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_label(&mut self, label: &str) -> &Self {
|
||||
pub fn with_label(mut self, label: &str) -> Self {
|
||||
self.label.with_value(label);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_placeholder(&mut self, placeholder: &str) -> &Self {
|
||||
pub fn with_placeholder(mut self, placeholder: &str) -> Self {
|
||||
self.placeholder.with_value(placeholder);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_autofocus(&mut self, toggle: bool) -> &Self {
|
||||
pub fn with_autofocus(mut self, toggle: bool) -> Self {
|
||||
self.autofocus.with_value(match toggle {
|
||||
true => "autofocus",
|
||||
false => "",
|
||||
|
|
@ -133,7 +133,7 @@ impl Date {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn with_autocomplete(&mut self, toggle: bool) -> &Self {
|
||||
pub fn with_autocomplete(mut self, toggle: bool) -> Self {
|
||||
self.autocomplete.with_value(match toggle {
|
||||
true => "",
|
||||
false => "off",
|
||||
|
|
@ -141,7 +141,7 @@ impl Date {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn with_disabled(&mut self, toggle: bool) -> &Self {
|
||||
pub fn with_disabled(mut self, toggle: bool) -> Self {
|
||||
self.disabled.with_value(match toggle {
|
||||
true => "disabled",
|
||||
false => "",
|
||||
|
|
@ -149,7 +149,7 @@ impl Date {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn with_readonly(&mut self, toggle: bool) -> &Self {
|
||||
pub fn with_readonly(mut self, toggle: bool) -> Self {
|
||||
self.readonly.with_value(match toggle {
|
||||
true => "readonly",
|
||||
false => "",
|
||||
|
|
@ -157,7 +157,7 @@ impl Date {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn with_required(&mut self, toggle: bool) -> &Self {
|
||||
pub fn with_required(mut self, toggle: bool) -> Self {
|
||||
self.required.with_value(match toggle {
|
||||
true => "required",
|
||||
false => "",
|
||||
|
|
@ -165,22 +165,22 @@ impl Date {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn with_help_text(&mut self, help_text: &str) -> &Self {
|
||||
pub fn with_help_text(mut self, help_text: &str) -> Self {
|
||||
self.help_text.with_value(help_text);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn set_classes(&mut self, classes: &str) -> &Self {
|
||||
pub fn set_classes(mut self, classes: &str) -> Self {
|
||||
self.classes.set_classes(classes);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_classes(&mut self, classes: &str) -> &Self {
|
||||
pub fn add_classes(mut self, classes: &str) -> Self {
|
||||
self.classes.add_classes(classes);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn using_template(&mut self, template: &str) -> &Self {
|
||||
pub fn using_template(mut self, template: &str) -> Self {
|
||||
self.template = template.to_owned();
|
||||
self
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,10 +5,10 @@ pub enum FormMethod {Get, Post}
|
|||
pub struct Form {
|
||||
renderable: fn() -> bool,
|
||||
weight : i8,
|
||||
elements : PageContainer,
|
||||
action : OptAttr,
|
||||
charset : OptAttr,
|
||||
method : FormMethod,
|
||||
elements : PageContainer,
|
||||
id : OptIden,
|
||||
classes : Classes,
|
||||
template : String,
|
||||
|
|
@ -19,10 +19,10 @@ impl PageComponent for Form {
|
|||
Form {
|
||||
renderable: always,
|
||||
weight : 0,
|
||||
elements : PageContainer::new(),
|
||||
action : OptAttr::none(),
|
||||
charset : OptAttr::some("UTF-8"),
|
||||
method : FormMethod::Post,
|
||||
elements : PageContainer::new(),
|
||||
id : OptIden::none(),
|
||||
classes : Classes::none(),
|
||||
template : "default".to_owned(),
|
||||
|
|
@ -58,54 +58,60 @@ impl PageComponent for Form {
|
|||
|
||||
impl Form {
|
||||
|
||||
// Form BUILDER.
|
||||
// Form CONTAINER.
|
||||
|
||||
pub fn with_renderable(&mut self, renderable: fn() -> bool) -> &Self {
|
||||
self.renderable = renderable;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_weight(&mut self, weight: i8) -> &Self {
|
||||
self.weight = weight;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_action(&mut self, action: &str) -> &Self {
|
||||
self.action.with_value(action);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_charset(&mut self, charset: &str) -> &Self {
|
||||
self.charset.with_value(charset);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_method(&mut self, method: FormMethod) -> &Self {
|
||||
self.method = method;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add(mut self, element: ArcComponent) -> Self {
|
||||
pub fn add(mut self, element: impl PageComponent) -> Self {
|
||||
self.elements.add(element);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_id(&mut self, id: &str) -> &Self {
|
||||
pub fn elements(&self) -> &PageContainer {
|
||||
&self.elements
|
||||
}
|
||||
|
||||
// Form BUILDER.
|
||||
|
||||
pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self {
|
||||
self.renderable = renderable;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_weight(mut self, weight: i8) -> Self {
|
||||
self.weight = weight;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_action(mut self, action: &str) -> Self {
|
||||
self.action.with_value(action);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_charset(mut self, charset: &str) -> Self {
|
||||
self.charset.with_value(charset);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_method(mut self, method: FormMethod) -> Self {
|
||||
self.method = method;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_id(mut self, id: &str) -> Self {
|
||||
self.id.with_value(id);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn set_classes(&mut self, classes: &str) -> &Self {
|
||||
pub fn set_classes(mut self, classes: &str) -> Self {
|
||||
self.classes.set_classes(classes);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_classes(&mut self, classes: &str) -> &Self {
|
||||
pub fn add_classes(mut self, classes: &str) -> Self {
|
||||
self.classes.add_classes(classes);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn using_template(&mut self, template: &str) -> &Self {
|
||||
pub fn using_template(mut self, template: &str) -> Self {
|
||||
self.template = template.to_owned();
|
||||
self
|
||||
}
|
||||
|
|
@ -124,10 +130,6 @@ impl Form {
|
|||
&self.method
|
||||
}
|
||||
|
||||
pub fn elements(&self) -> &PageContainer {
|
||||
&self.elements
|
||||
}
|
||||
|
||||
pub fn id(&self) -> &Option<String> {
|
||||
self.id.option()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,25 +32,24 @@ impl PageComponent for Hidden {
|
|||
|
||||
impl Hidden {
|
||||
pub fn set(name: &str, value: &str) -> Self {
|
||||
let mut hidden = Hidden::new();
|
||||
hidden.with_name(name);
|
||||
hidden.with_value(value);
|
||||
hidden
|
||||
Hidden::new()
|
||||
.with_name(name)
|
||||
.with_value(value)
|
||||
}
|
||||
|
||||
// Hidden BUILDER.
|
||||
|
||||
pub fn with_weight(&mut self, weight: i8) -> &Self {
|
||||
pub fn with_weight(mut self, weight: i8) -> Self {
|
||||
self.weight = weight;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_name(&mut self, name: &str) -> &Self {
|
||||
pub fn with_name(mut self, name: &str) -> Self {
|
||||
self.name.with_value(name);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_value(&mut self, value: &str) -> &Self {
|
||||
pub fn with_value(mut self, value: &str) -> Self {
|
||||
self.value.with_value(value);
|
||||
self
|
||||
}
|
||||
|
|
|
|||
|
|
@ -149,52 +149,52 @@ impl Input {
|
|||
|
||||
// Input BUILDER.
|
||||
|
||||
pub fn with_renderable(&mut self, renderable: fn() -> bool) -> &Self {
|
||||
pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self {
|
||||
self.renderable = renderable;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_weight(&mut self, weight: i8) -> &Self {
|
||||
pub fn with_weight(mut self, weight: i8) -> Self {
|
||||
self.weight = weight;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_name(&mut self, name: &str) -> &Self {
|
||||
pub fn with_name(mut self, name: &str) -> Self {
|
||||
self.name.with_value(name);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_value(&mut self, value: &str) -> &Self {
|
||||
pub fn with_value(mut self, value: &str) -> Self {
|
||||
self.value.with_value(value);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_label(&mut self, label: &str) -> &Self {
|
||||
pub fn with_label(mut self, label: &str) -> Self {
|
||||
self.label.with_value(label);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_size(&mut self, size: Option<u16>) -> &Self {
|
||||
pub fn with_size(mut self, size: Option<u16>) -> Self {
|
||||
self.size = size;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_minlength(&mut self, minlength: Option<u16>) -> &Self {
|
||||
pub fn with_minlength(mut self, minlength: Option<u16>) -> Self {
|
||||
self.minlength = minlength;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_maxlength(&mut self, maxlength: Option<u16>) -> &Self {
|
||||
pub fn with_maxlength(mut self, maxlength: Option<u16>) -> Self {
|
||||
self.maxlength = maxlength;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_placeholder(&mut self, placeholder: &str) -> &Self {
|
||||
pub fn with_placeholder(mut self, placeholder: &str) -> Self {
|
||||
self.placeholder.with_value(placeholder);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_autofocus(&mut self, toggle: bool) -> &Self {
|
||||
pub fn with_autofocus(mut self, toggle: bool) -> Self {
|
||||
self.autofocus.with_value(match toggle {
|
||||
true => "autofocus",
|
||||
false => "",
|
||||
|
|
@ -202,7 +202,7 @@ impl Input {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn with_autocomplete(&mut self, toggle: bool) -> &Self {
|
||||
pub fn with_autocomplete(mut self, toggle: bool) -> Self {
|
||||
self.autocomplete.with_value(match toggle {
|
||||
true => "",
|
||||
false => "off",
|
||||
|
|
@ -210,7 +210,7 @@ impl Input {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn with_disabled(&mut self, toggle: bool) -> &Self {
|
||||
pub fn with_disabled(mut self, toggle: bool) -> Self {
|
||||
self.disabled.with_value(match toggle {
|
||||
true => "disabled",
|
||||
false => "",
|
||||
|
|
@ -218,7 +218,7 @@ impl Input {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn with_readonly(&mut self, toggle: bool) -> &Self {
|
||||
pub fn with_readonly(mut self, toggle: bool) -> Self {
|
||||
self.readonly.with_value(match toggle {
|
||||
true => "readonly",
|
||||
false => "",
|
||||
|
|
@ -226,7 +226,7 @@ impl Input {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn with_required(&mut self, toggle: bool) -> &Self {
|
||||
pub fn with_required(mut self, toggle: bool) -> Self {
|
||||
self.required.with_value(match toggle {
|
||||
true => "required",
|
||||
false => "",
|
||||
|
|
@ -234,22 +234,22 @@ impl Input {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn with_help_text(&mut self, help_text: &str) -> &Self {
|
||||
pub fn with_help_text(mut self, help_text: &str) -> Self {
|
||||
self.help_text.with_value(help_text);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn set_classes(&mut self, classes: &str) -> &Self {
|
||||
pub fn set_classes(mut self, classes: &str) -> Self {
|
||||
self.classes.set_classes(classes);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_classes(&mut self, classes: &str) -> &Self {
|
||||
pub fn add_classes(mut self, classes: &str) -> Self {
|
||||
self.classes.add_classes(classes);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn using_template(&mut self, template: &str) -> &Self {
|
||||
pub fn using_template(mut self, template: &str) -> Self {
|
||||
self.template = template.to_owned();
|
||||
self
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,49 +44,51 @@ impl PageComponent for Column {
|
|||
|
||||
impl Column {
|
||||
|
||||
// Column BUILDER.
|
||||
// Column CONTAINER.
|
||||
|
||||
pub fn with_renderable(&mut self, renderable: fn() -> bool) -> &Self {
|
||||
self.renderable = renderable;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_weight(&mut self, weight: i8) -> &Self {
|
||||
self.weight = weight;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add(mut self, component: ArcComponent) -> Self {
|
||||
pub fn add(mut self, component: impl PageComponent) -> Self {
|
||||
self.components.add(component);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_id(&mut self, id: &str) -> &Self {
|
||||
pub fn components(&self) -> &PageContainer {
|
||||
&self.components
|
||||
}
|
||||
|
||||
// Column BUILDER.
|
||||
|
||||
pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self {
|
||||
self.renderable = renderable;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_weight(mut self, weight: i8) -> Self {
|
||||
self.weight = weight;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_id(mut self, id: &str) -> Self {
|
||||
self.id.with_value(id);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn set_classes(&mut self, classes: &str) -> &Self {
|
||||
pub fn set_classes(mut self, classes: &str) -> Self {
|
||||
self.classes.set_classes(classes);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_classes(&mut self, classes: &str) -> &Self {
|
||||
pub fn add_classes(mut self, classes: &str) -> Self {
|
||||
self.classes.add_classes(classes);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn using_template(&mut self, template: &str) -> &Self {
|
||||
pub fn using_template(mut self, template: &str) -> Self {
|
||||
self.template = template.to_owned();
|
||||
self
|
||||
}
|
||||
|
||||
// Column GETTERS.
|
||||
|
||||
pub fn components(&self) -> &PageContainer {
|
||||
&self.components
|
||||
}
|
||||
|
||||
pub fn id(&self) -> &Option<String> {
|
||||
self.id.option()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,49 +44,51 @@ impl PageComponent for Row {
|
|||
|
||||
impl Row {
|
||||
|
||||
// Row CONTAINER.
|
||||
|
||||
pub fn add_column(mut self, column: grid::Column) -> Self {
|
||||
self.columns.add(column);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn columns(&self) -> &PageContainer {
|
||||
&self.columns
|
||||
}
|
||||
|
||||
// Row BUILDER.
|
||||
|
||||
pub fn with_renderable(&mut self, renderable: fn() -> bool) -> &Self {
|
||||
pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self {
|
||||
self.renderable = renderable;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_weight(&mut self, weight: i8) -> &Self {
|
||||
pub fn with_weight(mut self, weight: i8) -> Self {
|
||||
self.weight = weight;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_column(mut self, column: grid::Column) -> Self {
|
||||
self.columns.add(column.arc());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_id(&mut self, id: &str) -> &Self {
|
||||
pub fn with_id(mut self, id: &str) -> Self {
|
||||
self.id.with_value(id);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn set_classes(&mut self, classes: &str) -> &Self {
|
||||
pub fn set_classes(mut self, classes: &str) -> Self {
|
||||
self.classes.set_classes(classes);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_classes(&mut self, classes: &str) -> &Self {
|
||||
pub fn add_classes(mut self, classes: &str) -> Self {
|
||||
self.classes.add_classes(classes);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn using_template(&mut self, template: &str) -> &Self {
|
||||
pub fn using_template(mut self, template: &str) -> Self {
|
||||
self.template = template.to_owned();
|
||||
self
|
||||
}
|
||||
|
||||
// Row GETTERS.
|
||||
|
||||
pub fn columns(&self) -> &PageContainer {
|
||||
&self.columns
|
||||
}
|
||||
|
||||
pub fn id(&self) -> &Option<String> {
|
||||
self.id.option()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,44 +41,42 @@ impl PageComponent for Image {
|
|||
|
||||
impl Image {
|
||||
pub fn image(source: &str) -> Self {
|
||||
let mut image = Image::new();
|
||||
image.with_source(source);
|
||||
image
|
||||
Image::new().with_source(source)
|
||||
}
|
||||
|
||||
// Image BUILDER.
|
||||
|
||||
pub fn with_renderable(&mut self, renderable: fn() -> bool) -> &Self {
|
||||
pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self {
|
||||
self.renderable = renderable;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_weight(&mut self, weight: i8) -> &Self {
|
||||
pub fn with_weight(mut self, weight: i8) -> Self {
|
||||
self.weight = weight;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_source(&mut self, source: &str) -> &Self {
|
||||
pub fn with_source(mut self, source: &str) -> Self {
|
||||
self.source.with_value(source);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_id(&mut self, id: &str) -> &Self {
|
||||
pub fn with_id(mut self, id: &str) -> Self {
|
||||
self.id.with_value(id);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn set_classes(&mut self, classes: &str) -> &Self {
|
||||
pub fn set_classes(mut self, classes: &str) -> Self {
|
||||
self.classes.set_classes(classes);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_classes(&mut self, classes: &str) -> &Self {
|
||||
pub fn add_classes(mut self, classes: &str) -> Self {
|
||||
self.classes.add_classes(classes);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn using_template(&mut self, template: &str) -> &Self {
|
||||
pub fn using_template(mut self, template: &str) -> Self {
|
||||
self.template = template.to_owned();
|
||||
self
|
||||
}
|
||||
|
|
|
|||
|
|
@ -209,6 +209,17 @@ impl PageComponent for Menu {
|
|||
|
||||
impl Menu {
|
||||
|
||||
// Menu CONTAINER.
|
||||
|
||||
pub fn add(mut self, item: MenuItem) -> Self {
|
||||
self.items.add(item);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn items(&self) -> &PageContainer {
|
||||
&self.items
|
||||
}
|
||||
|
||||
// Menu BUILDER.
|
||||
|
||||
pub fn with_renderable(mut self, renderable: fn() -> bool) -> Self {
|
||||
|
|
@ -221,11 +232,6 @@ impl Menu {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn add(mut self, item: MenuItem) -> Self {
|
||||
self.items.add(item.arc());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_id(mut self, id: &str) -> Self {
|
||||
self.id.with_value(id);
|
||||
self
|
||||
|
|
@ -248,10 +254,6 @@ impl Menu {
|
|||
|
||||
// Menu GETTERS.
|
||||
|
||||
pub fn items(&self) -> &PageContainer {
|
||||
&self.items
|
||||
}
|
||||
|
||||
pub fn id(&self) -> &Option<String> {
|
||||
self.id.option()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ async fn demo() -> app::Result<Markup> {
|
|||
.render()
|
||||
}
|
||||
|
||||
fn hello_world() -> ArcComponent {
|
||||
fn hello_world() -> Container {
|
||||
Container::header()
|
||||
.add(grid::Row::new()
|
||||
.add_column(grid::Column::new()
|
||||
|
|
@ -68,17 +68,15 @@ fn hello_world() -> ArcComponent {
|
|||
i class="fas fa-paper-plane" {}
|
||||
"Get quote"
|
||||
}
|
||||
}).arc())
|
||||
}))
|
||||
)
|
||||
.add_column(grid::Column::new()
|
||||
.add(Image::image("/bootsier/images/demo-header.svg").arc())
|
||||
.add(Image::image("/bootsier/images/demo-header.svg"))
|
||||
)
|
||||
.arc()
|
||||
)
|
||||
.arc()
|
||||
}
|
||||
|
||||
fn hello_world_original() -> ArcComponent {
|
||||
fn hello_world_original() -> Chunck {
|
||||
Chunck::with(html! {
|
||||
header id="header" class="header" {
|
||||
div class="container" {
|
||||
|
|
@ -123,10 +121,10 @@ fn hello_world_original() -> ArcComponent {
|
|||
}
|
||||
}
|
||||
}
|
||||
}).arc()
|
||||
})
|
||||
}
|
||||
|
||||
fn just_visiting() -> ArcComponent {
|
||||
fn just_visiting() -> Chunck {
|
||||
Chunck::with(html! {
|
||||
div id="details" class="basic-1" {
|
||||
div class="container" {
|
||||
|
|
@ -153,10 +151,10 @@ fn just_visiting() -> ArcComponent {
|
|||
}
|
||||
}
|
||||
}
|
||||
}).arc()
|
||||
})
|
||||
}
|
||||
|
||||
fn about_pagetop() -> ArcComponent {
|
||||
fn about_pagetop() -> Chunck {
|
||||
Chunck::with(html! {
|
||||
div id="pagetop" class="basic-2" {
|
||||
div class="container" {
|
||||
|
|
@ -177,10 +175,10 @@ fn about_pagetop() -> ArcComponent {
|
|||
}
|
||||
}
|
||||
}
|
||||
}).arc()
|
||||
})
|
||||
}
|
||||
|
||||
fn promo_pagetop() -> ArcComponent {
|
||||
fn promo_pagetop() -> Chunck {
|
||||
Chunck::with(html! {
|
||||
div id="promo" class="basic-3" {
|
||||
div class="container" {
|
||||
|
|
@ -202,10 +200,10 @@ fn promo_pagetop() -> ArcComponent {
|
|||
}
|
||||
}
|
||||
}
|
||||
}).arc()
|
||||
})
|
||||
}
|
||||
|
||||
fn reporting_problems() -> ArcComponent {
|
||||
fn reporting_problems() -> Chunck {
|
||||
Chunck::with(html! {
|
||||
div id="reporting" class="basic-4" {
|
||||
div class="container" {
|
||||
|
|
@ -225,5 +223,5 @@ fn reporting_problems() -> ArcComponent {
|
|||
}
|
||||
}
|
||||
}
|
||||
}).arc()
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ impl ThemeTrait for BootsierTheme {
|
|||
}
|
||||
}
|
||||
}
|
||||
}).arc())
|
||||
}))
|
||||
.render()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,11 +3,8 @@ use crate::response::page::PageAssets;
|
|||
|
||||
use downcast_rs::{Downcast, impl_downcast};
|
||||
|
||||
use std::sync::Arc;
|
||||
use std::any::type_name;
|
||||
|
||||
pub type ArcComponent = Arc<dyn PageComponent>;
|
||||
|
||||
pub trait PageComponent: Downcast + Send + Sync {
|
||||
|
||||
fn new() -> Self where Self: Sized;
|
||||
|
|
@ -36,12 +33,6 @@ pub trait PageComponent: Downcast + Send + Sync {
|
|||
0
|
||||
}
|
||||
|
||||
#[allow(unused_mut)]
|
||||
fn arc(mut self) -> ArcComponent where Self: Sized {
|
||||
let component = self;
|
||||
Arc::new(component)
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn default_render(&self, assets: &mut PageAssets) -> Markup {
|
||||
html! {}
|
||||
|
|
|
|||
|
|
@ -1,22 +1,24 @@
|
|||
use crate::html::{Markup, html};
|
||||
use crate::response::page::{ArcComponent, PageAssets, render_component};
|
||||
use crate::response::page::{PageAssets, PageComponent, render_component};
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct PageContainer(Vec<ArcComponent>);
|
||||
pub struct PageContainer(Vec<Arc<dyn PageComponent>>);
|
||||
|
||||
impl PageContainer {
|
||||
pub fn new() -> Self {
|
||||
PageContainer(Vec::new())
|
||||
}
|
||||
|
||||
pub fn new_with(component: ArcComponent) -> Self {
|
||||
pub fn new_with(component: impl PageComponent) -> Self {
|
||||
let mut container = PageContainer::new();
|
||||
container.add(component);
|
||||
container
|
||||
}
|
||||
|
||||
pub fn add(&mut self, component: ArcComponent) {
|
||||
self.0.push(component);
|
||||
pub fn add(&mut self, component: impl PageComponent) {
|
||||
self.0.push(Arc::new(component));
|
||||
}
|
||||
|
||||
pub fn render(&self, assets: &mut PageAssets) -> Markup {
|
||||
|
|
@ -28,4 +30,4 @@ impl PageContainer {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ pub use assets::{
|
|||
};
|
||||
|
||||
mod component;
|
||||
pub use component::{ArcComponent, PageComponent};
|
||||
pub use component::PageComponent;
|
||||
|
||||
mod container;
|
||||
pub use container::PageContainer;
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ impl<'a> Page<'a> {
|
|||
pub fn add_to(
|
||||
&mut self,
|
||||
region: &'a str,
|
||||
component: ArcComponent
|
||||
component: impl PageComponent
|
||||
) -> &mut Self {
|
||||
if let Some(regions) = self.regions.get_mut(region) {
|
||||
regions.add(component);
|
||||
|
|
@ -205,7 +205,7 @@ pub fn render_component(
|
|||
}
|
||||
}
|
||||
|
||||
pub fn add_component_to(region: &'static str, component: ArcComponent) {
|
||||
pub fn add_component_to(region: &'static str, component: impl PageComponent) {
|
||||
let mut hmap = COMPONENTS.write().unwrap();
|
||||
if let Some(regions) = hmap.get_mut(region) {
|
||||
regions.add(component);
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ pub trait ThemeTrait: Send + Sync {
|
|||
div {
|
||||
h1 { (s) }
|
||||
}
|
||||
}).arc())
|
||||
}))
|
||||
.render()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue