🎨 Mejora la página de bienvenida y el tema básico #6

Merged
manuelcillero merged 37 commits from advanced-welcome-page into main 2025-09-20 12:37:55 +02:00
5 changed files with 46 additions and 16 deletions
Showing only changes of commit 0e4f10237d - Show all commits

View file

@ -14,7 +14,7 @@ async fn hello_name(
) -> ResultPage<Markup, ErrorPage> { ) -> ResultPage<Markup, ErrorPage> {
let name = path.into_inner(); let name = path.into_inner();
Page::new(Some(request)) Page::new(Some(request))
.with_component(Html::with(move |_| html! { h1 { "Hello " (name) "!" } })) .add_component(Html::with(move |_| html! { h1 { "Hello " (name) "!" } }))
.render() .render()
} }

View file

@ -10,7 +10,7 @@ impl Extension for HelloWorld {
async fn hello_world(request: HttpRequest) -> ResultPage<Markup, ErrorPage> { async fn hello_world(request: HttpRequest) -> ResultPage<Markup, ErrorPage> {
Page::new(Some(request)) Page::new(Some(request))
.with_component(Html::with(move |_| html! { h1 { "Hello World!" } })) .add_component(Html::with(move |_| html! { h1 { "Hello World!" } }))
.render() .render()
} }

View file

@ -77,11 +77,11 @@ 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_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] #[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) { if let Some(region) = self.0.get_mut(region_name) {
region.alter_child(op); region.alter_child(op);
} else { } else {
@ -143,17 +143,17 @@ impl InRegion {
InRegion::Content => { InRegion::Content => {
COMMON_REGIONS COMMON_REGIONS
.write() .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 COMMON_REGIONS
.write() .write()
.alter_child_in_region(name, ChildOp::Add(child)); .alter_child_in(region_name, ChildOp::Add(child));
} }
InRegion::OfTheme(region_name, theme_ref) => { InRegion::OfTheme(region_name, 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(region_name, ChildOp::Add(child)); r.alter_child_in(region_name, ChildOp::Add(child));
} else { } else {
regions.insert( regions.insert(
theme_ref.type_id(), theme_ref.type_id(),

View file

@ -122,28 +122,58 @@ impl Page {
self 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. /// 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 self.regions
.alter_child_in_region(REGION_CONTENT, ChildOp::Add(Child::with(component))); .alter_child_in(REGION_CONTENT, ChildOp::Add(Child::with(component)));
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_name`) de la página.
pub fn with_component_in( pub fn add_component_in(
mut self, mut self,
region_name: &'static str, region_name: &'static str,
component: impl Component, component: impl Component,
) -> Self { ) -> Self {
self.regions 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 self
} }
/// Opera con [`ChildOp`] en una región (`region_name`) de la página. /// Opera con [`ChildOp`] en una región (`region_name`) de la página.
#[builder_fn] #[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 {
self.regions.alter_child_in_region(region_name, op); self.regions.alter_child_in(region_name, op);
self self
} }

View file

@ -33,7 +33,7 @@ impl Display for ErrorPage {
if let Ok(page) = error_page if let Ok(page) = error_page
.with_title(L10n::n("Error FORBIDDEN")) .with_title(L10n::n("Error FORBIDDEN"))
.with_layout("error") .with_layout("error")
.with_component(Html::with(move |_| error403.clone())) .add_component(Html::with(move |_| error403.clone()))
.render() .render()
{ {
write!(f, "{}", page.into_string()) write!(f, "{}", page.into_string())
@ -48,7 +48,7 @@ impl Display for ErrorPage {
if let Ok(page) = error_page if let Ok(page) = error_page
.with_title(L10n::n("Error RESOURCE NOT FOUND")) .with_title(L10n::n("Error RESOURCE NOT FOUND"))
.with_layout("error") .with_layout("error")
.with_component(Html::with(move |_| error404.clone())) .add_component(Html::with(move |_| error404.clone()))
.render() .render()
{ {
write!(f, "{}", page.into_string()) write!(f, "{}", page.into_string())