🚚 Renombra region_name a region_key

This commit is contained in:
Manuel Cillero 2025-10-03 01:55:03 +02:00
parent 31310c1c13
commit 9af2ac39a1
5 changed files with 44 additions and 58 deletions

View file

@ -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" { footer class="intro-footer" {

View file

@ -105,9 +105,9 @@ pub trait Contextual: LangId {
#[builder_fn] #[builder_fn]
fn with_assets(self, op: ContextOp) -> Self; 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] #[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 >********************************************************************* // **< Contextual GETTERS >*********************************************************************
@ -290,10 +290,10 @@ impl Context {
markup markup
} }
/// Renderiza los componentes de una región (`region_name`). /// Renderiza los componentes de una región (`region_key`).
pub fn render_region(&mut self, region_name: &'static str) -> Markup { pub fn render_components_of(&mut self, region_key: &'static str) -> Markup {
self.regions self.regions
.merge_all_components(self.theme, region_name) .merge_all_components(self.theme, region_key)
.render(self) .render(self)
} }
@ -486,8 +486,8 @@ impl Contextual for Context {
} }
#[builder_fn] #[builder_fn]
fn with_child_in(mut self, region_name: &'static str, op: ChildOp) -> Self { fn with_child_in(mut self, region_key: &'static str, op: ChildOp) -> Self {
self.regions.alter_child_in(region_name, op); self.regions.alter_child_in(region_key, op);
self self
} }

View file

