🎨 Mejora la página de bienvenida y el tema básico #6
5 changed files with 46 additions and 16 deletions
|
@ -14,7 +14,7 @@ async fn hello_name(
|
|||
) -> ResultPage<Markup, ErrorPage> {
|
||||
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()
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ impl Extension for HelloWorld {
|
|||
|
||||
async fn hello_world(request: HttpRequest) -> ResultPage<Markup, ErrorPage> {
|
||||
Page::new(Some(request))
|
||||
.with_component(Html::with(move |_| html! { h1 { "Hello World!" } }))
|
||||
.add_component(Html::with(move |_| html! { h1 { "Hello World!" } }))
|
||||
.render()
|
||||
}
|
||||
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue