♻️ Cambia en prepare_component() el tipo devuelto
Elimina `PrepareMarkup` como tipo de retorno de prepare_component() y de
`FnPrepareRender`, sustituyéndolo directamente por `Markup`. Se elimina
una capa innecesaria, ya que html! {} y html! { ... } cubren todos los
casos que ofrecía `PrepareMarkup`.
This commit is contained in:
parent
a5ee0fecb1
commit
3e1bc0fb0e
28 changed files with 241 additions and 335 deletions
|
|
@ -35,7 +35,7 @@ pub use all::dispatch_actions;
|
|||
/// impl Theme for MyTheme {}
|
||||
///
|
||||
/// fn before_render_button(c: &mut Button, cx: &mut Context) { todo!() }
|
||||
/// fn render_error404(c: &Error404, cx: &mut Context) -> PrepareMarkup { todo!() }
|
||||
/// fn render_error404(c: &Error404, cx: &mut Context) -> Markup { todo!() }
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! actions_boxed {
|
||||
|
|
|
|||
|
|
@ -38,8 +38,8 @@ pub use context::{Context, ContextError, ContextOp, Contextual};
|
|||
/// self.renderable.map_or(true, |f| f(cx))
|
||||
/// }
|
||||
///
|
||||
/// fn prepare_component(&self, _cx: &mut Context) -> PrepareMarkup {
|
||||
/// PrepareMarkup::Escaped("Visible component".into())
|
||||
/// fn prepare_component(&self, _cx: &mut Context) -> Markup {
|
||||
/// html! { "Visible component" }
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ use crate::{builder_fn, util, CowStr};
|
|||
|
||||
use std::any::Any;
|
||||
use std::collections::HashMap;
|
||||
use std::fmt;
|
||||
|
||||
/// Operaciones para modificar recursos asociados al [`Context`] de un documento.
|
||||
pub enum ContextOp {
|
||||
|
|
@ -45,6 +46,26 @@ pub enum ContextError {
|
|||
},
|
||||
}
|
||||
|
||||
impl fmt::Display for ContextError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
ContextError::ParamNotFound => {
|
||||
write!(f, "parameter not found")
|
||||
}
|
||||
ContextError::ParamTypeMismatch {
|
||||
key,
|
||||
expected,
|
||||
saved,
|
||||
} => write!(
|
||||
f,
|
||||
"type mismatch for parameter \"{key}\": expected \"{expected}\", found \"{saved}\""
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for ContextError {}
|
||||
|
||||
/// Interfaz para gestionar el **contexto de renderizado** de un documento HTML.
|
||||
///
|
||||
/// `Contextual` extiende [`LangId`] para establecer el idioma del documento y añade métodos para:
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use crate::base::action;
|
||||
use crate::core::component::Context;
|
||||
use crate::core::{AnyInfo, TypeInfo};
|
||||
use crate::html::{html, Markup, PrepareMarkup};
|
||||
use crate::html::{html, Markup};
|
||||
|
||||
/// Define la función de renderizado para todos los componentes.
|
||||
///
|
||||
|
|
@ -77,10 +77,10 @@ pub trait Component: AnyInfo + ComponentRender + Send + Sync {
|
|||
/// los campos de la estructura del componente. Es una forma de garantizar que los programadores
|
||||
/// podrán sobrescribir este método sin preocuparse por los detalles internos del componente.
|
||||
///
|
||||
/// Por defecto, devuelve [`PrepareMarkup::None`].
|
||||
/// Por defecto, devuelve un [`Markup`] vacío (`html! {}`).
|
||||
#[allow(unused_variables)]
|
||||
fn prepare_component(&self, cx: &mut Context) -> PrepareMarkup {
|
||||
PrepareMarkup::None
|
||||
fn prepare_component(&self, cx: &mut Context) -> Markup {
|
||||
html! {}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -137,6 +137,6 @@ impl<C: Component> ComponentRender for C {
|
|||
action::component::AfterRender::dispatch(self, cx);
|
||||
|
||||
// Devuelve el marcado final.
|
||||
prepare.render()
|
||||
prepare
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue