From 93d6d455c8ecc8c37c4ac1c38cd9e859abcbdd0e Mon Sep 17 00:00:00 2001 From: Manuel Cillero Date: Wed, 6 Apr 2022 21:17:56 +0200 Subject: [PATCH] =?UTF-8?q?Actualiza=20y=20recupera=20definici=C3=B3n=20or?= =?UTF-8?q?iginal=20de=20comp.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prácticamente se revierten los últimos cambios realizados en la estructura de componentes. --- pagetop-admin/src/summary.rs | 7 +-- pagetop-user/src/lib.rs | 14 ++--- pagetop/src/base/component/block.rs | 45 ++++++-------- pagetop/src/base/component/chunck.rs | 25 +++----- pagetop/src/base/component/container.rs | 46 +++++++------- pagetop/src/base/component/form/button.rs | 28 ++++----- pagetop/src/base/component/form/date.rs | 30 ++++----- pagetop/src/base/component/form/form.rs | 76 ++++++++++++----------- pagetop/src/base/component/form/hidden.rs | 13 ++-- pagetop/src/base/component/form/input.rs | 36 +++++------ pagetop/src/base/component/grid/column.rs | 42 +++++++------ pagetop/src/base/component/grid/row.rs | 32 +++++----- pagetop/src/base/component/image.rs | 18 +++--- pagetop/src/base/component/menu.rs | 20 +++--- pagetop/src/base/module/demopage/mod.rs | 28 ++++----- pagetop/src/base/theme/bootsier/mod.rs | 2 +- pagetop/src/response/page/component.rs | 9 --- pagetop/src/response/page/container.rs | 14 +++-- pagetop/src/response/page/mod.rs | 2 +- pagetop/src/response/page/page.rs | 4 +- pagetop/src/theme/definition.rs | 2 +- 21 files changed, 234 insertions(+), 259 deletions(-) diff --git a/pagetop-admin/src/summary.rs b/pagetop-admin/src/summary.rs index 6e6f2158..b91b97fa 100644 --- a/pagetop-admin/src/summary.rs +++ b/pagetop-admin/src/summary.rs @@ -38,18 +38,17 @@ pub async fn summary() -> app::Result { .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() ) diff --git a/pagetop-user/src/lib.rs b/pagetop-user/src/lib.rs index 06b0dd1a..c40057f0 100644 --- a/pagetop-user/src/lib.rs +++ b/pagetop-user/src/lib.rs @@ -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 { Page::new() .with_title( "Identificación del usuario" - )/* + ) .add_to("content", Container::new() .with_id("welcome") .add(form_login()) - .arc() - )*/ + ) .render() } diff --git a/pagetop/src/base/component/block.rs b/pagetop/src/base/component/block.rs index 64dd8d7c..99950286 100644 --- a/pagetop/src/base/component/block.rs +++ b/pagetop/src/base/component/block.rs @@ -3,8 +3,8 @@ use crate::prelude::*; pub struct Block { renderable: fn() -> bool, weight : i8, + components: PageContainer, title : OptAttr, - html : Vec, 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 { - &self.html - } - pub fn id(&self) -> &Option { self.id.option() } diff --git a/pagetop/src/base/component/chunck.rs b/pagetop/src/base/component/chunck.rs index 7589ea4a..0e46c779 100644 --- a/pagetop/src/base/component/chunck.rs +++ b/pagetop/src/base/component/chunck.rs @@ -3,7 +3,7 @@ use crate::prelude::*; pub struct Chunck { renderable: fn() -> bool, weight : i8, - html : Vec, + 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 { + pub fn html(&self) -> &Markup { &self.html } diff --git a/pagetop/src/base/component/container.rs b/pagetop/src/base/component/container.rs index 79f9b7a5..70162bb9 100644 --- a/pagetop/src/base/component/container.rs +++ b/pagetop/src/base/component/container.rs @@ -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 { self.id.option() } diff --git a/pagetop/src/base/component/form/button.rs b/pagetop/src/base/component/form/button.rs index f6fd474d..f99f06d3 100644 --- a/pagetop/src/base/component/form/button.rs +++ b/pagetop/src/base/component/form/button.rs @@ -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 } diff --git a/pagetop/src/base/component/form/date.rs b/pagetop/src/base/component/form/date.rs index bc355a2a..40c2f784 100644 --- a/pagetop/src/base/component/form/date.rs +++ b/pagetop/src/base/component/form/date.rs @@ -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 } diff --git a/pagetop/src/base/component/form/form.rs b/pagetop/src/base/component/form/form.rs index 3685d9a1..07cb6e17 100644 --- a/pagetop/src/base/component/form/form.rs +++ b/pagetop/src/base/component/form/form.rs @@ -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 { self.id.option() } diff --git a/pagetop/src/base/component/form/hidden.rs b/pagetop/src/base/component/form/hidden.rs index 0e6e56c3..8f2cc4b3 100644 --- a/pagetop/src/base/component/form/hidden.rs +++ b/pagetop/src/base/component/form/hidden.rs @@ -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 } diff --git a/pagetop/src/base/component/form/input.rs b/pagetop/src/base/component/form/input.rs index c468cdfe..9d6e1afd 100644 --- a/pagetop/src/base/component/form/input.rs +++ b/pagetop/src/base/component/form/input.rs @@ -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) -> &Self { + pub fn with_size(mut self, size: Option) -> Self { self.size = size; self } - pub fn with_minlength(&mut self, minlength: Option) -> &Self { + pub fn with_minlength(mut self, minlength: Option) -> Self { self.minlength = minlength; self } - pub fn with_maxlength(&mut self, maxlength: Option) -> &Self { + pub fn with_maxlength(mut self, maxlength: Option) -> 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 } diff --git a/pagetop/src/base/component/grid/column.rs b/pagetop/src/base/component/grid/column.rs index e4e5525a..f29544ca 100644 --- a/pagetop/src/base/component/grid/column.rs +++ b/pagetop/src/base/component/grid/column.rs @@ -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 { self.id.option() } diff --git a/pagetop/src/base/component/grid/row.rs b/pagetop/src/base/component/grid/row.rs index 30a5f351..59645b79 100644 --- a/pagetop/src/base/component/grid/row.rs +++ b/pagetop/src/base/component/grid/row.rs @@ -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 { self.id.option() } diff --git a/pagetop/src/base/component/image.rs b/pagetop/src/base/component/image.rs index 30cca8f3..1384f4df 100644 --- a/pagetop/src/base/component/image.rs +++ b/pagetop/src/base/component/image.rs @@ -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 } diff --git a/pagetop/src/base/component/menu.rs b/pagetop/src/base/component/menu.rs index 3f2b4ff4..01a60129 100644 --- a/pagetop/src/base/component/menu.rs +++ b/pagetop/src/base/component/menu.rs @@ -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 { self.id.option() } diff --git a/pagetop/src/base/module/demopage/mod.rs b/pagetop/src/base/module/demopage/mod.rs index d71c7176..489b6d3b 100644 --- a/pagetop/src/base/module/demopage/mod.rs +++ b/pagetop/src/base/module/demopage/mod.rs @@ -35,7 +35,7 @@ async fn demo() -> app::Result { .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() + }) } diff --git a/pagetop/src/base/theme/bootsier/mod.rs b/pagetop/src/base/theme/bootsier/mod.rs index b169351d..90111723 100644 --- a/pagetop/src/base/theme/bootsier/mod.rs +++ b/pagetop/src/base/theme/bootsier/mod.rs @@ -77,7 +77,7 @@ impl ThemeTrait for BootsierTheme { } } } - }).arc()) + })) .render() } } diff --git a/pagetop/src/response/page/component.rs b/pagetop/src/response/page/component.rs index b9a920d3..630b8a9b 100644 --- a/pagetop/src/response/page/component.rs +++ b/pagetop/src/response/page/component.rs @@ -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; - 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! {} diff --git a/pagetop/src/response/page/container.rs b/pagetop/src/response/page/container.rs index 7e5d4953..011e5f50 100644 --- a/pagetop/src/response/page/container.rs +++ b/pagetop/src/response/page/container.rs @@ -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); +pub struct PageContainer(Vec>); 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 { } } } -} \ No newline at end of file +} diff --git a/pagetop/src/response/page/mod.rs b/pagetop/src/response/page/mod.rs index 63c19a47..f34070e2 100644 --- a/pagetop/src/response/page/mod.rs +++ b/pagetop/src/response/page/mod.rs @@ -7,7 +7,7 @@ pub use assets::{ }; mod component; -pub use component::{ArcComponent, PageComponent}; +pub use component::PageComponent; mod container; pub use container::PageContainer; diff --git a/pagetop/src/response/page/page.rs b/pagetop/src/response/page/page.rs index 5cbe80cb..5501678a 100644 --- a/pagetop/src/response/page/page.rs +++ b/pagetop/src/response/page/page.rs @@ -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); diff --git a/pagetop/src/theme/definition.rs b/pagetop/src/theme/definition.rs index db4c0e37..acc30f47 100644 --- a/pagetop/src/theme/definition.rs +++ b/pagetop/src/theme/definition.rs @@ -104,7 +104,7 @@ pub trait ThemeTrait: Send + Sync { div { h1 { (s) } } - }).arc()) + })) .render() } }