Modifica PageComponent por ComponentTrait
This commit is contained in:
parent
cd7020c77d
commit
37d0254055
18 changed files with 32 additions and 32 deletions
|
|
@ -10,7 +10,7 @@ pub struct Block {
|
||||||
template : String,
|
template : String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PageComponent for Block {
|
impl ComponentTrait for Block {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
Block {
|
Block {
|
||||||
renderable: render_always,
|
renderable: render_always,
|
||||||
|
|
@ -59,7 +59,7 @@ impl Block {
|
||||||
|
|
||||||
// Block CONTAINER.
|
// Block CONTAINER.
|
||||||
|
|
||||||
pub fn add(mut self, component: impl PageComponent) -> Self {
|
pub fn add(mut self, component: impl ComponentTrait) -> Self {
|
||||||
self.components.add(component);
|
self.components.add(component);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ pub struct Chunck {
|
||||||
template : String,
|
template : String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PageComponent for Chunck {
|
impl ComponentTrait for Chunck {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
Chunck {
|
Chunck {
|
||||||
renderable: render_always,
|
renderable: render_always,
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ pub struct Container {
|
||||||
template : String,
|
template : String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PageComponent for Container {
|
impl ComponentTrait for Container {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
Container {
|
Container {
|
||||||
renderable : render_always,
|
renderable : render_always,
|
||||||
|
|
@ -109,7 +109,7 @@ impl Container {
|
||||||
|
|
||||||
// Container CONTAINER.
|
// Container CONTAINER.
|
||||||
|
|
||||||
pub fn add(mut self, component: impl PageComponent) -> Self {
|
pub fn add(mut self, component: impl ComponentTrait) -> Self {
|
||||||
self.components.add(component);
|
self.components.add(component);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ pub struct Button {
|
||||||
template : String,
|
template : String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PageComponent for Button {
|
impl ComponentTrait for Button {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
Button {
|
Button {
|
||||||
renderable : render_always,
|
renderable : render_always,
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ pub struct Date {
|
||||||
template : String,
|
template : String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PageComponent for Date {
|
impl ComponentTrait for Date {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
Date {
|
Date {
|
||||||
renderable : render_always,
|
renderable : render_always,
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ pub struct Form {
|
||||||
template : String,
|
template : String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PageComponent for Form {
|
impl ComponentTrait for Form {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
Form {
|
Form {
|
||||||
renderable: render_always,
|
renderable: render_always,
|
||||||
|
|
@ -68,7 +68,7 @@ impl Form {
|
||||||
|
|
||||||
// Form CONTAINER.
|
// Form CONTAINER.
|
||||||
|
|
||||||
pub fn add(mut self, element: impl PageComponent) -> Self {
|
pub fn add(mut self, element: impl ComponentTrait) -> Self {
|
||||||
self.elements.add(element);
|
self.elements.add(element);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ pub struct Hidden {
|
||||||
value : OptAttr,
|
value : OptAttr,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PageComponent for Hidden {
|
impl ComponentTrait for Hidden {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
Hidden {
|
Hidden {
|
||||||
weight: 0,
|
weight: 0,
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ pub struct Input {
|
||||||
template : String,
|
template : String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PageComponent for Input {
|
impl ComponentTrait for Input {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
Input {
|
Input {
|
||||||
renderable : render_always,
|
renderable : render_always,
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ pub struct Column {
|
||||||
template : String,
|
template : String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PageComponent for Column {
|
impl ComponentTrait for Column {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
Column {
|
Column {
|
||||||
renderable: render_always,
|
renderable: render_always,
|
||||||
|
|
@ -54,7 +54,7 @@ impl Column {
|
||||||
|
|
||||||
// Column CONTAINER.
|
// Column CONTAINER.
|
||||||
|
|
||||||
pub fn add(mut self, component: impl PageComponent) -> Self {
|
pub fn add(mut self, component: impl ComponentTrait) -> Self {
|
||||||
self.components.add(component);
|
self.components.add(component);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ pub struct Row {
|
||||||
template : String,
|
template : String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PageComponent for Row {
|
impl ComponentTrait for Row {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
Row {
|
Row {
|
||||||
renderable: render_always,
|
renderable: render_always,
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ pub struct Image {
|
||||||
template : String,
|
template : String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PageComponent for Image {
|
impl ComponentTrait for Image {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
Image {
|
Image {
|
||||||
renderable: render_always,
|
renderable: render_always,
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ pub struct MenuItem {
|
||||||
item_type : MenuItemType,
|
item_type : MenuItemType,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PageComponent for MenuItem {
|
impl ComponentTrait for MenuItem {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
MenuItem {
|
MenuItem {
|
||||||
renderable: render_always,
|
renderable: render_always,
|
||||||
|
|
@ -179,7 +179,7 @@ pub struct Menu {
|
||||||
template : String,
|
template : String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PageComponent for Menu {
|
impl ComponentTrait for Menu {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
Menu {
|
Menu {
|
||||||
renderable: render_always,
|
renderable: render_always,
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ impl ThemeTrait for BulmixTheme {
|
||||||
|
|
||||||
fn before_render_component(
|
fn before_render_component(
|
||||||
&self,
|
&self,
|
||||||
component: &mut dyn PageComponent,
|
component: &mut dyn ComponentTrait,
|
||||||
_assets: &mut PageAssets
|
_assets: &mut PageAssets
|
||||||
) {
|
) {
|
||||||
match component.name() {
|
match component.name() {
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ use std::any::type_name;
|
||||||
|
|
||||||
pub use std::any::Any as AnyComponent;
|
pub use std::any::Any as AnyComponent;
|
||||||
|
|
||||||
pub trait PageComponent: AnyComponent + Send + Sync {
|
pub trait ComponentTrait: AnyComponent + Send + Sync {
|
||||||
|
|
||||||
fn new() -> Self where Self: Sized;
|
fn new() -> Self where Self: Sized;
|
||||||
|
|
||||||
|
|
@ -47,10 +47,10 @@ pub trait PageComponent: AnyComponent + Send + Sync {
|
||||||
fn as_mut_any(&mut self) -> &mut dyn AnyComponent;
|
fn as_mut_any(&mut self) -> &mut dyn AnyComponent;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn component_ref<T: 'static>(component: &dyn PageComponent) -> &T {
|
pub fn component_ref<T: 'static>(component: &dyn ComponentTrait) -> &T {
|
||||||
component.as_ref_any().downcast_ref::<T>().unwrap()
|
component.as_ref_any().downcast_ref::<T>().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn component_mut<T: 'static>(component: &mut dyn PageComponent) -> &mut T {
|
pub fn component_mut<T: 'static>(component: &mut dyn ComponentTrait) -> &mut T {
|
||||||
component.as_mut_any().downcast_mut::<T>().unwrap()
|
component.as_mut_any().downcast_mut::<T>().unwrap()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,23 @@
|
||||||
use crate::html::{Markup, html};
|
use crate::html::{Markup, html};
|
||||||
use crate::response::page::{PageAssets, PageComponent, render_component};
|
use crate::response::page::{PageAssets, ComponentTrait, render_component};
|
||||||
|
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::{Arc, RwLock};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct PageContainer(Vec<Arc<RwLock<dyn PageComponent>>>);
|
pub struct PageContainer(Vec<Arc<RwLock<dyn ComponentTrait>>>);
|
||||||
|
|
||||||
impl PageContainer {
|
impl PageContainer {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
PageContainer(Vec::new())
|
PageContainer(Vec::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_with(component: impl PageComponent) -> Self {
|
pub fn new_with(component: impl ComponentTrait) -> Self {
|
||||||
let mut container = PageContainer::new();
|
let mut container = PageContainer::new();
|
||||||
container.add(component);
|
container.add(component);
|
||||||
container
|
container
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add(&mut self, component: impl PageComponent) {
|
pub fn add(&mut self, component: impl ComponentTrait) {
|
||||||
self.0.push(Arc::new(RwLock::new(component)));
|
self.0.push(Arc::new(RwLock::new(component)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ pub use assets::{
|
||||||
mod component;
|
mod component;
|
||||||
pub use component::{
|
pub use component::{
|
||||||
AnyComponent,
|
AnyComponent,
|
||||||
PageComponent,
|
ComponentTrait,
|
||||||
component_ref,
|
component_ref,
|
||||||
component_mut,
|
component_mut,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,7 @@ impl<'a> Page<'a> {
|
||||||
pub fn add_to(
|
pub fn add_to(
|
||||||
&mut self,
|
&mut self,
|
||||||
region: &'a str,
|
region: &'a str,
|
||||||
component: impl PageComponent
|
component: impl ComponentTrait
|
||||||
) -> &mut Self {
|
) -> &mut Self {
|
||||||
if let Some(regions) = self.regions.get_mut(region) {
|
if let Some(regions) = self.regions.get_mut(region) {
|
||||||
regions.add(component);
|
regions.add(component);
|
||||||
|
|
@ -187,7 +187,7 @@ impl<'a> Page<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render_component(component: &mut dyn PageComponent, assets: &mut PageAssets) -> Markup {
|
pub fn render_component(component: &mut dyn ComponentTrait, assets: &mut PageAssets) -> Markup {
|
||||||
component.before_render(assets);
|
component.before_render(assets);
|
||||||
assets.theme().before_render_component(component, assets);
|
assets.theme().before_render_component(component, assets);
|
||||||
match component.is_renderable() {
|
match component.is_renderable() {
|
||||||
|
|
@ -201,7 +201,7 @@ pub fn render_component(component: &mut dyn PageComponent, assets: &mut PageAsse
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_component_to(region: &'static str, component: impl PageComponent) {
|
pub fn add_component_to(region: &'static str, component: impl ComponentTrait) {
|
||||||
let mut hmap = COMPONENTS.write().unwrap();
|
let mut hmap = COMPONENTS.write().unwrap();
|
||||||
if let Some(regions) = hmap.get_mut(region) {
|
if let Some(regions) = hmap.get_mut(region) {
|
||||||
regions.add(component);
|
regions.add(component);
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::{app, concat_string};
|
use crate::{app, concat_string};
|
||||||
use crate::config::SETTINGS;
|
use crate::config::SETTINGS;
|
||||||
use crate::html::{Markup, html};
|
use crate::html::{Markup, html};
|
||||||
use crate::response::page::{Favicon, Page, PageAssets, PageComponent};
|
use crate::response::page::{ComponentTrait, Favicon, Page, PageAssets};
|
||||||
use crate::base::component::Chunck;
|
use crate::base::component::Chunck;
|
||||||
|
|
||||||
/// Los temas deben implementar este "trait".
|
/// Los temas deben implementar este "trait".
|
||||||
|
|
@ -77,7 +77,7 @@ pub trait ThemeTrait: Send + Sync {
|
||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
fn before_render_component(
|
fn before_render_component(
|
||||||
&self,
|
&self,
|
||||||
component: &mut dyn PageComponent,
|
component: &mut dyn ComponentTrait,
|
||||||
assets: &mut PageAssets
|
assets: &mut PageAssets
|
||||||
) {
|
) {
|
||||||
/*
|
/*
|
||||||
|
|
@ -96,7 +96,7 @@ pub trait ThemeTrait: Send + Sync {
|
||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
fn render_component(
|
fn render_component(
|
||||||
&self,
|
&self,
|
||||||
component: &dyn PageComponent,
|
component: &dyn ComponentTrait,
|
||||||
assets: &mut PageAssets
|
assets: &mut PageAssets
|
||||||
) -> Option<Markup> {
|
) -> Option<Markup> {
|
||||||
None
|
None
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue