Modifica PageContainer para ser ComponentsHolder

This commit is contained in:
Manuel Cillero 2022-05-06 00:27:21 +02:00
parent c2b69fa539
commit d53408c6b6
11 changed files with 36 additions and 32 deletions

View file

@ -9,7 +9,7 @@ mod holder;
pub use holder::{
ActionItem,
};
pub(crate) use holder::{
use holder::{
ActionsHolder,
};

View file

@ -1,10 +1,10 @@
use crate::Lazy;
use super::{ComponentTrait, PageContainer};
use super::{ComponentsHolder, ComponentTrait};
use std::sync::RwLock;
use std::collections::HashMap;
static COMPONENTS: Lazy<RwLock<HashMap<&str, PageContainer>>> = Lazy::new(|| {
static COMPONENTS: Lazy<RwLock<HashMap<&str, ComponentsHolder>>> = Lazy::new(|| {
RwLock::new(HashMap::new())
});
@ -13,10 +13,10 @@ pub fn add_component_to(region: &'static str, component: impl ComponentTrait) {
if let Some(regions) = hmap.get_mut(region) {
regions.add(component);
} else {
hmap.insert(region, PageContainer::new_with(component));
hmap.insert(region, ComponentsHolder::new_with(component));
}
}
pub fn common_components() -> HashMap<&'static str, PageContainer> {
pub fn common_components() -> HashMap<&'static str, ComponentsHolder> {
COMPONENTS.read().unwrap().clone()
}

View file

@ -4,15 +4,15 @@ use super::{ComponentTrait, PageAssets};
use std::sync::{Arc, RwLock};
#[derive(Clone)]
pub struct PageContainer(Vec<Arc<RwLock<dyn ComponentTrait>>>);
pub struct ComponentsHolder(Vec<Arc<RwLock<dyn ComponentTrait>>>);
impl PageContainer {
impl ComponentsHolder {
pub fn new() -> Self {
PageContainer(Vec::new())
ComponentsHolder(Vec::new())
}
pub fn new_with(component: impl ComponentTrait) -> Self {
let mut container = PageContainer::new();
let mut container = ComponentsHolder::new();
container.add(component);
container
}

View file

@ -20,10 +20,14 @@ pub use definition::{
component_ref,
component_mut,
};
use definition::render_component;
use definition::{
render_component,
};
mod container;
pub use container::PageContainer;
mod holder;
pub use holder::{
ComponentsHolder,
};
mod all;
pub use all::{

View file

@ -5,7 +5,7 @@ pub const TYPENAME_BLOCK: &str = "pagetop::base::component::block::Block";
pub struct Block {
renderable: fn() -> bool,
weight : isize,
components: PageContainer,
components: ComponentsHolder,
title : OptAttr,
id : OptIden,
classes : Classes,
@ -17,7 +17,7 @@ impl ComponentTrait for Block {
Block {
renderable: render_always,
weight : 0,
components: PageContainer::new(),
components: ComponentsHolder::new(),
title : OptAttr::new(),
id : OptIden::new(),
classes : Classes::new_with_default("block"),
@ -66,7 +66,7 @@ impl Block {
self
}
pub fn components(&self) -> &PageContainer {
pub fn components(&self) -> &ComponentsHolder {
&self.components
}

View file

@ -7,7 +7,7 @@ pub enum ContainerType { Header, Footer, Main, Section, Wrapper }
pub struct Container {
renderable : fn() -> bool,
weight : isize,
components : PageContainer,
components : ComponentsHolder,
container : ContainerType,
id : OptIden,
classes : Classes,
@ -20,7 +20,7 @@ impl ComponentTrait for Container {
Container {
renderable : render_always,
weight : 0,
components : PageContainer::new(),
components : ComponentsHolder::new(),
container : ContainerType::Wrapper,
id : OptIden::new(),
classes : Classes::new_with_default("container"),
@ -116,7 +116,7 @@ impl Container {
self
}
pub fn components(&self) -> &PageContainer {
pub fn components(&self) -> &ComponentsHolder {
&self.components
}

View file

@ -7,7 +7,7 @@ pub enum FormMethod {Get, Post}
pub struct Form {
renderable: fn() -> bool,
weight : isize,
elements : PageContainer,
elements : ComponentsHolder,
action : OptAttr,
charset : OptAttr,
method : FormMethod,
@ -21,7 +21,7 @@ impl ComponentTrait for Form {
Form {
renderable: render_always,
weight : 0,
elements : PageContainer::new(),
elements : ComponentsHolder::new(),
action : OptAttr::new(),
charset : OptAttr::new_with_value("UTF-8"),
method : FormMethod::Post,
@ -75,7 +75,7 @@ impl Form {
self
}
pub fn elements(&self) -> &PageContainer {
pub fn elements(&self) -> &ComponentsHolder {
&self.elements
}

View file

@ -5,7 +5,7 @@ pub const TYPENAME_COLUMN: &str = "pagetop::base::component::grid::column::Colum
pub struct Column {
renderable: fn() -> bool,
weight : isize,
components: PageContainer,
components: ComponentsHolder,
id : OptIden,
classes : Classes,
template : String,
@ -16,7 +16,7 @@ impl ComponentTrait for Column {
Column {
renderable: render_always,
weight : 0,
components: PageContainer::new(),
components: ComponentsHolder::new(),
id : OptIden::new(),
classes : Classes::new_with_default("col"),
template : "default".to_owned(),
@ -57,7 +57,7 @@ impl Column {
self
}
pub fn components(&self) -> &PageContainer {
pub fn components(&self) -> &ComponentsHolder {
&self.components
}

View file

@ -5,7 +5,7 @@ pub const TYPENAME_ROW: &str = "pagetop::base::component::grid::row::Row";
pub struct Row {
renderable: fn() -> bool,
weight : isize,
columns : PageContainer,
columns : ComponentsHolder,
id : OptIden,
classes : Classes,
template : String,
@ -16,7 +16,7 @@ impl ComponentTrait for Row {
Row {
renderable: render_always,
weight : 0,
columns : PageContainer::new(),
columns : ComponentsHolder::new(),
id : OptIden::new(),
classes : Classes::new_with_default("row"),
template : "default".to_owned(),
@ -57,7 +57,7 @@ impl Row {
self
}
pub fn columns(&self) -> &PageContainer {
pub fn columns(&self) -> &ComponentsHolder {
&self.columns
}

View file

@ -172,7 +172,7 @@ impl MenuItem {
pub struct Menu {
renderable: fn() -> bool,
weight : isize,
items : PageContainer,
items : ComponentsHolder,
id : OptIden,
classes : Classes,
template : String,
@ -183,7 +183,7 @@ impl ComponentTrait for Menu {
Menu {
renderable: render_always,
weight : 0,
items : PageContainer::new(),
items : ComponentsHolder::new(),
id : OptIden::new(),
classes : Classes::new_with_default("sm sm-clean"),
template : "default".to_owned(),
@ -243,7 +243,7 @@ impl Menu {
self
}
pub fn items(&self) -> &PageContainer {
pub fn items(&self) -> &ComponentsHolder {
&self.items
}

View file

@ -42,7 +42,7 @@ pub struct Page<'a> {
title : OptAttr,
description : OptAttr,
assets : PageAssets,
regions : HashMap<&'a str, PageContainer>,
regions : HashMap<&'a str, ComponentsHolder>,
body_classes: Classes,
template : String,
}
@ -102,7 +102,7 @@ impl<'a> Page<'a> {
if let Some(regions) = self.regions.get_mut(region) {
regions.add(component);
} else {
self.regions.insert(region, PageContainer::new_with(component));
self.regions.insert(region, ComponentsHolder::new_with(component));
}
self
}