🏗️ Use actions to decide component rendering

This commit is contained in:
Manuel Cillero 2024-04-15 02:06:39 +02:00
parent 45cb063e52
commit 7d4cf642ff
27 changed files with 125 additions and 304 deletions

View file

@ -1,3 +1,6 @@
mod is_renderable;
pub use is_renderable::*;
mod before_prepare_component; mod before_prepare_component;
pub use before_prepare_component::*; pub use before_prepare_component::*;

View file

@ -49,10 +49,6 @@ impl<C: ComponentTrait> AfterPrepare<C> {
ActionKey::new(TypeId::of::<Self>(), None, Some(TypeId::of::<C>()), None), ActionKey::new(TypeId::of::<Self>(), None, Some(TypeId::of::<C>()), None),
|action: &Self| (action.f)(component, cx), |action: &Self| (action.f)(component, cx),
); );
}
#[inline(always)]
pub(crate) fn dispatch_by_id(component: &mut C, cx: &mut Context) {
if component.id().is_some() { if component.id().is_some() {
dispatch_actions( dispatch_actions(
ActionKey::new( ActionKey::new(

View file

@ -49,10 +49,6 @@ impl<C: ComponentTrait> BeforePrepare<C> {
ActionKey::new(TypeId::of::<Self>(), None, Some(TypeId::of::<C>()), None), ActionKey::new(TypeId::of::<Self>(), None, Some(TypeId::of::<C>()), None),
|action: &Self| (action.f)(component, cx), |action: &Self| (action.f)(component, cx),
); );
}
#[inline(always)]
pub(crate) fn dispatch_by_id(component: &mut C, cx: &mut Context) {
if component.id().is_some() { if component.id().is_some() {
dispatch_actions( dispatch_actions(
ActionKey::new( ActionKey::new(

View file

@ -0,0 +1,74 @@
use crate::prelude::*;
pub type FnIsRenderable<C> = fn(component: &C, cx: &mut Context) -> bool;
pub struct IsRenderable<C: ComponentTrait> {
f: FnIsRenderable<C>,
referer_type_id: Option<TypeId>,
referer_id: OptionId,
weight: Weight,
}
impl<C: ComponentTrait> ActionTrait for IsRenderable<C> {
fn referer_type_id(&self) -> Option<TypeId> {
self.referer_type_id
}
fn referer_id(&self) -> Option<String> {
self.referer_id.get()
}
fn weight(&self) -> Weight {
self.weight
}
}
impl<C: ComponentTrait> IsRenderable<C> {
pub fn new(f: FnIsRenderable<C>) -> Self {
IsRenderable {
f,
referer_type_id: Some(TypeId::of::<C>()),
referer_id: OptionId::default(),
weight: 0,
}
}
pub fn filter_by_referer_id(mut self, id: impl Into<String>) -> Self {
self.referer_id.alter_value(id);
self
}
pub fn with_weight(mut self, value: Weight) -> Self {
self.weight = value;
self
}
#[inline(always)]
pub(crate) fn dispatch(component: &C, cx: &mut Context) -> bool {
let mut renderable = true;
dispatch_actions(
ActionKey::new(TypeId::of::<Self>(), None, Some(TypeId::of::<C>()), None),
|action: &Self| {
if renderable && !(action.f)(component, cx) {
renderable = false;
}
},
);
if renderable && component.id().is_some() {
dispatch_actions(
ActionKey::new(
TypeId::of::<Self>(),
None,
Some(TypeId::of::<C>()),
component.id(),
),
|action: &Self| {
if renderable && !(action.f)(component, cx) {
renderable = false;
}
},
);
}
renderable
}
}

View file

@ -4,8 +4,7 @@ use crate::prelude::*;
#[derive(AutoDefault, ComponentClasses)] #[derive(AutoDefault, ComponentClasses)]
pub struct Block { pub struct Block {
id : OptionId, id : OptionId,
renderable: Renderable, classes: OptionClasses,
classes : OptionClasses,
style : StyleBase, style : StyleBase,
title : OptionTranslated, title : OptionTranslated,
mixed : MixedComponents, mixed : MixedComponents,
@ -20,10 +19,6 @@ impl ComponentTrait for Block {
self.id.get() self.id.get()
} }
fn is_renderable(&self, cx: &Context) -> bool {
(self.renderable.check)(cx)
}
fn setup_before_prepare(&mut self, _cx: &mut Context) { fn setup_before_prepare(&mut self, _cx: &mut Context) {
self.alter_classes( self.alter_classes(
ClassesOp::Prepend, ClassesOp::Prepend,
@ -60,12 +55,6 @@ impl Block {
self self
} }
#[fn_builder]
pub fn alter_renderable(&mut self, check: FnIsRenderable) -> &mut Self {
self.renderable.check = check;
self
}
#[fn_builder] #[fn_builder]
pub fn alter_style(&mut self, style: StyleBase) -> &mut Self { pub fn alter_style(&mut self, style: StyleBase) -> &mut Self {
self.style = style; self.style = style;

View file

@ -4,13 +4,12 @@ use crate::prelude::*;
#[derive(AutoDefault)] #[derive(AutoDefault)]
pub struct Branding { pub struct Branding {
id : OptionId, id : OptionId,
renderable: Renderable,
#[default(_code = "config::SETTINGS.app.name.to_owned()")] #[default(_code = "config::SETTINGS.app.name.to_owned()")]
app_name : String, app_name : String,
slogan : OptionTranslated, slogan : OptionTranslated,
logo : OptionComponent<Image>, logo : OptionComponent<Image>,
#[default(_code = "|_| \"/\"")] #[default(_code = "|_| \"/\"")]
frontpage : FnContextualPath, frontpage: FnContextualPath,
} }
impl ComponentTrait for Branding { impl ComponentTrait for Branding {
@ -22,10 +21,6 @@ impl ComponentTrait for Branding {
self.id.get() self.id.get()
} }
fn is_renderable(&self, cx: &Context) -> bool {
(self.renderable.check)(cx)
}
fn prepare_component(&self, cx: &mut Context) -> PrepareMarkup { fn prepare_component(&self, cx: &mut Context) -> PrepareMarkup {
let logo = self.logo().render(cx); let logo = self.logo().render(cx);
let home = self.frontpage()(cx); let home = self.frontpage()(cx);
@ -63,12 +58,6 @@ impl Branding {
self self
} }
#[fn_builder]
pub fn alter_renderable(&mut self, check: FnIsRenderable) -> &mut Self {
self.renderable.check = check;
self
}
#[fn_builder] #[fn_builder]
pub fn alter_app_name(&mut self, app_name: impl Into<String>) -> &mut Self { pub fn alter_app_name(&mut self, app_name: impl Into<String>) -> &mut Self {
self.app_name = app_name.into(); self.app_name = app_name.into();

View file

@ -14,12 +14,11 @@ pub enum ButtonTarget {
#[derive(AutoDefault, ComponentClasses)] #[derive(AutoDefault, ComponentClasses)]
pub struct Button { pub struct Button {
id : OptionId, id : OptionId,
renderable : Renderable,
classes : OptionClasses, classes : OptionClasses,
style : StyleBase, style : StyleBase,
font_size : FontSize, font_size : FontSize,
left_icon : OptionComponent<Icon>, left_icon : OptionComponent<Icon>,
right_icon : OptionComponent<Icon>, right_icon: OptionComponent<Icon>,
href : OptionString, href : OptionString,
html : OptionTranslated, html : OptionTranslated,
target : ButtonTarget, target : ButtonTarget,
@ -34,10 +33,6 @@ impl ComponentTrait for Button {
self.id.get() self.id.get()
} }
fn is_renderable(&self, cx: &Context) -> bool {
(self.renderable.check)(cx)
}
fn setup_before_prepare(&mut self, _cx: &mut Context) { fn setup_before_prepare(&mut self, _cx: &mut Context) {
self.alter_classes( self.alter_classes(
ClassesOp::Prepend, ClassesOp::Prepend,
@ -87,12 +82,6 @@ impl Button {
self self
} }
#[fn_builder]
pub fn alter_renderable(&mut self, check: FnIsRenderable) -> &mut Self {
self.renderable.check = check;
self
}
#[fn_builder] #[fn_builder]
pub fn alter_style(&mut self, style: StyleBase) -> &mut Self { pub fn alter_style(&mut self, style: StyleBase) -> &mut Self {
self.style = style; self.style = style;

View file

@ -15,7 +15,6 @@ pub enum ContainerType {
#[derive(AutoDefault, ComponentClasses)] #[derive(AutoDefault, ComponentClasses)]
pub struct Container { pub struct Container {
id : OptionId, id : OptionId,
renderable : Renderable,
classes : OptionClasses, classes : OptionClasses,
container_type: ContainerType, container_type: ContainerType,
direction : flex::Direction, direction : flex::Direction,
@ -35,10 +34,6 @@ impl ComponentTrait for Container {
self.id.get() self.id.get()
} }
fn is_renderable(&self, cx: &Context) -> bool {
(self.renderable.check)(cx)
}
fn setup_before_prepare(&mut self, cx: &mut Context) { fn setup_before_prepare(&mut self, cx: &mut Context) {
self.alter_classes( self.alter_classes(
ClassesOp::Prepend, ClassesOp::Prepend,
@ -144,12 +139,6 @@ impl Container {
self self
} }
#[fn_builder]
pub fn alter_renderable(&mut self, check: FnIsRenderable) -> &mut Self {
self.renderable.check = check;
self
}
#[fn_builder] #[fn_builder]
pub fn alter_direction(&mut self, direction: flex::Direction) -> &mut Self { pub fn alter_direction(&mut self, direction: flex::Direction) -> &mut Self {
self.direction = direction; self.direction = direction;

View file

@ -13,7 +13,6 @@ pub enum ItemType {
#[derive(AutoDefault, ComponentClasses)] #[derive(AutoDefault, ComponentClasses)]
pub struct Item { pub struct Item {
id : OptionId, id : OptionId,
renderable : Renderable,
classes : OptionClasses, classes : OptionClasses,
item_type : ItemType, item_type : ItemType,
flex_grow : flex::Grow, flex_grow : flex::Grow,
@ -33,10 +32,6 @@ impl ComponentTrait for Item {
self.id.get() self.id.get()
} }
fn is_renderable(&self, cx: &Context) -> bool {
(self.renderable.check)(cx)
}
fn setup_before_prepare(&mut self, _cx: &mut Context) { fn setup_before_prepare(&mut self, _cx: &mut Context) {
self.alter_classes( self.alter_classes(
ClassesOp::Prepend, ClassesOp::Prepend,
@ -129,12 +124,6 @@ impl Item {
self self
} }
#[fn_builder]
pub fn alter_renderable(&mut self, check: FnIsRenderable) -> &mut Self {
self.renderable.check = check;
self
}
#[fn_builder] #[fn_builder]
pub fn alter_grow(&mut self, grow: flex::Grow) -> &mut Self { pub fn alter_grow(&mut self, grow: flex::Grow) -> &mut Self {
self.flex_grow = grow; self.flex_grow = grow;

View file

@ -20,7 +20,6 @@ impl ToString for ActionButtonType {
#[rustfmt::skip] #[rustfmt::skip]
#[derive(AutoDefault, ComponentClasses)] #[derive(AutoDefault, ComponentClasses)]
pub struct ActionButton { pub struct ActionButton {
renderable : Renderable,
classes : OptionClasses, classes : OptionClasses,
button_type: ActionButtonType, button_type: ActionButtonType,
style : StyleBase, style : StyleBase,
@ -38,10 +37,6 @@ impl ComponentTrait for ActionButton {
ActionButton::submit() ActionButton::submit()
} }
fn is_renderable(&self, cx: &Context) -> bool {
(self.renderable.check)(cx)
}
fn setup_before_prepare(&mut self, _cx: &mut Context) { fn setup_before_prepare(&mut self, _cx: &mut Context) {
self.alter_classes( self.alter_classes(
ClassesOp::Prepend, ClassesOp::Prepend,
@ -95,12 +90,6 @@ impl ActionButton {
// Button BUILDER. // Button BUILDER.
#[fn_builder]
pub fn alter_renderable(&mut self, check: FnIsRenderable) -> &mut Self {
self.renderable.check = check;
self
}
#[fn_builder] #[fn_builder]
pub fn alter_style(&mut self, style: StyleBase) -> &mut Self { pub fn alter_style(&mut self, style: StyleBase) -> &mut Self {
self.style = style; self.style = style;

View file

@ -3,7 +3,6 @@ use crate::prelude::*;
#[rustfmt::skip] #[rustfmt::skip]
#[derive(AutoDefault, ComponentClasses)] #[derive(AutoDefault, ComponentClasses)]
pub struct Date { pub struct Date {
renderable : Renderable,
classes : OptionClasses, classes : OptionClasses,
name : OptionString, name : OptionString,
value : OptionString, value : OptionString,
@ -22,10 +21,6 @@ impl ComponentTrait for Date {
Date::default().with_classes(ClassesOp::Add, "form-item form-type-date") Date::default().with_classes(ClassesOp::Add, "form-item form-type-date")
} }
fn is_renderable(&self, cx: &Context) -> bool {
(self.renderable.check)(cx)
}
fn prepare_component(&self, _cx: &mut Context) -> PrepareMarkup { fn prepare_component(&self, _cx: &mut Context) -> PrepareMarkup {
let id = self.name().get().map(|name| concat_string!("edit-", name)); let id = self.name().get().map(|name| concat_string!("edit-", name));
PrepareMarkup::With(html! { PrepareMarkup::With(html! {
@ -63,12 +58,6 @@ impl ComponentTrait for Date {
impl Date { impl Date {
// Date BUILDER. // Date BUILDER.
#[fn_builder]
pub fn alter_renderable(&mut self, check: FnIsRenderable) -> &mut Self {
self.renderable.check = check;
self
}
#[fn_builder] #[fn_builder]
pub fn alter_name(&mut self, name: &str) -> &mut Self { pub fn alter_name(&mut self, name: &str) -> &mut Self {
self.name.alter_value(name); self.name.alter_value(name);

View file

@ -11,10 +11,9 @@ pub enum FormMethod {
#[derive(AutoDefault, ComponentClasses)] #[derive(AutoDefault, ComponentClasses)]
pub struct Form { pub struct Form {
id : OptionId, id : OptionId,
renderable: Renderable, classes: OptionClasses,
classes : OptionClasses,
action : OptionString, action : OptionString,
charset : OptionString, charset: OptionString,
method : FormMethod, method : FormMethod,
mixed : MixedComponents, mixed : MixedComponents,
} }
@ -30,10 +29,6 @@ impl ComponentTrait for Form {
self.id.get() self.id.get()
} }
fn is_renderable(&self, cx: &Context) -> bool {
(self.renderable.check)(cx)
}
fn prepare_component(&self, cx: &mut Context) -> PrepareMarkup { fn prepare_component(&self, cx: &mut Context) -> PrepareMarkup {
let method = match self.method() { let method = match self.method() {
FormMethod::Post => Some("post".to_owned()), FormMethod::Post => Some("post".to_owned()),
@ -62,12 +57,6 @@ impl Form {
self self
} }
#[fn_builder]
pub fn alter_renderable(&mut self, check: FnIsRenderable) -> &mut Self {
self.renderable.check = check;
self
}
#[fn_builder] #[fn_builder]
pub fn alter_action(&mut self, action: &str) -> &mut Self { pub fn alter_action(&mut self, action: &str) -> &mut Self {
self.action.alter_value(action); self.action.alter_value(action);

View file

@ -14,7 +14,6 @@ pub enum InputType {
#[rustfmt::skip] #[rustfmt::skip]
#[derive(AutoDefault, ComponentClasses)] #[derive(AutoDefault, ComponentClasses)]
pub struct Input { pub struct Input {
renderable : Renderable,
classes : OptionClasses, classes : OptionClasses,
input_type : InputType, input_type : InputType,
name : OptionName, name : OptionName,
@ -40,10 +39,6 @@ impl ComponentTrait for Input {
.with_maxlength(Some(128)) .with_maxlength(Some(128))
} }
fn is_renderable(&self, cx: &Context) -> bool {
(self.renderable.check)(cx)
}
#[rustfmt::skip] #[rustfmt::skip]
fn prepare_component(&self, cx: &mut Context) -> PrepareMarkup { fn prepare_component(&self, cx: &mut Context) -> PrepareMarkup {
let type_input = match self.input_type() { let type_input = match self.input_type() {
@ -142,12 +137,6 @@ impl Input {
// Input BUILDER. // Input BUILDER.
#[fn_builder]
pub fn alter_renderable(&mut self, check: FnIsRenderable) -> &mut Self {
self.renderable.check = check;
self
}
#[fn_builder] #[fn_builder]
pub fn alter_name(&mut self, name: &str) -> &mut Self { pub fn alter_name(&mut self, name: &str) -> &mut Self {
if let Some(previous) = self.name.get() { if let Some(previous) = self.name.get() {

View file

@ -42,7 +42,6 @@ impl ToString for HeadingSize {
#[derive(AutoDefault, ComponentClasses)] #[derive(AutoDefault, ComponentClasses)]
pub struct Heading { pub struct Heading {
id : OptionId, id : OptionId,
renderable : Renderable,
classes : OptionClasses, classes : OptionClasses,
heading_type: HeadingType, heading_type: HeadingType,
size : HeadingSize, size : HeadingSize,
@ -58,10 +57,6 @@ impl ComponentTrait for Heading {
self.id.get() self.id.get()
} }
fn is_renderable(&self, cx: &Context) -> bool {
(self.renderable.check)(cx)
}
fn setup_before_prepare(&mut self, _cx: &mut Context) { fn setup_before_prepare(&mut self, _cx: &mut Context) {
self.alter_classes(ClassesOp::Add, self.size().to_string()); self.alter_classes(ClassesOp::Add, self.size().to_string());
} }
@ -126,12 +121,6 @@ impl Heading {
self self
} }
#[fn_builder]
pub fn alter_renderable(&mut self, check: FnIsRenderable) -> &mut Self {
self.renderable.check = check;
self
}
#[fn_builder] #[fn_builder]
pub fn alter_heading_type(&mut self, heading_type: HeadingType) -> &mut Self { pub fn alter_heading_type(&mut self, heading_type: HeadingType) -> &mut Self {
self.heading_type = heading_type; self.heading_type = heading_type;

View file

@ -3,10 +3,9 @@ use crate::prelude::*;
#[rustfmt::skip] #[rustfmt::skip]
#[derive(AutoDefault, ComponentClasses)] #[derive(AutoDefault, ComponentClasses)]
pub struct Icon { pub struct Icon {
renderable: Renderable,
classes : OptionClasses, classes : OptionClasses,
icon_name : OptionString, icon_name: OptionString,
font_size : FontSize, font_size: FontSize,
} }
impl ComponentTrait for Icon { impl ComponentTrait for Icon {
@ -14,10 +13,6 @@ impl ComponentTrait for Icon {
Icon::default() Icon::default()
} }
fn is_renderable(&self, cx: &Context) -> bool {
(self.renderable.check)(cx)
}
#[rustfmt::skip] #[rustfmt::skip]
fn setup_before_prepare(&mut self, cx: &mut Context) { fn setup_before_prepare(&mut self, cx: &mut Context) {
if let Some(icon_name) = self.icon_name().get() { if let Some(icon_name) = self.icon_name().get() {
@ -43,12 +38,6 @@ impl Icon {
// Icon BUILDER. // Icon BUILDER.
#[fn_builder]
pub fn alter_renderable(&mut self, check: FnIsRenderable) -> &mut Self {
self.renderable.check = check;
self
}
#[fn_builder] #[fn_builder]
pub fn alter_icon_name(&mut self, name: impl Into<String>) -> &mut Self { pub fn alter_icon_name(&mut self, name: impl Into<String>) -> &mut Self {
self.icon_name.alter_value(name); self.icon_name.alter_value(name);

View file

@ -17,8 +17,7 @@ pub enum ImageSize {
#[derive(AutoDefault, ComponentClasses)] #[derive(AutoDefault, ComponentClasses)]
pub struct Image { pub struct Image {
id : OptionId, id : OptionId,
renderable: Renderable, classes: OptionClasses,
classes : OptionClasses,
source : OptionString, source : OptionString,
size : ImageSize, size : ImageSize,
} }
@ -32,10 +31,6 @@ impl ComponentTrait for Image {
self.id.get() self.id.get()
} }
fn is_renderable(&self, cx: &Context) -> bool {
(self.renderable.check)(cx)
}
fn prepare_component(&self, _cx: &mut Context) -> PrepareMarkup { fn prepare_component(&self, _cx: &mut Context) -> PrepareMarkup {
let (width, height) = match self.size() { let (width, height) = match self.size() {
ImageSize::Auto => (None, None), ImageSize::Auto => (None, None),
@ -83,12 +78,6 @@ impl Image {
self self
} }
#[fn_builder]
pub fn alter_renderable(&mut self, check: FnIsRenderable) -> &mut Self {
self.renderable.check = check;
self
}
#[fn_builder] #[fn_builder]
pub fn alter_source(&mut self, source: &str) -> &mut Self { pub fn alter_source(&mut self, source: &str) -> &mut Self {
self.source.alter_value(source); self.source.alter_value(source);

View file

@ -18,7 +18,6 @@ pub enum ElementType {
#[rustfmt::skip] #[rustfmt::skip]
#[derive(AutoDefault)] #[derive(AutoDefault)]
pub struct Element { pub struct Element {
renderable : Renderable,
element_type: ElementType, element_type: ElementType,
} }
@ -27,10 +26,6 @@ impl ComponentTrait for Element {
Element::default() Element::default()
} }
fn is_renderable(&self, cx: &Context) -> bool {
(self.renderable.check)(cx)
}
fn prepare_component(&self, cx: &mut Context) -> PrepareMarkup { fn prepare_component(&self, cx: &mut Context) -> PrepareMarkup {
match self.element_type() { match self.element_type() {
ElementType::Void => PrepareMarkup::None, ElementType::Void => PrepareMarkup::None,
@ -48,25 +43,15 @@ impl Element {
pub fn html(content: Html) -> Self { pub fn html(content: Html) -> Self {
Element { Element {
element_type: ElementType::Html(Content::with(content)), element_type: ElementType::Html(Content::with(content)),
..Default::default()
} }
} }
pub fn submenu(submenu: Submenu) -> Self { pub fn submenu(submenu: Submenu) -> Self {
Element { Element {
element_type: ElementType::Submenu(SubmenuItems::with(submenu)), element_type: ElementType::Submenu(SubmenuItems::with(submenu)),
..Default::default()
} }
} }
// Element BUILDER.
#[fn_builder]
pub fn alter_renderable(&mut self, check: FnIsRenderable) -> &mut Self {
self.renderable.check = check;
self
}
// Element GETTERS. // Element GETTERS.
pub fn element_type(&self) -> &ElementType { pub fn element_type(&self) -> &ElementType {

View file

@ -6,8 +6,7 @@ use super::Element;
#[derive(AutoDefault)] #[derive(AutoDefault)]
pub struct Group { pub struct Group {
id : OptionId, id : OptionId,
renderable: Renderable, elements: MixedComponents,
elements : MixedComponents,
} }
impl ComponentTrait for Group { impl ComponentTrait for Group {
@ -19,10 +18,6 @@ impl ComponentTrait for Group {
self.id.get() self.id.get()
} }
fn is_renderable(&self, cx: &Context) -> bool {
(self.renderable.check)(cx)
}
fn prepare_component(&self, cx: &mut Context) -> PrepareMarkup { fn prepare_component(&self, cx: &mut Context) -> PrepareMarkup {
PrepareMarkup::With(html! { PrepareMarkup::With(html! {
div id=[self.id()] class="menu-group" { div id=[self.id()] class="menu-group" {
@ -41,12 +36,6 @@ impl Group {
self self
} }
#[fn_builder]
pub fn alter_renderable(&mut self, check: FnIsRenderable) -> &mut Self {
self.renderable.check = check;
self
}
#[fn_builder] #[fn_builder]
pub fn alter_elements(&mut self, op: TypedOp<Element>) -> &mut Self { pub fn alter_elements(&mut self, op: TypedOp<Element>) -> &mut Self {
self.elements.alter_typed(op); self.elements.alter_typed(op);

View file

@ -24,7 +24,6 @@ pub enum ItemType {
#[rustfmt::skip] #[rustfmt::skip]
#[derive(AutoDefault)] #[derive(AutoDefault)]
pub struct Item { pub struct Item {
renderable : Renderable,
item_type : ItemType, item_type : ItemType,
description: OptionTranslated, description: OptionTranslated,
left_icon : OptionComponent<Icon>, left_icon : OptionComponent<Icon>,
@ -36,10 +35,6 @@ impl ComponentTrait for Item {
Item::default() Item::default()
} }
fn is_renderable(&self, cx: &Context) -> bool {
(self.renderable.check)(cx)
}
fn prepare_component(&self, cx: &mut Context) -> PrepareMarkup { fn prepare_component(&self, cx: &mut Context) -> PrepareMarkup {
let description = self.description.using(cx.langid()); let description = self.description.using(cx.langid());
@ -151,12 +146,6 @@ impl Item {
// Item BUILDER. // Item BUILDER.
#[fn_builder]
pub fn alter_renderable(&mut self, check: FnIsRenderable) -> &mut Self {
self.renderable.check = check;
self
}
#[fn_builder] #[fn_builder]
pub fn alter_description(&mut self, text: L10n) -> &mut Self { pub fn alter_description(&mut self, text: L10n) -> &mut Self {
self.description.alter_value(text); self.description.alter_value(text);

View file

@ -6,8 +6,7 @@ use super::Group;
#[derive(AutoDefault)] #[derive(AutoDefault)]
pub struct Megamenu { pub struct Megamenu {
id : OptionId, id : OptionId,
renderable: Renderable, groups: MixedComponents,
groups : MixedComponents,
} }
impl ComponentTrait for Megamenu { impl ComponentTrait for Megamenu {
@ -19,10 +18,6 @@ impl ComponentTrait for Megamenu {
self.id.get() self.id.get()
} }
fn is_renderable(&self, cx: &Context) -> bool {
(self.renderable.check)(cx)
}
fn prepare_component(&self, cx: &mut Context) -> PrepareMarkup { fn prepare_component(&self, cx: &mut Context) -> PrepareMarkup {
PrepareMarkup::With(html! { PrepareMarkup::With(html! {
div id=[self.id()] class="menu__groups" { div id=[self.id()] class="menu__groups" {
@ -41,12 +36,6 @@ impl Megamenu {
self self
} }
#[fn_builder]
pub fn alter_renderable(&mut self, check: FnIsRenderable) -> &mut Self {
self.renderable.check = check;
self
}
#[fn_builder] #[fn_builder]
pub fn alter_groups(&mut self, op: TypedOp<Group>) -> &mut Self { pub fn alter_groups(&mut self, op: TypedOp<Group>) -> &mut Self {
self.groups.alter_typed(op); self.groups.alter_typed(op);

View file

@ -6,8 +6,7 @@ use super::Item;
#[derive(AutoDefault)] #[derive(AutoDefault)]
pub struct Menu { pub struct Menu {
id : OptionId, id : OptionId,
renderable: Renderable, items: MixedComponents,
items : MixedComponents,
} }
impl ComponentTrait for Menu { impl ComponentTrait for Menu {
@ -19,10 +18,6 @@ impl ComponentTrait for Menu {
self.id.get() self.id.get()
} }
fn is_renderable(&self, cx: &Context) -> bool {
(self.renderable.check)(cx)
}
fn prepare_component(&self, cx: &mut Context) -> PrepareMarkup { fn prepare_component(&self, cx: &mut Context) -> PrepareMarkup {
cx.set_param::<bool>(PARAM_BASE_INCLUDE_MENU_ASSETS, true); cx.set_param::<bool>(PARAM_BASE_INCLUDE_MENU_ASSETS, true);
cx.set_param::<bool>(PARAM_BASE_INCLUDE_ICONS, true); cx.set_param::<bool>(PARAM_BASE_INCLUDE_ICONS, true);
@ -69,12 +64,6 @@ impl Menu {
self self
} }
#[fn_builder]
pub fn alter_renderable(&mut self, check: FnIsRenderable) -> &mut Self {
self.renderable.check = check;
self
}
#[fn_builder] #[fn_builder]
pub fn alter_items(&mut self, op: TypedOp<Item>) -> &mut Self { pub fn alter_items(&mut self, op: TypedOp<Item>) -> &mut Self {
self.items.alter_typed(op); self.items.alter_typed(op);

View file

@ -6,9 +6,8 @@ use super::Item;
#[derive(AutoDefault)] #[derive(AutoDefault)]
pub struct Submenu { pub struct Submenu {
id : OptionId, id : OptionId,
renderable: Renderable, title: OptionTranslated,
title : OptionTranslated, items: MixedComponents,
items : MixedComponents,
} }
impl ComponentTrait for Submenu { impl ComponentTrait for Submenu {
@ -20,10 +19,6 @@ impl ComponentTrait for Submenu {
self.id.get() self.id.get()
} }
fn is_renderable(&self, cx: &Context) -> bool {
(self.renderable.check)(cx)
}
fn prepare_component(&self, cx: &mut Context) -> PrepareMarkup { fn prepare_component(&self, cx: &mut Context) -> PrepareMarkup {
PrepareMarkup::With(html! { PrepareMarkup::With(html! {
div id=[self.id()] class="menu__items" { div id=[self.id()] class="menu__items" {
@ -47,12 +42,6 @@ impl Submenu {
self self
} }
#[fn_builder]
pub fn alter_renderable(&mut self, check: FnIsRenderable) -> &mut Self {
self.renderable.check = check;
self
}
#[fn_builder] #[fn_builder]
pub fn alter_title(&mut self, title: L10n) -> &mut Self { pub fn alter_title(&mut self, title: L10n) -> &mut Self {
self.title.alter_value(title); self.title.alter_value(title);

View file

@ -4,9 +4,8 @@ use crate::prelude::*;
#[derive(AutoDefault, ComponentClasses)] #[derive(AutoDefault, ComponentClasses)]
pub struct Paragraph { pub struct Paragraph {
id : OptionId, id : OptionId,
renderable: Renderable,
classes : OptionClasses, classes : OptionClasses,
font_size : FontSize, font_size: FontSize,
mixed : MixedComponents, mixed : MixedComponents,
} }
@ -19,10 +18,6 @@ impl ComponentTrait for Paragraph {
self.id.get() self.id.get()
} }
fn is_renderable(&self, cx: &Context) -> bool {
(self.renderable.check)(cx)
}
fn setup_before_prepare(&mut self, _cx: &mut Context) { fn setup_before_prepare(&mut self, _cx: &mut Context) {
self.alter_classes(ClassesOp::Prepend, self.font_size().to_string()); self.alter_classes(ClassesOp::Prepend, self.font_size().to_string());
} }
@ -56,12 +51,6 @@ impl Paragraph {
self self
} }
#[fn_builder]
pub fn alter_renderable(&mut self, check: FnIsRenderable) -> &mut Self {
self.renderable.check = check;
self
}
#[fn_builder] #[fn_builder]
pub fn alter_font_size(&mut self, font_size: FontSize) -> &mut Self { pub fn alter_font_size(&mut self, font_size: FontSize) -> &mut Self {
self.font_size = font_size; self.font_size = font_size;

View file

@ -13,8 +13,7 @@ pub enum PoweredByLogo {
#[rustfmt::skip] #[rustfmt::skip]
#[derive(AutoDefault)] #[derive(AutoDefault)]
pub struct PoweredBy { pub struct PoweredBy {
renderable: Renderable, copyright: Option<String>,
copyright : Option<String>,
logo : PoweredByLogo, logo : PoweredByLogo,
} }
@ -28,10 +27,6 @@ impl ComponentTrait for PoweredBy {
} }
} }
fn is_renderable(&self, cx: &Context) -> bool {
(self.renderable.check)(cx)
}
fn prepare_component(&self, cx: &mut Context) -> PrepareMarkup { fn prepare_component(&self, cx: &mut Context) -> PrepareMarkup {
let poweredby_pagetop = L10n::l("poweredby_pagetop") let poweredby_pagetop = L10n::l("poweredby_pagetop")
.with_arg( .with_arg(
@ -62,12 +57,6 @@ impl ComponentTrait for PoweredBy {
impl PoweredBy { impl PoweredBy {
// PoweredBy BUILDER. // PoweredBy BUILDER.
#[fn_builder]
pub fn alter_renderable(&mut self, check: FnIsRenderable) -> &mut Self {
self.renderable.check = check;
self
}
#[fn_builder] #[fn_builder]
pub fn alter_copyright(&mut self, copyright: Option<impl Into<String>>) -> &mut Self { pub fn alter_copyright(&mut self, copyright: Option<impl Into<String>>) -> &mut Self {
self.copyright = copyright.map(|c| c.into()); self.copyright = copyright.map(|c| c.into());

View file

@ -2,9 +2,6 @@ mod context;
pub use context::{AssetsOp, Context}; pub use context::{AssetsOp, Context};
pub type FnContextualPath = fn(cx: &Context) -> &str; pub type FnContextualPath = fn(cx: &Context) -> &str;
mod renderable;
pub use renderable::{FnIsRenderable, Renderable};
mod definition; mod definition;
pub use definition::{ComponentBase, ComponentTrait}; pub use definition::{ComponentBase, ComponentTrait};

View file

@ -25,11 +25,6 @@ pub trait ComponentTrait: AnyBase + ComponentBase + Send + Sync {
None None
} }
#[allow(unused_variables)]
fn is_renderable(&self, cx: &Context) -> bool {
true
}
#[allow(unused_variables)] #[allow(unused_variables)]
fn setup_before_prepare(&mut self, cx: &mut Context) {} fn setup_before_prepare(&mut self, cx: &mut Context) {}
@ -41,7 +36,7 @@ pub trait ComponentTrait: AnyBase + ComponentBase + Send + Sync {
impl<C: ComponentTrait> ComponentBase for C { impl<C: ComponentTrait> ComponentBase for C {
fn render(&mut self, cx: &mut Context) -> Markup { fn render(&mut self, cx: &mut Context) -> Markup {
if self.is_renderable(cx) { if action::component::IsRenderable::dispatch(self, cx) {
// Comprueba el componente antes de prepararlo. // Comprueba el componente antes de prepararlo.
self.setup_before_prepare(cx); self.setup_before_prepare(cx);
@ -50,7 +45,6 @@ impl<C: ComponentTrait> ComponentBase for C {
// Acciones de los módulos antes de preparar el componente. // Acciones de los módulos antes de preparar el componente.
action::component::BeforePrepare::dispatch(self, cx); action::component::BeforePrepare::dispatch(self, cx);
action::component::BeforePrepare::dispatch_by_id(self, cx);
// Renderiza el componente. // Renderiza el componente.
let markup = match action::theme::RenderComponent::dispatch(self, cx) { let markup = match action::theme::RenderComponent::dispatch(self, cx) {
@ -67,7 +61,6 @@ impl<C: ComponentTrait> ComponentBase for C {
// Acciones de los módulos después de preparar el componente. // Acciones de los módulos después de preparar el componente.
action::component::AfterPrepare::dispatch(self, cx); action::component::AfterPrepare::dispatch(self, cx);
action::component::AfterPrepare::dispatch_by_id(self, cx);
markup markup
} else { } else {

View file

@ -1,14 +0,0 @@
use crate::core::component::Context;
use crate::AutoDefault;
pub type FnIsRenderable = fn(cx: &Context) -> bool;
#[derive(AutoDefault)]
pub struct Renderable {
#[default(_code = "render_always")]
pub check: FnIsRenderable,
}
fn render_always(_cx: &Context) -> bool {
true
}