Revierte anterior commit

This commit is contained in:
Manuel Cillero 2023-05-30 19:21:53 +02:00
parent bcfdc412a0
commit d0add7c7ab

View file

@ -1,7 +1,7 @@
use crate::core::component::{AnyComponent, ComponentTrait, RenderContext}; use crate::core::component::{AnyComponent, ComponentTrait, RenderContext};
use crate::html::{html, Markup, PreEscaped}; use crate::html::{html, Markup, PreEscaped};
use crate::locale::{translate, Locale, Locales}; use crate::locale::{translate, Locale, Locales};
use crate::{define_handle, paste, Handle}; use crate::{define_handle, fn_builder, paste, Handle};
use std::collections::HashMap; use std::collections::HashMap;
@ -10,7 +10,7 @@ macro_rules! basic_components {
define_handle!($COMPONENT_HANDLE); define_handle!($COMPONENT_HANDLE);
enum [< $Component Op >] { pub enum [< $Component Op >] {
None, None,
Value($TypeValue), Value($TypeValue),
Translated(&'static str, &'static Locales), Translated(&'static str, &'static Locales),
@ -41,7 +41,7 @@ macro_rules! basic_components {
} }
fn default_render(&self, rcx: &mut RenderContext) -> Markup { fn default_render(&self, rcx: &mut RenderContext) -> Markup {
match &self.op { match self.op() {
[< $Component Op >]::None => html! {}, [< $Component Op >]::None => html! {},
[< $Component Op >]::Value(value) => html! { (value) }, [< $Component Op >]::Value(value) => html! { (value) },
[< $Component Op >]::Translated(key, locales) => html! { [< $Component Op >]::Translated(key, locales) => html! {
@ -50,7 +50,7 @@ macro_rules! basic_components {
Locale::Using( Locale::Using(
rcx.langid(), rcx.langid(),
locales, locales,
&self.args.iter().fold(HashMap::new(), |mut args, (key, value)| { &self.args().iter().fold(HashMap::new(), |mut args, (key, value)| {
args.insert(key.to_string(), value.to_owned().into()); args.insert(key.to_string(), value.to_owned().into());
args args
}) })
@ -63,7 +63,7 @@ macro_rules! basic_components {
Locale::Using( Locale::Using(
rcx.langid(), rcx.langid(),
locales, locales,
&self.args.iter().fold(HashMap::new(), |mut args, (key, value)| { &self.args().iter().fold(HashMap::new(), |mut args, (key, value)| {
args.insert(key.to_string(), value.to_owned().into()); args.insert(key.to_string(), value.to_owned().into());
args args
}) })
@ -103,6 +103,35 @@ macro_rules! basic_components {
..Default::default() ..Default::default()
} }
} }
// $Component BUILDER.
#[fn_builder]
pub fn alter_op(&mut self, op: [< $Component Op >]) -> &mut Self {
self.op = op;
self
}
#[fn_builder]
pub fn alter_arg(&mut self, arg: &'static str, value: String) -> &mut Self {
self.args.insert(arg, value);
self
}
pub fn clear_args(&mut self) -> &mut Self {
self.args.drain();
self
}
// $Component GETTERS.
pub fn op(&self) -> &[< $Component Op >] {
&self.op
}
pub fn args(&self) -> &HashMap<&str, String> {
&self.args
}
} }
} )* }; } )* };