@ -36,7 +36,7 @@ pub trait ThemePage {
fn render_body(&self, page: &mut Page, regions: &[(Region, L10n)]) -> Markup { fn render_body(&self, page: &mut Page, regions: &[(Region, L10n)]) -> Markup {
html! { html! {
@for (region, region_label) in regions { @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() { @if !output.is_empty() {
@let region_name = region.name(); @let region_name = region.name();
div div
@ -84,7 +84,7 @@ pub trait ThemePage {
meta property=(property) content=(content) {} meta property=(property) content=(content) {}
} }
(page.render_assets()) (page.context().render_assets())
} }
} }
} }

View file

@ -76,30 +76,30 @@ impl Region {
pub struct ChildrenInRegions(HashMap<&'static str, Children>); pub struct ChildrenInRegions(HashMap<&'static str, Children>);
impl ChildrenInRegions { impl ChildrenInRegions {
pub fn with(region_name: &'static str, child: Child) -> Self { pub fn with(region_key: &'static str, child: Child) -> Self {
ChildrenInRegions::default().with_child_in(region_name, ChildOp::Add(child)) ChildrenInRegions::default().with_child_in(region_key, ChildOp::Add(child))
} }
#[builder_fn] #[builder_fn]
pub fn with_child_in(mut self, region_name: &'static str, op: ChildOp) -> Self { pub fn with_child_in(mut self, region_key: &'static str, op: ChildOp) -> Self {
if let Some(region) = self.0.get_mut(region_name) { if let Some(region) = self.0.get_mut(region_key) {
region.alter_child(op); region.alter_child(op);
} else { } else {
self.0.insert(region_name, Children::new().with_child(op)); self.0.insert(region_key, Children::new().with_child(op));
} }
self 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(); let common = COMMON_REGIONS.read();
if let Some(r) = THEME_REGIONS.read().get(&theme_ref.type_id()) { if let Some(r) = THEME_REGIONS.read().get(&theme_ref.type_id()) {
Children::merge(&[ Children::merge(&[
common.0.get(region_name), common.0.get(region_key),
self.0.get(region_name), self.0.get(region_key),
r.0.get(region_name), r.0.get(region_key),
]) ])
} else { } 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 { pub enum InRegion {
/// Región de contenido por defecto. /// Región de contenido por defecto.
Content, Content,
/// Región identificada por el nombre proporcionado. /// Región identificada por la clave proporcionado.
Named(&'static str), Key(&'static str),
/// Región identificada por un nombre y asociada a un tema concreto. /// Región identificada por una clave para un tema concreto.
OfTheme(&'static str, ThemeRef), OfTheme(&'static str, ThemeRef),
} }
@ -134,7 +134,7 @@ impl InRegion {
/// ))); /// )));
/// ///
/// // Texto en la región "sidebar". /// // Texto en la región "sidebar".
/// InRegion::Named("sidebar").add(Child::with(Html::with(|_| /// InRegion::Key("sidebar").add(Child::with(Html::with(|_|
/// html! { ("Publicidad") } /// html! { ("Publicidad") }
/// ))); /// )));
/// ``` /// ```
@ -145,19 +145,19 @@ impl InRegion {
.write() .write()
.alter_child_in(REGION_CONTENT, ChildOp::Add(child)); .alter_child_in(REGION_CONTENT, ChildOp::Add(child));
} }
InRegion::Named(region_name) => { InRegion::Key(region_key) => {
COMMON_REGIONS COMMON_REGIONS
.write() .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(); let mut regions = THEME_REGIONS.write();
if let Some(r) = regions.get_mut(&theme_ref.type_id()) { 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 { } else {
regions.insert( regions.insert(
theme_ref.type_id(), theme_ref.type_id(),
ChildrenInRegions::with(region_name, child), ChildrenInRegions::with(region_key, child),
); );
} }
} }

View file

@ -103,8 +103,8 @@ impl Page {
/// **Obsoleto desde la versión 0.4.0**: usar [`add_component_in()`](Self::add_component_in) en /// **Obsoleto desde la versión 0.4.0**: usar [`add_component_in()`](Self::add_component_in) en
/// su lugar. /// su lugar.
#[deprecated(since = "0.4.0", note = "Use `add_component_in()` instead")] #[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 { pub fn with_component_in(self, region_key: &'static str, component: impl Component) -> Self {
self.add_component_in(region_name, component) self.add_component_in(region_key, component)
} }
/// Añade un componente a la región de contenido por defecto. /// Añade un componente a la región de contenido por defecto.
@ -114,30 +114,26 @@ impl Page {
self self
} }
/// Añade un componente en una región (`region_name`) de la página. /// Añade un componente en una región (`region_key`) de la página.
pub fn add_component_in( pub fn add_component_in(mut self, region_key: &'static str, component: impl Component) -> Self {
mut self,
region_name: &'static str,
component: impl Component,
) -> Self {
self.context self.context
.alter_child_in(region_name, ChildOp::Add(Child::with(component))); .alter_child_in(region_key, ChildOp::Add(Child::with(component)));
self self
} }
/// **Obsoleto desde la versión 0.4.0**: usar [`with_child_in()`](Self::with_child_in) en su /// **Obsoleto desde la versión 0.4.0**: usar [`with_child_in()`](Self::with_child_in) en su
/// lugar. /// lugar.
#[deprecated(since = "0.4.0", note = "Use `with_child_in()` instead")] #[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 { pub fn with_child_in_region(mut self, region_key: &'static str, op: ChildOp) -> Self {
self.alter_child_in(region_name, op); self.alter_child_in(region_key, op);
self self
} }
/// **Obsoleto desde la versión 0.4.0**: usar [`alter_child_in()`](Self::alter_child_in) en su /// **Obsoleto desde la versión 0.4.0**: usar [`alter_child_in()`](Self::alter_child_in) en su
/// lugar. /// lugar.
#[deprecated(since = "0.4.0", note = "Use `alter_child_in()` instead")] #[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 { pub fn alter_child_in_region(&mut self, region_key: &'static str, op: ChildOp) -> &mut Self {
self.alter_child_in(region_name, op); self.alter_child_in(region_key, op);
self self
} }
@ -184,18 +180,6 @@ impl Page {
// **< Page RENDER >**************************************************************************** // **< 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. /// Renderiza la página completa en formato HTML.
/// ///
/// Ejecuta las acciones correspondientes antes y después de renderizar el `<body>`, /// Ejecuta las acciones correspondientes antes y después de renderizar el `<body>`,
@ -233,9 +217,9 @@ impl Page {
(head) (head)
} }
body id=[self.body_id().get()] class=[self.body_classes().get()] { body id=[self.body_id().get()] class=[self.body_classes().get()] {
(self.render_region("page-top")) (self.context.render_components_of("page-top"))
(body) (body)
(self.render_region("page-bottom")) (self.context.render_components_of("page-bottom"))
} }
} }
}) })
@ -288,8 +272,8 @@ impl Contextual for Page {
} }
#[builder_fn] #[builder_fn]
fn with_child_in(mut self, region_name: &'static str, op: ChildOp) -> Self { fn with_child_in(mut self, region_key: &'static str, op: ChildOp) -> Self {
self.context.alter_child_in(region_name, op); self.context.alter_child_in(region_key, op);
self self
} }