diff --git a/src/base/theme/basic.rs b/src/base/theme/basic.rs index 28d9389..54660a9 100644 --- a/src/base/theme/basic.rs +++ b/src/base/theme/basic.rs @@ -136,7 +136,9 @@ fn render_intro(page: &mut Page) -> Markup { } } } - div class="intro-text" { (page.render_region("content")) } + div class="intro-text" { + (page.context().render_components_of("content")) + } } } footer class="intro-footer" { diff --git a/src/core/component/context.rs b/src/core/component/context.rs index b344c86..f58d381 100644 --- a/src/core/component/context.rs +++ b/src/core/component/context.rs @@ -105,9 +105,9 @@ pub trait Contextual: LangId { #[builder_fn] fn with_assets(self, op: ContextOp) -> Self; - /// Opera con [`ChildOp`] en una región (`region_name`) de la página. + /// Opera con [`ChildOp`] en una región (`region_key`) de la página. #[builder_fn] - fn with_child_in(self, region_name: &'static str, op: ChildOp) -> Self; + fn with_child_in(self, region_key: &'static str, op: ChildOp) -> Self; // **< Contextual GETTERS >********************************************************************* @@ -290,10 +290,10 @@ impl Context { markup } - /// Renderiza los componentes de una región (`region_name`). - pub fn render_region(&mut self, region_name: &'static str) -> Markup { + /// Renderiza los componentes de una región (`region_key`). + pub fn render_components_of(&mut self, region_key: &'static str) -> Markup { self.regions - .merge_all_components(self.theme, region_name) + .merge_all_components(self.theme, region_key) .render(self) } @@ -486,8 +486,8 @@ impl Contextual for Context { } #[builder_fn] - fn with_child_in(mut self, region_name: &'static str, op: ChildOp) -> Self { - self.regions.alter_child_in(region_name, op); + fn with_child_in(mut self, region_key: &'static str, op: ChildOp) -> Self { + self.regions.alter_child_in(region_key, op); self } diff --git a/src/core/theme/definition.rs b/src/core/theme/definition.rs index 643bfff..4478ad0 100644 --- a/src/core/theme/definition.rs +++ b/src/core/theme/definition.rs @@ -36,7 +36,7 @@ pub trait ThemePage { fn render_body(&self, page: &mut Page, regions: &[(Region, L10n)]) -> Markup { html! { @for (region, region_label) in regions { - @let output = page.render_region(region.key()); + @let output = page.context().render_components_of(region.key()); @if !output.is_empty() { @let region_name = region.name(); div @@ -84,7 +84,7 @@ pub trait ThemePage { meta property=(property) content=(content) {} } - (page.render_assets()) + (page.context().render_assets()) } } } diff --git a/src/core/theme/regions.rs b/src/core/theme/regions.rs index f14645c..3fdfe09 100644 --- a/src/core/theme/regions.rs +++ b/src/core/theme/regions.rs @@ -76,30 +76,30 @@ impl Region { pub struct ChildrenInRegions(HashMap<&'static str, Children>); impl ChildrenInRegions { - pub fn with(region_name: &'static str, child: Child) -> Self { - ChildrenInRegions::default().with_child_in(region_name, ChildOp::Add(child)) + pub fn with(region_key: &'static str, child: Child) -> Self { + ChildrenInRegions::default().with_child_in(region_key, ChildOp::Add(child)) } #[builder_fn] - pub fn with_child_in(mut self, region_name: &'static str, op: ChildOp) -> Self { - if let Some(region) = self.0.get_mut(region_name) { + pub fn with_child_in(mut self, region_key: &'static str, op: ChildOp) -> Self { + if let Some(region) = self.0.get_mut(region_key) { region.alter_child(op); } else { - self.0.insert(region_name, Children::new().with_child(op)); + self.0.insert(region_key, Children::new().with_child(op)); } self } - pub fn merge_all_components(&self, theme_ref: ThemeRef, region_name: &'static str) -> Children { + pub fn merge_all_components(&self, theme_ref: ThemeRef, region_key: &'static str) -> Children { let common = COMMON_REGIONS.read(); if let Some(r) = THEME_REGIONS.read().get(&theme_ref.type_id()) { Children::merge(&[ - common.0.get(region_name), - self.0.get(region_name), - r.0.get(region_name), + common.0.get(region_key), + self.0.get(region_key), + r.0.get(region_key), ]) } else { - Children::merge(&[common.0.get(region_name), self.0.get(region_name)]) + Children::merge(&[common.0.get(region_key), self.0.get(region_key)]) } } } @@ -114,9 +114,9 @@ impl ChildrenInRegions { pub enum InRegion { /// Región de contenido por defecto. Content, - /// Región identificada por el nombre proporcionado. - Named(&'static str), - /// Región identificada por un nombre y asociada a un tema concreto. + /// Región identificada por la clave proporcionado. + Key(&'static str), + /// Región identificada por una clave para un tema concreto. OfTheme(&'static str, ThemeRef), } @@ -134,7 +134,7 @@ impl InRegion { /// ))); /// /// // Texto en la región "sidebar". - /// InRegion::Named("sidebar").add(Child::with(Html::with(|_| + /// InRegion::Key("sidebar").add(Child::with(Html::with(|_| /// html! { ("Publicidad") } /// ))); /// ``` @@ -145,19 +145,19 @@ impl InRegion { .write() .alter_child_in(REGION_CONTENT, ChildOp::Add(child)); } - InRegion::Named(region_name) => { + InRegion::Key(region_key) => { COMMON_REGIONS .write() - .alter_child_in(region_name, ChildOp::Add(child)); + .alter_child_in(region_key, ChildOp::Add(child)); } - InRegion::OfTheme(region_name, theme_ref) => { + InRegion::OfTheme(region_key, theme_ref) => { let mut regions = THEME_REGIONS.write(); if let Some(r) = regions.get_mut(&theme_ref.type_id()) { - r.alter_child_in(region_name, ChildOp::Add(child)); + r.alter_child_in(region_key, ChildOp::Add(child)); } else { regions.insert( theme_ref.type_id(), - ChildrenInRegions::with(region_name, child), + ChildrenInRegions::with(region_key, child), ); } } diff --git a/src/response/page.rs b/src/response/page.rs index deab452..1649d54 100644 --- a/src/response/page.rs +++ b/src/response/page.rs @@ -103,8 +103,8 @@ impl Page { /// **Obsoleto desde la versión 0.4.0**: usar [`add_component_in()`](Self::add_component_in) en /// su lugar. #[deprecated(since = "0.4.0", note = "Use `add_component_in()` instead")] - pub fn with_component_in(self, region_name: &'static str, component: impl Component) -> Self { - self.add_component_in(region_name, component) + pub fn with_component_in(self, region_key: &'static str, component: impl Component) -> Self { + self.add_component_in(region_key, component) } /// Añade un componente a la región de contenido por defecto. @@ -114,30 +114,26 @@ impl Page { self } - /// Añade un componente en una región (`region_name`) de la página. - pub fn add_component_in( - mut self, - region_name: &'static str, - component: impl Component, - ) -> Self { + /// Añade un componente en una región (`region_key`) de la página. + pub fn add_component_in(mut self, region_key: &'static str, component: impl Component) -> Self { self.context - .alter_child_in(region_name, ChildOp::Add(Child::with(component))); + .alter_child_in(region_key, ChildOp::Add(Child::with(component))); self } /// **Obsoleto desde la versión 0.4.0**: usar [`with_child_in()`](Self::with_child_in) en su /// lugar. #[deprecated(since = "0.4.0", note = "Use `with_child_in()` instead")] - pub fn with_child_in_region(mut self, region_name: &'static str, op: ChildOp) -> Self { - self.alter_child_in(region_name, op); + pub fn with_child_in_region(mut self, region_key: &'static str, op: ChildOp) -> Self { + self.alter_child_in(region_key, op); self } /// **Obsoleto desde la versión 0.4.0**: usar [`alter_child_in()`](Self::alter_child_in) en su /// lugar. #[deprecated(since = "0.4.0", note = "Use `alter_child_in()` instead")] - pub fn alter_child_in_region(&mut self, region_name: &'static str, op: ChildOp) -> &mut Self { - self.alter_child_in(region_name, op); + pub fn alter_child_in_region(&mut self, region_key: &'static str, op: ChildOp) -> &mut Self { + self.alter_child_in(region_key, op); self } @@ -184,18 +180,6 @@ impl Page { // **< Page RENDER >**************************************************************************** - /// Renderiza los componentes de una región (`region_name`) de la página. - #[inline] - pub fn render_region(&mut self, region_name: &'static str) -> Markup { - self.context.render_region(region_name) - } - - /// Renderiza los recursos de la página. - #[inline] - pub fn render_assets(&mut self) -> Markup { - self.context.render_assets() - } - /// Renderiza la página completa en formato HTML. /// /// Ejecuta las acciones correspondientes antes y después de renderizar el ``, @@ -233,9 +217,9 @@ impl Page { (head) } body id=[self.body_id().get()] class=[self.body_classes().get()] { - (self.render_region("page-top")) + (self.context.render_components_of("page-top")) (body) - (self.render_region("page-bottom")) + (self.context.render_components_of("page-bottom")) } } }) @@ -288,8 +272,8 @@ impl Contextual for Page { } #[builder_fn] - fn with_child_in(mut self, region_name: &'static str, op: ChildOp) -> Self { - self.context.alter_child_in(region_name, op); + fn with_child_in(mut self, region_key: &'static str, op: ChildOp) -> Self { + self.context.alter_child_in(region_key, op); self }