From 0e4f10237da6c97a67965e135278cb1ee1e21308 Mon Sep 17 00:00:00 2001 From: Manuel Cillero Date: Thu, 4 Sep 2025 01:11:03 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=9A=20Renombra=20`with=5Fcomponent`=20?= =?UTF-8?q?por=20`add=5Fcomponent`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/hello-name.rs | 2 +- examples/hello-world.rs | 2 +- src/core/theme/regions.rs | 12 +++++------ src/response/page.rs | 42 ++++++++++++++++++++++++++++++++------ src/response/page/error.rs | 4 ++-- 5 files changed, 46 insertions(+), 16 deletions(-) diff --git a/examples/hello-name.rs b/examples/hello-name.rs index 7a6db54..3a491a6 100644 --- a/examples/hello-name.rs +++ b/examples/hello-name.rs @@ -14,7 +14,7 @@ async fn hello_name( ) -> ResultPage { let name = path.into_inner(); Page::new(Some(request)) - .with_component(Html::with(move |_| html! { h1 { "Hello " (name) "!" } })) + .add_component(Html::with(move |_| html! { h1 { "Hello " (name) "!" } })) .render() } diff --git a/examples/hello-world.rs b/examples/hello-world.rs index ba268dc..5550514 100644 --- a/examples/hello-world.rs +++ b/examples/hello-world.rs @@ -10,7 +10,7 @@ impl Extension for HelloWorld { async fn hello_world(request: HttpRequest) -> ResultPage { Page::new(Some(request)) - .with_component(Html::with(move |_| html! { h1 { "Hello World!" } })) + .add_component(Html::with(move |_| html! { h1 { "Hello World!" } })) .render() } diff --git a/src/core/theme/regions.rs b/src/core/theme/regions.rs index c8a0555..4fcd7df 100644 --- a/src/core/theme/regions.rs +++ b/src/core/theme/regions.rs @@ -77,11 +77,11 @@ 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(region_name, ChildOp::Add(child)) + ChildrenInRegions::default().with_child_in(region_name, ChildOp::Add(child)) } #[builder_fn] - pub fn with_child_in_region(mut self, region_name: &'static str, op: ChildOp) -> Self { + pub fn with_child_in(mut self, region_name: &'static str, op: ChildOp) -> Self { if let Some(region) = self.0.get_mut(region_name) { region.alter_child(op); } else { @@ -143,17 +143,17 @@ impl InRegion { InRegion::Content => { COMMON_REGIONS .write() - .alter_child_in_region(REGION_CONTENT, ChildOp::Add(child)); + .alter_child_in(REGION_CONTENT, ChildOp::Add(child)); } - InRegion::Named(name) => { + InRegion::Named(region_name) => { COMMON_REGIONS .write() - .alter_child_in_region(name, ChildOp::Add(child)); + .alter_child_in(region_name, ChildOp::Add(child)); } InRegion::OfTheme(region_name, theme_ref) => { let mut regions = THEME_REGIONS.write(); if let Some(r) = regions.get_mut(&theme_ref.type_id()) { - r.alter_child_in_region(region_name, ChildOp::Add(child)); + r.alter_child_in(region_name, ChildOp::Add(child)); } else { regions.insert( theme_ref.type_id(), diff --git a/src/response/page.rs b/src/response/page.rs index 7ef5270..5ac3720 100644 --- a/src/response/page.rs +++ b/src/response/page.rs @@ -122,28 +122,58 @@ impl Page { self } + /// **Obsoleto desde la versión 0.4.0**: usar [`add_component()`](Self::add_component) en su + /// lugar. + #[deprecated(since = "0.4.0", note = "Use `add_component()` instead")] + pub fn with_component(self, component: impl Component) -> Self { + self.add_component(component) + } + + /// **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) + } + /// Añade un componente a la región de contenido por defecto. - pub fn with_component(mut self, component: impl Component) -> Self { + pub fn add_component(mut self, component: impl Component) -> Self { self.regions - .alter_child_in_region(REGION_CONTENT, ChildOp::Add(Child::with(component))); + .alter_child_in(REGION_CONTENT, ChildOp::Add(Child::with(component))); self } /// Añade un componente en una región (`region_name`) de la página. - pub fn with_component_in( + pub fn add_component_in( mut self, region_name: &'static str, component: impl Component, ) -> Self { self.regions - .alter_child_in_region(region_name, ChildOp::Add(Child::with(component))); + .alter_child_in(region_name, 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); + 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); self } /// Opera con [`ChildOp`] en una región (`region_name`) de la página. #[builder_fn] - pub fn with_child_in_region(mut self, region_name: &'static str, op: ChildOp) -> Self { - self.regions.alter_child_in_region(region_name, op); + pub fn with_child_in(mut self, region_name: &'static str, op: ChildOp) -> Self { + self.regions.alter_child_in(region_name, op); self } diff --git a/src/response/page/error.rs b/src/response/page/error.rs index 99ba62b..ab56338 100644 --- a/src/response/page/error.rs +++ b/src/response/page/error.rs @@ -33,7 +33,7 @@ impl Display for ErrorPage { if let Ok(page) = error_page .with_title(L10n::n("Error FORBIDDEN")) .with_layout("error") - .with_component(Html::with(move |_| error403.clone())) + .add_component(Html::with(move |_| error403.clone())) .render() { write!(f, "{}", page.into_string()) @@ -48,7 +48,7 @@ impl Display for ErrorPage { if let Ok(page) = error_page .with_title(L10n::n("Error RESOURCE NOT FOUND")) .with_layout("error") - .with_component(Html::with(move |_| error404.clone())) + .add_component(Html::with(move |_| error404.clone())) .render() { write!(f, "{}", page.into_string())