diff --git a/packages/pagetop-bootsier/src/bs/container.rs b/packages/pagetop-bootsier/src/bs/container.rs index 9de58b21..f6c41911 100644 --- a/packages/pagetop-bootsier/src/bs/container.rs +++ b/packages/pagetop-bootsier/src/bs/container.rs @@ -142,7 +142,7 @@ impl Container { } pub fn with_child(mut self, child: impl ComponentTrait) -> Self { - self.children.add(ChildComponent::with(child)); + self.children.add(Child::with(child)); self } diff --git a/packages/pagetop-bootsier/src/bs/grid/component.rs b/packages/pagetop-bootsier/src/bs/grid/component.rs index 4226f911..51ab3421 100644 --- a/packages/pagetop-bootsier/src/bs/grid/component.rs +++ b/packages/pagetop-bootsier/src/bs/grid/component.rs @@ -73,7 +73,7 @@ impl Grid { } pub fn with_item(mut self, item: grid::Item) -> Self { - self.items.add(ChildComponent::with(item)); + self.items.add(Child::with(item)); self } diff --git a/packages/pagetop-bootsier/src/bs/grid/item.rs b/packages/pagetop-bootsier/src/bs/grid/item.rs index f0ae5d74..6d527af6 100644 --- a/packages/pagetop-bootsier/src/bs/grid/item.rs +++ b/packages/pagetop-bootsier/src/bs/grid/item.rs @@ -85,7 +85,7 @@ impl Item { } pub fn with_child(mut self, child: impl ComponentTrait) -> Self { - self.children.add(ChildComponent::with(child)); + self.children.add(Child::with(child)); self } diff --git a/packages/pagetop-bootsier/src/bs/navbar/component.rs b/packages/pagetop-bootsier/src/bs/navbar/component.rs index fc113021..7f2586aa 100644 --- a/packages/pagetop-bootsier/src/bs/navbar/component.rs +++ b/packages/pagetop-bootsier/src/bs/navbar/component.rs @@ -9,7 +9,7 @@ pub enum NavbarType { #[default] Default, Basic, - Offcanvas(TypedComponent), + Offcanvas(Typed), } #[rustfmt::skip] @@ -52,7 +52,7 @@ impl ComponentTrait for Navbar { let (output, id_content) = if let NavbarType::Offcanvas(oc) = self.navbar_type() { ( oc.writable() - .alter_children(ChildOp::Prepend(ChildComponent::with(Html::with(elements)))) + .alter_children(ChildOp::Prepend(Child::with(Html::with(elements)))) .render(cx), cx.required_id::(oc.id()), ) diff --git a/packages/pagetop-bootsier/src/bs/navbar/nav.rs b/packages/pagetop-bootsier/src/bs/navbar/nav.rs index 3b522d28..ce21d0ab 100644 --- a/packages/pagetop-bootsier/src/bs/navbar/nav.rs +++ b/packages/pagetop-bootsier/src/bs/navbar/nav.rs @@ -53,7 +53,7 @@ impl Nav { } pub fn with_item(mut self, item: navbar::Item) -> Self { - self.items.add(ChildComponent::with(item)); + self.items.add(Child::with(item)); self } diff --git a/packages/pagetop-bootsier/src/bs/offcanvas/component.rs b/packages/pagetop-bootsier/src/bs/offcanvas/component.rs index 96060f42..8c246688 100644 --- a/packages/pagetop-bootsier/src/bs/offcanvas/component.rs +++ b/packages/pagetop-bootsier/src/bs/offcanvas/component.rs @@ -142,7 +142,7 @@ impl Offcanvas { } pub fn with_child(mut self, child: impl ComponentTrait) -> Self { - self.children.add(ChildComponent::with(child)); + self.children.add(Child::with(child)); self } diff --git a/pagetop/src/core/component.rs b/pagetop/src/core/component.rs index cca8baf9..7b38cc90 100644 --- a/pagetop/src/core/component.rs +++ b/pagetop/src/core/component.rs @@ -7,5 +7,5 @@ pub use definition::{ComponentBase, ComponentTrait}; mod children; pub use children::Children; -pub use children::{ChildComponent, ChildOp}; -pub use children::{TypedComponent, TypedOp}; +pub use children::{Child, ChildOp}; +pub use children::{Typed, TypedOp}; diff --git a/pagetop/src/core/component/children.rs b/pagetop/src/core/component/children.rs index 531f20c6..86ea53bc 100644 --- a/pagetop/src/core/component/children.rs +++ b/pagetop/src/core/component/children.rs @@ -5,14 +5,14 @@ use crate::{fn_builder, UniqueId}; use std::sync::{Arc, RwLock, RwLockWriteGuard}; #[derive(Clone)] -pub struct ChildComponent(Arc>); +pub struct Child(Arc>); -impl ChildComponent { +impl Child { pub fn with(component: impl ComponentTrait) -> Self { - ChildComponent(Arc::new(RwLock::new(component))) + Child(Arc::new(RwLock::new(component))) } - // ChildComponent GETTERS. + // Child GETTERS. pub fn id(&self) -> Option { self.0.read().unwrap().id() @@ -22,13 +22,13 @@ impl ChildComponent { self.0.write().unwrap() } - // ChildComponent RENDER. + // Child RENDER. pub fn render(&self, cx: &mut Context) -> Markup { self.0.write().unwrap().render(cx) } - // ChildComponent HELPERS. + // Child HELPERS. fn type_id(&self) -> UniqueId { self.0.read().unwrap().type_id() @@ -41,20 +41,20 @@ impl ChildComponent { // ************************************************************************************************* -pub struct TypedComponent(Arc>); +pub struct Typed(Arc>); -impl Clone for TypedComponent { +impl Clone for Typed { fn clone(&self) -> Self { Self(self.0.clone()) } } -impl TypedComponent { +impl Typed { pub fn with(component: C) -> Self { - TypedComponent(Arc::new(RwLock::new(component))) + Typed(Arc::new(RwLock::new(component))) } - // TypedComponent GETTERS. + // Typed GETTERS. pub fn id(&self) -> Option { self.0.read().unwrap().id() @@ -64,50 +64,50 @@ impl TypedComponent { self.0.write().unwrap() } - // TypedComponent RENDER. + // Typed RENDER. pub fn render(&self, cx: &mut Context) -> Markup { self.0.write().unwrap().render(cx) } - // TypedComponent HELPERS. + // Typed HELPERS. - fn to_child(&self) -> ChildComponent { - ChildComponent(self.0.clone()) + fn to_child(&self) -> Child { + Child(self.0.clone()) } } // ************************************************************************************************* pub enum ChildOp { - Add(ChildComponent), - InsertAfterId(&'static str, ChildComponent), - InsertBeforeId(&'static str, ChildComponent), - Prepend(ChildComponent), + Add(Child), + InsertAfterId(&'static str, Child), + InsertBeforeId(&'static str, Child), + Prepend(Child), RemoveById(&'static str), - ReplaceById(&'static str, ChildComponent), + ReplaceById(&'static str, Child), Reset, } pub enum TypedOp { - Add(TypedComponent), - InsertAfterId(&'static str, TypedComponent), - InsertBeforeId(&'static str, TypedComponent), - Prepend(TypedComponent), + Add(Typed), + InsertAfterId(&'static str, Typed), + InsertBeforeId(&'static str, Typed), + Prepend(Typed), RemoveById(&'static str), - ReplaceById(&'static str, TypedComponent), + ReplaceById(&'static str, Typed), Reset, } #[derive(Clone, Default)] -pub struct Children(Vec); +pub struct Children(Vec); impl Children { pub fn new() -> Self { Children::default() } - pub fn with(child: ChildComponent) -> Self { + pub fn with(child: Child) -> Self { Children::default().with_child(ChildOp::Add(child)) } @@ -148,13 +148,13 @@ impl Children { } #[inline] - pub fn add(&mut self, child: ChildComponent) -> &mut Self { + pub fn add(&mut self, child: Child) -> &mut Self { self.0.push(child); self } #[inline] - fn insert_after_id(&mut self, id: &str, child: ChildComponent) -> &mut Self { + fn insert_after_id(&mut self, id: &str, child: Child) -> &mut Self { match self.0.iter().position(|c| c.child_id() == id) { Some(index) => self.0.insert(index + 1, child), _ => self.0.push(child), @@ -163,7 +163,7 @@ impl Children { } #[inline] - fn insert_before_id(&mut self, id: &str, child: ChildComponent) -> &mut Self { + fn insert_before_id(&mut self, id: &str, child: Child) -> &mut Self { match self.0.iter().position(|c| c.child_id() == id) { Some(index) => self.0.insert(index, child), _ => self.0.insert(0, child), @@ -172,7 +172,7 @@ impl Children { } #[inline] - fn prepend(&mut self, child: ChildComponent) -> &mut Self { + fn prepend(&mut self, child: Child) -> &mut Self { self.0.insert(0, child); self } @@ -186,7 +186,7 @@ impl Children { } #[inline] - fn replace_by_id(&mut self, id: &str, child: ChildComponent) -> &mut Self { + fn replace_by_id(&mut self, id: &str, child: Child) -> &mut Self { for c in &mut self.0 { if c.child_id() == id { *c = child; @@ -212,17 +212,17 @@ impl Children { self.0.is_empty() } - pub fn get_by_id(&self, id: impl Into) -> Option<&ChildComponent> { + pub fn get_by_id(&self, id: impl Into) -> Option<&Child> { let id = id.into(); self.0.iter().find(|c| c.child_id() == id) } - pub fn iter_by_id(&self, id: impl Into) -> impl Iterator { + pub fn iter_by_id(&self, id: impl Into) -> impl Iterator { let id = id.into(); self.0.iter().filter(move |&c| c.child_id() == id) } - pub fn iter_by_type_id(&self, type_id: UniqueId) -> impl Iterator { + pub fn iter_by_type_id(&self, type_id: UniqueId) -> impl Iterator { self.0.iter().filter(move |&c| c.type_id() == type_id) } diff --git a/pagetop/src/core/theme/regions.rs b/pagetop/src/core/theme/regions.rs index acd6c37b..060bf7e5 100644 --- a/pagetop/src/core/theme/regions.rs +++ b/pagetop/src/core/theme/regions.rs @@ -1,4 +1,4 @@ -use crate::core::component::{ChildComponent, ChildOp, Children}; +use crate::core::component::{Child, ChildOp, Children}; use crate::core::theme::ThemeRef; use crate::{fn_builder, AutoDefault, UniqueId}; @@ -19,7 +19,7 @@ impl ChildrenInRegions { ChildrenInRegions::default() } - pub fn with(region_id: &'static str, child: ChildComponent) -> Self { + pub fn with(region_id: &'static str, child: Child) -> Self { ChildrenInRegions::default().with_in_region(region_id, ChildOp::Add(child)) } @@ -54,7 +54,7 @@ pub enum InRegion { } impl InRegion { - pub fn add(&self, child: ChildComponent) -> &Self { + pub fn add(&self, child: Child) -> &Self { match self { InRegion::Content => { COMMON_REGIONS diff --git a/pagetop/src/html/opt_component.rs b/pagetop/src/html/opt_component.rs index 858685a4..fe2a708e 100644 --- a/pagetop/src/html/opt_component.rs +++ b/pagetop/src/html/opt_component.rs @@ -1,8 +1,8 @@ -use crate::core::component::{ComponentTrait, Context, TypedComponent}; +use crate::core::component::{ComponentTrait, Context, Typed}; use crate::fn_builder; use crate::html::{html, Markup}; -pub struct OptionComponent(Option>); +pub struct OptionComponent(Option>); impl Default for OptionComponent { fn default() -> Self { @@ -20,7 +20,7 @@ impl OptionComponent { #[fn_builder] pub fn with_value(mut self, component: Option) -> Self { if let Some(component) = component { - self.0 = Some(TypedComponent::with(component)); + self.0 = Some(Typed::with(component)); } else { self.0 = None; } @@ -29,7 +29,7 @@ impl OptionComponent { // OptionComponent GETTERS. - pub fn get(&self) -> Option> { + pub fn get(&self) -> Option> { if let Some(value) = &self.0 { return Some(value.clone()); } diff --git a/pagetop/src/response/page.rs b/pagetop/src/response/page.rs index 7ae2f16c..2e223bfe 100644 --- a/pagetop/src/response/page.rs +++ b/pagetop/src/response/page.rs @@ -5,7 +5,7 @@ pub use actix_web::Result as ResultPage; use crate::base::action; use crate::core::component::{AssetsOp, Context}; -use crate::core::component::{ChildComponent, ChildOp, ComponentTrait}; +use crate::core::component::{Child, ChildOp, ComponentTrait}; use crate::fn_builder; use crate::html::{html, Markup, DOCTYPE}; use crate::html::{ClassesOp, OptionClasses, OptionId, OptionTranslated}; @@ -102,10 +102,8 @@ impl Page { } pub fn with_component(mut self, component: impl ComponentTrait) -> Self { - self.context.alter_in_region( - "region-content", - ChildOp::Add(ChildComponent::with(component)), - ); + self.context + .alter_in_region("region-content", ChildOp::Add(Child::with(component))); self } @@ -115,7 +113,7 @@ impl Page { component: impl ComponentTrait, ) -> Self { self.context - .alter_in_region(region, ChildOp::Add(ChildComponent::with(component))); + .alter_in_region(region, ChildOp::Add(Child::with(component))); self } diff --git a/website/src/main.rs b/website/src/main.rs index 256a7779..3a2bf096 100644 --- a/website/src/main.rs +++ b/website/src/main.rs @@ -27,7 +27,7 @@ impl PackageTrait for PageTopWebSite { } fn init(&self) { - let nav = Navbar::new().with_nav(TypedOp::Add(TypedComponent::with( + let nav = Navbar::new().with_nav(TypedOp::Add(Typed::with( navbar::Nav::new() .with_item(navbar::Item::link( L10n::t("menu_home", &LOCALES_WEBSITE), @@ -53,7 +53,7 @@ impl PackageTrait for PageTopWebSite { )), ))); - InRegion::Content.add(ChildComponent::with(nav)); + InRegion::Content.add(Child::with(nav)); /* let branding = Branding::new()