diff --git a/pagetop-megamenu/src/component.rs b/pagetop-megamenu/src/component.rs index ad6da656..fdaa5be4 100644 --- a/pagetop-megamenu/src/component.rs +++ b/pagetop-megamenu/src/component.rs @@ -175,6 +175,10 @@ impl ComponentTrait for MegaMenu { COMPONENT_MEGAMENU } + fn id(&self) -> Option { + self.id.get() + } + fn weight(&self) -> isize { self.weight } @@ -264,10 +268,6 @@ impl MegaMenu { // MegaMenu GETTERS. - pub fn id(&self) -> &IdentifierValue { - &self.id - } - pub fn classes(&self) -> &Classes { &self.classes } diff --git a/pagetop-minimal/src/component/anchor.rs b/pagetop-minimal/src/component/anchor.rs index dba9c7d6..da7ba95c 100644 --- a/pagetop-minimal/src/component/anchor.rs +++ b/pagetop-minimal/src/component/anchor.rs @@ -50,6 +50,10 @@ impl ComponentTrait for Anchor { COMPONENT_ANCHOR } + fn id(&self) -> Option { + self.id.get() + } + fn weight(&self) -> isize { self.weight } @@ -69,7 +73,7 @@ impl ComponentTrait for Anchor { }; html! { a - id=[self.id().get()] + id=[self.id()] class=[self.classes().get()] href=[self.href().get()] target=[target] @@ -183,10 +187,6 @@ impl Anchor { // Anchor GETTERS. - pub fn id(&self) -> &IdentifierValue { - &self.id - } - pub fn classes(&self) -> &Classes { &self.classes } diff --git a/pagetop-minimal/src/component/container.rs b/pagetop-minimal/src/component/container.rs index 82a4d8c1..f61a01ea 100644 --- a/pagetop-minimal/src/component/container.rs +++ b/pagetop-minimal/src/component/container.rs @@ -38,6 +38,10 @@ impl ComponentTrait for Container { COMPONENT_CONTAINER } + fn id(&self) -> Option { + self.id.get() + } + fn weight(&self) -> isize { self.weight } @@ -53,35 +57,35 @@ impl ComponentTrait for Container { fn default_render(&self, rcx: &mut RenderContext) -> Markup { match self.container_type() { ContainerType::Header => html! { - header id=[self.id().get()] class=[self.classes().get()] { + header id=[self.id()] class=[self.classes().get()] { div class=[self.inner_classes().get()] { (self.components().render(rcx)) } } }, ContainerType::Footer => html! { - footer id=[self.id().get()] class=[self.classes().get()] { + footer id=[self.id()] class=[self.classes().get()] { div class=[self.inner_classes().get()] { (self.components().render(rcx)) } } }, ContainerType::Main => html! { - main id=[self.id().get()] class=[self.classes().get()] { + main id=[self.id()] class=[self.classes().get()] { div class=[self.inner_classes().get()] { (self.components().render(rcx)) } } }, ContainerType::Section => html! { - section id=[self.id().get()] class=[self.classes().get()] { + section id=[self.id()] class=[self.classes().get()] { div class=[self.inner_classes().get()] { (self.components().render(rcx)) } } }, _ => html! { - div id=[self.id().get()] class=[self.classes().get()] { + div id=[self.id()] class=[self.classes().get()] { (self.components().render(rcx)) } }, @@ -168,10 +172,6 @@ impl Container { // Container GETTERS. - pub fn id(&self) -> &IdentifierValue { - &self.id - } - pub fn classes(&self) -> &Classes { &self.classes } diff --git a/pagetop-minimal/src/component/form_element/form.rs b/pagetop-minimal/src/component/form_element/form.rs index 979d9a78..ccab94ff 100644 --- a/pagetop-minimal/src/component/form_element/form.rs +++ b/pagetop-minimal/src/component/form_element/form.rs @@ -36,6 +36,10 @@ impl ComponentTrait for Form { COMPONENT_FORM } + fn id(&self) -> Option { + self.id.get() + } + fn weight(&self) -> isize { self.weight } @@ -55,7 +59,7 @@ impl ComponentTrait for Form { }; html! { form - id=[self.id().get()] + id=[self.id()] class=[self.classes().get()] action=[self.action().get()] method=[method] @@ -134,10 +138,6 @@ impl Form { // Form GETTERS. - pub fn id(&self) -> &IdentifierValue { - &self.id - } - pub fn classes(&self) -> &Classes { &self.classes } diff --git a/pagetop-minimal/src/component/grid/column.rs b/pagetop-minimal/src/component/grid/column.rs index f623b942..192b760a 100644 --- a/pagetop-minimal/src/component/grid/column.rs +++ b/pagetop-minimal/src/component/grid/column.rs @@ -57,6 +57,10 @@ impl ComponentTrait for Column { COMPONENT_COLUMN } + fn id(&self) -> Option { + self.id.get() + } + fn weight(&self) -> isize { self.weight } @@ -71,7 +75,7 @@ impl ComponentTrait for Column { fn default_render(&self, rcx: &mut RenderContext) -> Markup { html! { - div id=[self.id().get()] class=[self.classes().get()] { + div id=[self.id()] class=[self.classes().get()] { (self.components().render(rcx)) } } @@ -149,10 +153,6 @@ impl Column { // Column GETTERS. - pub fn id(&self) -> &IdentifierValue { - &self.id - } - pub fn classes(&self) -> &Classes { &self.classes } diff --git a/pagetop-minimal/src/component/grid/row.rs b/pagetop-minimal/src/component/grid/row.rs index c167617a..f9848568 100644 --- a/pagetop-minimal/src/component/grid/row.rs +++ b/pagetop-minimal/src/component/grid/row.rs @@ -26,6 +26,10 @@ impl ComponentTrait for Row { COMPONENT_ROW } + fn id(&self) -> Option { + self.id.get() + } + fn weight(&self) -> isize { self.weight } @@ -40,7 +44,7 @@ impl ComponentTrait for Row { fn default_render(&self, rcx: &mut RenderContext) -> Markup { html! { - div id=[self.id().get()] class=[self.classes().get()] { + div id=[self.id()] class=[self.classes().get()] { (self.columns().render(rcx)) } } @@ -96,10 +100,6 @@ impl Row { // Row GETTERS. - pub fn id(&self) -> &IdentifierValue { - &self.id - } - pub fn classes(&self) -> &Classes { &self.classes } diff --git a/pagetop-minimal/src/component/heading.rs b/pagetop-minimal/src/component/heading.rs index 4e1eb21b..666fdbcd 100644 --- a/pagetop-minimal/src/component/heading.rs +++ b/pagetop-minimal/src/component/heading.rs @@ -49,6 +49,10 @@ impl ComponentTrait for Heading { COMPONENT_HEADING } + fn id(&self) -> Option { + self.id.get() + } + fn weight(&self) -> isize { self.weight } @@ -58,7 +62,7 @@ impl ComponentTrait for Heading { } fn default_render(&self, rcx: &mut RenderContext) -> Markup { - let id = self.id().get(); + let id = self.id(); let classes = self.classes().get(); html! { @match &self.heading_type() { HeadingType::H1 => h1 id=[id] class=[classes] { (self.text().render(rcx)) }, @@ -181,10 +185,6 @@ impl Heading { // Paragraph GETTERS. - pub fn id(&self) -> &IdentifierValue { - &self.id - } - pub fn classes(&self) -> &Classes { &self.classes } diff --git a/pagetop-minimal/src/component/image.rs b/pagetop-minimal/src/component/image.rs index 2c87e0e8..840ef2ae 100644 --- a/pagetop-minimal/src/component/image.rs +++ b/pagetop-minimal/src/component/image.rs @@ -22,6 +22,10 @@ impl ComponentTrait for Image { COMPONENT_IMAGE } + fn id(&self) -> Option { + self.id.get() + } + fn weight(&self) -> isize { self.weight } @@ -34,7 +38,7 @@ impl ComponentTrait for Image { html! { img src=[self.source().get()] - id=[self.id().get()] + id=[self.id()] class=[self.classes().get()]; } } @@ -93,10 +97,6 @@ impl Image { // Image GETTERS. - pub fn id(&self) -> &IdentifierValue { - &self.id - } - pub fn classes(&self) -> &Classes { &self.classes } diff --git a/pagetop-minimal/src/component/paragraph.rs b/pagetop-minimal/src/component/paragraph.rs index ee3a047d..9e6b1df5 100644 --- a/pagetop-minimal/src/component/paragraph.rs +++ b/pagetop-minimal/src/component/paragraph.rs @@ -34,6 +34,10 @@ impl ComponentTrait for Paragraph { COMPONENT_PARAGRAPH } + fn id(&self) -> Option { + self.id.get() + } + fn weight(&self) -> isize { self.weight } @@ -45,7 +49,7 @@ impl ComponentTrait for Paragraph { fn default_render(&self, rcx: &mut RenderContext) -> Markup { html! { p - id=[self.id().get()] + id=[self.id()] class=[self.classes().get()] { (self.components().render(rcx)) @@ -125,10 +129,6 @@ impl Paragraph { // Paragraph GETTERS. - pub fn id(&self) -> &IdentifierValue { - &self.id - } - pub fn classes(&self) -> &Classes { &self.classes } diff --git a/pagetop/src/base/action/before_render_component.rs b/pagetop/src/base/action/before_render_component.rs index 1acf30ff..f2bd2e4f 100644 --- a/pagetop/src/base/action/before_render_component.rs +++ b/pagetop/src/base/action/before_render_component.rs @@ -6,14 +6,14 @@ macro_rules! action_before_render_component { type Action = fn(&$Component, &mut RenderContext); - pub struct [< BeforeRender $Component >] { + pub struct [] { action: Option, weight: isize, } - impl ActionTrait for [< BeforeRender $Component >] { + impl ActionTrait for [] { fn new() -> Self { - [< BeforeRender $Component >] { + [] { action: None, weight: 0, } @@ -32,7 +32,7 @@ macro_rules! action_before_render_component { } } - impl [< BeforeRender $Component >] { + impl [] { #[allow(dead_code)] pub fn with_action(mut self, action: Action) -> Self { self.action = Some(action); @@ -55,7 +55,7 @@ macro_rules! action_before_render_component { #[inline(always)] pub fn before_render_inline(component: &mut $Component, rcx: &mut RenderContext) { run_actions($ACTION_HANDLE, |action| - action_ref::<[< BeforeRender $Component >]>(&**action) + action_ref::<[]>(&**action) .run(component, rcx) ); } diff --git a/pagetop/src/base/component/block.rs b/pagetop/src/base/component/block.rs index 5153d6bf..4e3cf1d3 100644 --- a/pagetop/src/base/component/block.rs +++ b/pagetop/src/base/component/block.rs @@ -25,6 +25,10 @@ impl ComponentTrait for Block { COMPONENT_BLOCK } + fn id(&self) -> Option { + self.id.get() + } + fn weight(&self) -> isize { self.weight } @@ -107,10 +111,6 @@ impl Block { // Block GETTERS. - pub fn id(&self) -> &IdentifierValue { - &self.id - } - pub fn classes(&self) -> &Classes { &self.classes } diff --git a/pagetop/src/core/component/context.rs b/pagetop/src/core/component/context.rs index 295e33ac..e9550930 100644 --- a/pagetop/src/core/component/context.rs +++ b/pagetop/src/core/component/context.rs @@ -1,5 +1,5 @@ use crate::core::theme::{all::theme_by_single_name, ThemeStaticRef}; -use crate::html::{html, Assets, IdentifierValue, JavaScript, Markup, StyleSheet}; +use crate::html::{html, Assets, JavaScript, Markup, StyleSheet}; use crate::locale::{LanguageIdentifier, LANGID}; use crate::server::HttpRequest; use crate::{concat_string, config, util, LazyStatic}; @@ -120,8 +120,8 @@ impl RenderContext { // Context EXTRAS. - pub fn required_id(&mut self, id: &IdentifierValue) -> String { - match id.get() { + pub fn required_id(&mut self, id: Option) -> String { + match id { Some(id) => id, None => { let prefix = util::single_type_name::() diff --git a/pagetop/src/core/component/definition.rs b/pagetop/src/core/component/definition.rs index d153b65e..d81f30b9 100644 --- a/pagetop/src/core/component/definition.rs +++ b/pagetop/src/core/component/definition.rs @@ -27,6 +27,10 @@ pub trait ComponentTrait: AnyComponent + BaseComponent + Send + Sync { None } + fn id(&self) -> Option { + None + } + fn weight(&self) -> isize { 0 } diff --git a/pagetop/src/html/attribute.rs b/pagetop/src/html/attribute.rs index 1a68d21a..965e8beb 100644 --- a/pagetop/src/html/attribute.rs +++ b/pagetop/src/html/attribute.rs @@ -1,3 +1,5 @@ +use crate::fn_builder; + #[derive(Default)] pub struct AttributeValue(String); @@ -8,13 +10,7 @@ impl AttributeValue { // AttributeValue BUILDER. - pub fn with_value(mut self, value: &str) -> Self { - self.alter_value(value); - self - } - - // AttributeValue ALTER. - + #[fn_builder] pub fn alter_value(&mut self, value: &str) -> &mut Self { self.0 = value.trim().to_owned(); self diff --git a/pagetop/src/html/classes.rs b/pagetop/src/html/classes.rs index 6d453128..f9f4ee04 100644 --- a/pagetop/src/html/classes.rs +++ b/pagetop/src/html/classes.rs @@ -1,4 +1,4 @@ -use crate::concat_string; +use crate::{concat_string, fn_builder}; pub enum ClassesOp { Add, @@ -26,13 +26,7 @@ impl Classes { // Classes BUILDER. - pub fn with_value(mut self, op: ClassesOp, classes: &str) -> Self { - self.alter_value(op, classes); - self - } - - // Classes ALTER. - + #[fn_builder] pub fn alter_value(&mut self, op: ClassesOp, classes: &str) -> &mut Self { let classes = classes.trim(); match op { diff --git a/pagetop/src/html/identifier.rs b/pagetop/src/html/identifier.rs index 6707a71f..90f8295b 100644 --- a/pagetop/src/html/identifier.rs +++ b/pagetop/src/html/identifier.rs @@ -1,3 +1,5 @@ +use crate::fn_builder; + #[derive(Default)] pub struct IdentifierValue(String); @@ -8,13 +10,7 @@ impl IdentifierValue { // IdentifierValue BUILDER. - pub fn with_value(mut self, value: &str) -> Self { - self.alter_value(value); - self - } - - // IdentifierValue ALTER. - + #[fn_builder] pub fn alter_value(&mut self, value: &str) -> &mut Self { self.0 = value.trim().replace(' ', "_"); self diff --git a/pagetop/src/html/name.rs b/pagetop/src/html/name.rs index 5f8f2195..c3f2af12 100644 --- a/pagetop/src/html/name.rs +++ b/pagetop/src/html/name.rs @@ -1,3 +1,5 @@ +use crate::fn_builder; + #[derive(Default)] pub struct NameValue(String); @@ -8,13 +10,7 @@ impl NameValue { // NameValue BUILDER. - pub fn with_value(mut self, value: &str) -> Self { - self.alter_value(value); - self - } - - // NameValue ALTER. - + #[fn_builder] pub fn alter_value(&mut self, value: &str) -> &mut Self { self.0 = value.trim().replace(' ', "_"); self diff --git a/pagetop/src/util.rs b/pagetop/src/util.rs index 29906378..63fd72e9 100644 --- a/pagetop/src/util.rs +++ b/pagetop/src/util.rs @@ -1,4 +1,4 @@ -//! Funciones Ăștiles y macros declarativas. +//! Funciones Ăștiles. use crate::Handle; @@ -7,6 +7,7 @@ use crate::Handle; // ************************************************************************************************* // https://stackoverflow.com/a/71464396 +#[doc(hidden)] pub const fn handle( module_path: &'static str, file: &'static str,