♻️ Rename types for Mixed and Typed components

This commit is contained in:
Manuel Cillero 2024-03-07 21:27:36 +01:00
parent 57e71a9399
commit c65ac74a6f
20 changed files with 151 additions and 154 deletions

View file

@ -8,7 +8,7 @@ pub struct Block {
renderable: Renderable,
classes : OptionClasses,
title : OptionTranslated,
stuff : MixedComponents,
mixed : MixedComponents,
}
impl ComponentTrait for Block {
@ -78,13 +78,13 @@ impl Block {
#[rustfmt::skip]
pub fn add_component(mut self, component: impl ComponentTrait) -> Self {
self.stuff.alter_value(OneOp::Add(OneComponent::with(component)));
self.mixed.alter_value(MixedOp::Add(AnyComponent::with(component)));
self
}
#[fn_builder]
pub fn alter_components(&mut self, op: OneOp) -> &mut Self {
self.stuff.alter_value(op);
pub fn alter_components(&mut self, op: MixedOp) -> &mut Self {
self.mixed.alter_value(op);
self
}
@ -95,6 +95,6 @@ impl Block {
}
pub fn components(&self) -> &MixedComponents {
&self.stuff
&self.mixed
}
}

View file

@ -7,7 +7,7 @@ pub struct Container {
weight : Weight,
renderable : Renderable,
classes : OptionClasses,
items : VectorComponents<flex::Item>,
items : TypedComponents<flex::Item>,
direction : flex::Direction,
wrap_align : flex::WrapAlign,
content_justify: flex::ContentJustify,
@ -84,7 +84,7 @@ impl Container {
#[rustfmt::skip]
pub fn add_item(mut self, item: flex::Item) -> Self {
self.items.alter_value(TypedOp::Add(TypedComponent::with(item)));
self.items.alter_value(TypedOp::Add(OneComponent::with(item)));
self
}
@ -126,7 +126,7 @@ impl Container {
// Container GETTERS.
pub fn items(&self) -> &VectorComponents<flex::Item> {
pub fn items(&self) -> &TypedComponents<flex::Item> {
&self.items
}

View file

@ -12,7 +12,7 @@ pub struct Item {
item_size : flex::ItemSize,
item_offset : flex::ItemOffset,
item_align : flex::ItemAlign,
stuff : MixedComponents,
mixed : MixedComponents,
}
impl ComponentTrait for Item {
@ -63,6 +63,10 @@ impl ComponentTrait for Item {
}
impl Item {
pub fn with(component: impl ComponentTrait) -> Self {
Item::default().add_component(component)
}
// Item BUILDER.
#[fn_builder]
@ -115,13 +119,13 @@ impl Item {
#[rustfmt::skip]
pub fn add_component(mut self, component: impl ComponentTrait) -> Self {
self.stuff.alter_value(OneOp::Add(OneComponent::with(component)));
self.mixed.alter_value(MixedOp::Add(AnyComponent::with(component)));
self
}
#[fn_builder]
pub fn alter_components(&mut self, op: OneOp) -> &mut Self {
self.stuff.alter_value(op);
pub fn alter_components(&mut self, op: MixedOp) -> &mut Self {
self.mixed.alter_value(op);
self
}
@ -148,6 +152,6 @@ impl Item {
}
pub fn components(&self) -> &MixedComponents {
&self.stuff
&self.mixed
}
}

View file

@ -17,7 +17,7 @@ pub struct Form {
action : OptionString,
charset : OptionString,
method : FormMethod,
stuff : MixedComponents,
mixed : MixedComponents,
}
impl ComponentTrait for Form {
@ -99,13 +99,13 @@ impl Form {
#[rustfmt::skip]
pub fn add_element(mut self, element: impl ComponentTrait) -> Self {
self.stuff.alter_value(OneOp::Add(OneComponent::with(element)));
self.mixed.alter_value(MixedOp::Add(AnyComponent::with(element)));
self
}
#[fn_builder]
pub fn alter_elements(&mut self, op: OneOp) -> &mut Self {
self.stuff.alter_value(op);
pub fn alter_elements(&mut self, op: MixedOp) -> &mut Self {
self.mixed.alter_value(op);
self
}
@ -124,6 +124,6 @@ impl Form {
}
pub fn elements(&self) -> &MixedComponents {
&self.stuff
&self.mixed
}
}

View file

@ -2,8 +2,8 @@ use crate::prelude::*;
use super::Submenu;
type Content = TypedComponent<Html>;
type SubmenuItems = TypedComponent<Submenu>;
type Content = OneComponent<Html>;
type SubmenuItems = OneComponent<Submenu>;
#[derive(AutoDefault)]
pub enum ElementType {

View file

@ -8,7 +8,7 @@ pub struct Group {
id : OptionId,
weight : Weight,
renderable: Renderable,
elements : VectorComponents<Element>,
elements : TypedComponents<Element>,
}
impl ComponentTrait for Group {
@ -60,7 +60,7 @@ impl Group {
#[rustfmt::skip]
pub fn add_element(mut self, element: Element) -> Self {
self.elements.alter_value(TypedOp::Add(TypedComponent::with(element)));
self.elements.alter_value(TypedOp::Add(OneComponent::with(element)));
self
}
@ -72,7 +72,7 @@ impl Group {
// Group GETTERS.
pub fn elements(&self) -> &VectorComponents<Element> {
pub fn elements(&self) -> &TypedComponents<Element> {
&self.elements
}
}

View file

@ -3,9 +3,9 @@ use crate::prelude::*;
use super::{Megamenu, Submenu};
type Label = L10n;
type Content = TypedComponent<Html>;
type SubmenuItems = TypedComponent<Submenu>;
type MegamenuGroups = TypedComponent<Megamenu>;
type Content = OneComponent<Html>;
type SubmenuItems = OneComponent<Submenu>;
type MegamenuGroups = OneComponent<Megamenu>;
#[derive(AutoDefault)]
pub enum ItemType {

View file

@ -8,7 +8,7 @@ pub struct Megamenu {
id : OptionId,
weight : Weight,
renderable: Renderable,
groups : VectorComponents<Group>,
groups : TypedComponents<Group>,
}
impl ComponentTrait for Megamenu {
@ -60,7 +60,7 @@ impl Megamenu {
#[rustfmt::skip]
pub fn add_group(mut self, group: Group) -> Self {
self.groups.alter_value(TypedOp::Add(TypedComponent::with(group)));
self.groups.alter_value(TypedOp::Add(OneComponent::with(group)));
self
}
@ -72,7 +72,7 @@ impl Megamenu {
// Megamenu GETTERS.
pub fn groups(&self) -> &VectorComponents<Group> {
pub fn groups(&self) -> &TypedComponents<Group> {
&self.groups
}
}

View file

@ -8,7 +8,7 @@ pub struct Menu {
id : OptionId,
weight : Weight,
renderable: Renderable,
items : VectorComponents<Item>,
items : TypedComponents<Item>,
}
impl ComponentTrait for Menu {
@ -88,7 +88,7 @@ impl Menu {
#[rustfmt::skip]
pub fn add_item(mut self, item: Item) -> Self {
self.items.alter_value(TypedOp::Add(TypedComponent::with(item)));
self.items.alter_value(TypedOp::Add(OneComponent::with(item)));
self
}
@ -100,7 +100,7 @@ impl Menu {
// Menu GETTERS.
pub fn items(&self) -> &VectorComponents<Item> {
pub fn items(&self) -> &TypedComponents<Item> {
&self.items
}
}

View file

@ -9,7 +9,7 @@ pub struct Submenu {
weight : Weight,
renderable: Renderable,
title : OptionTranslated,
items : VectorComponents<Item>,
items : TypedComponents<Item>,
}
impl ComponentTrait for Submenu {
@ -72,7 +72,7 @@ impl Submenu {
#[rustfmt::skip]
pub fn add_item(mut self, item: Item) -> Self {
self.items.alter_value(TypedOp::Add(TypedComponent::with(item)));
self.items.alter_value(TypedOp::Add(OneComponent::with(item)));
self
}
@ -88,7 +88,7 @@ impl Submenu {
&self.title
}
pub fn items(&self) -> &VectorComponents<Item> {
pub fn items(&self) -> &TypedComponents<Item> {
&self.items
}
}

View file

@ -8,7 +8,7 @@ pub struct Paragraph {
renderable: Renderable,
classes : OptionClasses,
font_size : FontSize,
stuff : MixedComponents,
mixed : MixedComponents,
}
impl ComponentTrait for Paragraph {
@ -49,8 +49,8 @@ impl Paragraph {
Paragraph::default().add_component(component)
}
pub fn translated(l10n: L10n) -> Self {
Paragraph::default().add_translated(l10n)
pub fn fluent(l10n: L10n) -> Self {
Paragraph::default().add_component(Fluent::with(l10n))
}
// Paragraph BUILDER.
@ -81,19 +81,13 @@ impl Paragraph {
#[rustfmt::skip]
pub fn add_component(mut self, component: impl ComponentTrait) -> Self {
self.stuff.alter_value(OneOp::Add(OneComponent::with(component)));
self
}
#[rustfmt::skip]
pub fn add_translated(mut self, l10n: L10n) -> Self {
self.stuff.alter_value(OneOp::Add(OneComponent::with(Translate::with(l10n))));
self.mixed.alter_value(MixedOp::Add(AnyComponent::with(component)));
self
}
#[fn_builder]
pub fn alter_components(&mut self, op: OneOp) -> &mut Self {
self.stuff.alter_value(op);
pub fn alter_components(&mut self, op: MixedOp) -> &mut Self {
self.mixed.alter_value(op);
self
}
@ -104,6 +98,6 @@ impl Paragraph {
}
pub fn components(&self) -> &MixedComponents {
&self.stuff
&self.mixed
}
}

View file

@ -13,12 +13,12 @@ pub enum WrapperType {
#[rustfmt::skip]
#[derive(AutoDefault, ComponentClasses)]
pub struct Wrapper {
id : OptionId,
weight : Weight,
renderable : Renderable,
classes : OptionClasses,
wrapper_type : WrapperType,
stuff : MixedComponents,
id : OptionId,
weight : Weight,
renderable : Renderable,
classes : OptionClasses,
wrapper_type: WrapperType,
mixed : MixedComponents,
}
impl ComponentTrait for Wrapper {
@ -126,13 +126,13 @@ impl Wrapper {
#[rustfmt::skip]
pub fn add_component(mut self, component: impl ComponentTrait) -> Self {
self.stuff.alter_value(OneOp::Add(OneComponent::with(component)));
self.mixed.alter_value(MixedOp::Add(AnyComponent::with(component)));
self
}
#[fn_builder]
pub fn alter_components(&mut self, op: OneOp) -> &mut Self {
self.stuff.alter_value(op);
pub fn alter_components(&mut self, op: MixedOp) -> &mut Self {
self.mixed.alter_value(op);
self
}
@ -143,6 +143,6 @@ impl Wrapper {
}
pub fn components(&self) -> &MixedComponents {
&self.stuff
&self.mixed
}
}

View file

@ -61,7 +61,7 @@ fn hello_world() -> Wrapper {
Heading::h1(L10n::l("welcome_title")).with_size(HeadingSize::Medium),
)
.add_component(
Paragraph::translated(L10n::l("welcome_intro").with_arg(
Paragraph::fluent(L10n::l("welcome_intro").with_arg(
"app",
format!(
"<span class=\"app-name\">{}</span>",
@ -70,7 +70,7 @@ fn hello_world() -> Wrapper {
))
.with_font_size(FontSize::Medium),
)
.add_component(Paragraph::translated(L10n::l("welcome_powered").with_arg(
.add_component(Paragraph::fluent(L10n::l("welcome_powered").with_arg(
"pagetop",
format!(
"<a href=\"{}\" target=\"_blank\">{}</a>",
@ -119,10 +119,8 @@ fn welcome() -> Wrapper {
))
.with_size(HeadingSize::Subtitle),
)
.add_component(
Paragraph::translated(L10n::l("welcome_text1")).with_font_size(FontSize::Medium),
)
.add_component(Paragraph::translated(L10n::l("welcome_text2")))
.add_component(Paragraph::fluent(L10n::l("welcome_text1")).with_font_size(FontSize::Medium))
.add_component(Paragraph::fluent(L10n::l("welcome_text2")))
}
fn about_pagetop() -> Wrapper {
@ -142,11 +140,11 @@ fn about_pagetop() -> Wrapper {
.with_classes(ClassesOp::Add, "pagetop-col-text")
.add_component(Heading::h2(L10n::l("welcome_pagetop_title")))
.add_component(
Paragraph::translated(L10n::l("welcome_pagetop_text1"))
Paragraph::fluent(L10n::l("welcome_pagetop_text1"))
.with_font_size(FontSize::Medium),
)
.add_component(Paragraph::translated(L10n::l("welcome_pagetop_text2")))
.add_component(Paragraph::translated(L10n::l("welcome_pagetop_text3"))),
.add_component(Paragraph::fluent(L10n::l("welcome_pagetop_text2")))
.add_component(Paragraph::fluent(L10n::l("welcome_pagetop_text3"))),
),
)
}
@ -163,7 +161,7 @@ fn promo_pagetop() -> Wrapper {
.with_size(flex::ItemSize::Percent50)
.add_component(Heading::h2(L10n::l("welcome_promo_title")))
.add_component(
Paragraph::translated(L10n::l("welcome_promo_text1").with_arg(
Paragraph::fluent(L10n::l("welcome_promo_text1").with_arg(
"pagetop",
format!(
"<a href=\"{}\" target=\"_blank\">{}</a>",
@ -199,10 +197,10 @@ fn reporting_issues() -> Wrapper {
.with_size(flex::ItemSize::Percent50)
.add_component(Heading::h2(L10n::l("welcome_issues_title")))
.add_component(
Paragraph::translated(L10n::l("welcome_issues_text1"))
Paragraph::fluent(L10n::l("welcome_issues_text1"))
.with_font_size(FontSize::Medium),
)
.add_component(Paragraph::translated(
.add_component(Paragraph::fluent(
L10n::l("welcome_issues_text2").with_arg(
"app",
format!(