✨ Añade el primer componente básico nativo
Este componente renderiza directamente código HTML durante el renderizado del documento.
This commit is contained in:
parent
37df2ada75
commit
ed25a17e80
6 changed files with 40 additions and 7 deletions
|
@ -1,5 +1,7 @@
|
|||
//! Reúne acciones y temas listos para usar.
|
||||
//! Reúne acciones, componentes y temas listos para usar.
|
||||
|
||||
pub mod action;
|
||||
|
||||
pub mod component;
|
||||
|
||||
pub mod theme;
|
||||
|
|
4
src/base/component.rs
Normal file
4
src/base/component.rs
Normal file
|
@ -0,0 +1,4 @@
|
|||
//! Componentes nativos proporcionados por `PageTop`.
|
||||
|
||||
mod html;
|
||||
pub use html::Html;
|
28
src/base/component/html.rs
Normal file
28
src/base/component/html.rs
Normal file
|
@ -0,0 +1,28 @@
|
|||
use crate::prelude::*;
|
||||
|
||||
/// Componente básico para renderizar directamente código HTML.
|
||||
#[derive(AutoDefault)]
|
||||
pub struct Html(Markup);
|
||||
|
||||
impl ComponentTrait for Html {
|
||||
fn new() -> Self {
|
||||
Html::default()
|
||||
}
|
||||
|
||||
fn prepare_component(&self, _cx: &mut Context) -> PrepareMarkup {
|
||||
PrepareMarkup::With(html! { (self.0) })
|
||||
}
|
||||
}
|
||||
|
||||
impl Html {
|
||||
/// Crear una instancia con el código HTML del argumento.
|
||||
pub fn with(html: Markup) -> Self {
|
||||
Html(html)
|
||||
}
|
||||
|
||||
/// Modifica el código HTML de la instancia con el nuevo código del argumento.
|
||||
pub fn alter_html(&mut self, html: Markup) -> &mut Self {
|
||||
self.0 = html;
|
||||
self
|
||||
}
|
||||
}
|
|
@ -14,12 +14,10 @@ pub trait ComponentRender {
|
|||
/// Interfaz común que debe implementar un componente renderizable en `PageTop`.
|
||||
///
|
||||
/// Se recomienda que los componentes deriven [`AutoDefault`](crate::AutoDefault). También deben
|
||||
/// implementar el método [`new`](Self::new) y pueden sobrescribir los otros métodos para
|
||||
/// personalizar su comportamiento.
|
||||
/// implementar explícitamente el método [`new`](Self::new) y pueden sobrescribir los otros métodos
|
||||
/// para personalizar su comportamiento.
|
||||
pub trait ComponentTrait: AnyInfo + ComponentRender + Send + Sync {
|
||||
/// Crea una nueva instancia del componente.
|
||||
///
|
||||
/// Este método debe implementarse explícitamente.
|
||||
fn new() -> Self
|
||||
where
|
||||
Self: Sized;
|
||||
|
@ -53,7 +51,7 @@ pub trait ComponentTrait: AnyInfo + ComponentRender + Send + Sync {
|
|||
#[allow(unused_variables)]
|
||||
fn setup_before_prepare(&mut self, cx: &mut Context) {}
|
||||
|
||||
/// Devuelve la representación estructurada del componente lista para renderizar.
|
||||
/// Devuelve una representación estructurada del componente lista para renderizar.
|
||||
///
|
||||
/// Puede sobrescribirse para generar dinámicamente el contenido HTML. Por defecto, devuelve
|
||||
/// [`PrepareMarkup::None`].
|
||||
|
|
|
@ -96,7 +96,7 @@ pub mod datetime;
|
|||
pub mod core;
|
||||
// Gestión del servidor y servicios web.
|
||||
pub mod service;
|
||||
// Reúne acciones y temas listos para usar.
|
||||
// Reúne acciones, componentes y temas listos para usar.
|
||||
pub mod base;
|
||||
// Prepara y ejecuta la aplicación.
|
||||
pub mod app;
|
||||
|
|
|
@ -43,6 +43,7 @@ pub use crate::core::extension::*;
|
|||
pub use crate::core::theme::*;
|
||||
|
||||
pub use crate::base::action;
|
||||
pub use crate::base::component::*;
|
||||
pub use crate::base::theme;
|
||||
|
||||
pub use crate::app::Application;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue