💥 Impide prepare_component() renderizar en html!
This commit is contained in:
parent
b5606f043a
commit
9993b5975b
7 changed files with 40 additions and 24 deletions
|
|
@ -41,9 +41,9 @@ impl ComponentTrait for Block {
|
|||
run_actions_before_prepare_component(self, rcx);
|
||||
}
|
||||
|
||||
fn prepare_component(&self, rcx: &mut RenderContext) -> Markup {
|
||||
fn prepare_component(&self, rcx: &mut RenderContext) -> PrepareMarkup {
|
||||
let id = rcx.required_id::<Block>(self.id());
|
||||
html! {
|
||||
PrepareMarkup::With(html! {
|
||||
div id=(id) class=[self.classes().get()] {
|
||||
@if let Some(title) = self.title().get() {
|
||||
h2 class="block-title" { (title) }
|
||||
|
|
@ -52,7 +52,7 @@ impl ComponentTrait for Block {
|
|||
(self.components().prepare(rcx))
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn as_ref_any(&self) -> &dyn AnyComponent {
|
||||
|
|
|
|||
|
|
@ -14,8 +14,8 @@ impl ComponentTrait for Html {
|
|||
COMPONENT_HTML
|
||||
}
|
||||
|
||||
fn prepare_component(&self, _: &mut RenderContext) -> Markup {
|
||||
html! { (self.html()) }
|
||||
fn prepare_component(&self, _: &mut RenderContext) -> PrepareMarkup {
|
||||
PrepareMarkup::With(html! { (self.html()) })
|
||||
}
|
||||
|
||||
fn as_ref_any(&self) -> &dyn AnyComponent {
|
||||
|
|
|
|||
|
|
@ -28,11 +28,11 @@ impl ComponentTrait for L10n {
|
|||
COMPONENT_L10N
|
||||
}
|
||||
|
||||
fn prepare_component(&self, rcx: &mut RenderContext) -> Markup {
|
||||
fn prepare_component(&self, rcx: &mut RenderContext) -> PrepareMarkup {
|
||||
match self.op() {
|
||||
L10nOp::None => html! {},
|
||||
L10nOp::Text(text) => html! { (text) },
|
||||
L10nOp::Translated(key, locales) => html! {
|
||||
L10nOp::None => PrepareMarkup::None,
|
||||
L10nOp::Text(text) => PrepareMarkup::Text(text),
|
||||
L10nOp::Translated(key, locales) => PrepareMarkup::With(html! {
|
||||
(locales
|
||||
.lookup_with_args(
|
||||
rcx.langid(),
|
||||
|
|
@ -44,8 +44,8 @@ impl ComponentTrait for L10n {
|
|||
)
|
||||
.unwrap_or(key.to_string())
|
||||
)
|
||||
},
|
||||
L10nOp::Escaped(key, locales) => html! {
|
||||
}),
|
||||
L10nOp::Escaped(key, locales) => PrepareMarkup::With(html! {
|
||||
(PreEscaped(locales
|
||||
.lookup_with_args(
|
||||
rcx.langid(),
|
||||
|
|
@ -57,7 +57,7 @@ impl ComponentTrait for L10n {
|
|||
)
|
||||
.unwrap_or(key.to_string())
|
||||
))
|
||||
},
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use crate::core::component::RenderContext;
|
||||
use crate::html::{html, Markup};
|
||||
use crate::html::{html, Markup, PrepareMarkup};
|
||||
use crate::{util, Handle};
|
||||
|
||||
pub use std::any::Any as AnyComponent;
|
||||
|
|
@ -40,8 +40,8 @@ pub trait ComponentTrait: AnyComponent + BaseComponent + Send + Sync {
|
|||
fn before_prepare(&mut self, rcx: &mut RenderContext) {}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn prepare_component(&self, rcx: &mut RenderContext) -> Markup {
|
||||
html! {}
|
||||
fn prepare_component(&self, rcx: &mut RenderContext) -> PrepareMarkup {
|
||||
PrepareMarkup::None
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
|
|
@ -63,7 +63,7 @@ impl<C: ComponentTrait> BaseComponent for C {
|
|||
|
||||
let markup = match rcx.theme().render_component(self, rcx) {
|
||||
Some(html) => html,
|
||||
None => self.prepare_component(rcx),
|
||||
None => self.prepare_component(rcx).html(),
|
||||
};
|
||||
|
||||
// Acciones después de preparar el componente.
|
||||
|
|
|
|||
|
|
@ -22,3 +22,19 @@ pub use attribute::AttributeValue;
|
|||
|
||||
mod classes;
|
||||
pub use classes::{Classes, ClassesOp};
|
||||
|
||||
pub enum PrepareMarkup {
|
||||
None,
|
||||
Text(&'static str),
|
||||
With(Markup),
|
||||
}
|
||||
|
||||
impl PrepareMarkup {
|
||||
pub fn html(self) -> Markup {
|
||||
match self {
|
||||
PrepareMarkup::None => html! {},
|
||||
PrepareMarkup::Text(text) => html! { (text) },
|
||||
PrepareMarkup::With(markup) => markup,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use crate::core::component::{AnyComponent, ComponentTrait, RenderContext};
|
||||
use crate::html::{html, Markup};
|
||||
use crate::html::{html, PrepareMarkup};
|
||||
use crate::{use_handle, Handle};
|
||||
|
||||
use_handle!(ERROR_403);
|
||||
|
|
@ -15,12 +15,12 @@ impl ComponentTrait for Error403 {
|
|||
ERROR_403
|
||||
}
|
||||
|
||||
fn prepare_component(&self, _rcx: &mut RenderContext) -> Markup {
|
||||
html! {
|
||||
fn prepare_component(&self, _rcx: &mut RenderContext) -> PrepareMarkup {
|
||||
PrepareMarkup::With(html! {
|
||||
div {
|
||||
h1 { ("FORBIDDEN ACCESS") }
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn as_ref_any(&self) -> &dyn AnyComponent {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use crate::core::component::{AnyComponent, ComponentTrait, RenderContext};
|
||||
use crate::html::{html, Markup};
|
||||
use crate::html::{html, PrepareMarkup};
|
||||
use crate::{use_handle, Handle};
|
||||
|
||||
use_handle!(ERROR_404);
|
||||
|
|
@ -15,12 +15,12 @@ impl ComponentTrait for Error404 {
|
|||
ERROR_404
|
||||
}
|
||||
|
||||
fn prepare_component(&self, _rcx: &mut RenderContext) -> Markup {
|
||||
html! {
|
||||
fn prepare_component(&self, _rcx: &mut RenderContext) -> PrepareMarkup {
|
||||
PrepareMarkup::With(html! {
|
||||
div {
|
||||
h1 { ("RESOURCE NOT FOUND") }
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn as_ref_any(&self) -> &dyn AnyComponent {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue