🏷️ Simplifica nombres de traits esenciales
Los traits `ExtensionTrait`, `ThemeTrait` y `ComponentTrait` pasan a ser `Extension`, `Theme`y `Component`, respectivamente,
This commit is contained in:
parent
ac0889cb8c
commit
bf3ea43b53
23 changed files with 78 additions and 79 deletions
|
@ -101,7 +101,7 @@
|
||||||
//!
|
//!
|
||||||
//! pub struct MyExtension;
|
//! pub struct MyExtension;
|
||||||
//!
|
//!
|
||||||
//! impl ExtensionTrait for MyExtension {
|
//! impl Extension for MyExtension {
|
||||||
//! // Servicio web que publica los recursos de `guides` en `/ruta/a/guides`.
|
//! // Servicio web que publica los recursos de `guides` en `/ruta/a/guides`.
|
||||||
//! fn configure_service(&self, scfg: &mut service::web::ServiceConfig) {
|
//! fn configure_service(&self, scfg: &mut service::web::ServiceConfig) {
|
||||||
//! include_files_service!(scfg, guides => "/ruta/a/guides");
|
//! include_files_service!(scfg, guides => "/ruta/a/guides");
|
||||||
|
|
|
@ -3,7 +3,7 @@ use crate::prelude::*;
|
||||||
use crate::base::action::FnActionWithComponent;
|
use crate::base::action::FnActionWithComponent;
|
||||||
|
|
||||||
/// Ejecuta [`FnActionWithComponent`] después de renderizar un componente.
|
/// Ejecuta [`FnActionWithComponent`] después de renderizar un componente.
|
||||||
pub struct AfterRender<C: ComponentTrait> {
|
pub struct AfterRender<C: Component> {
|
||||||
f: FnActionWithComponent<C>,
|
f: FnActionWithComponent<C>,
|
||||||
referer_type_id: Option<UniqueId>,
|
referer_type_id: Option<UniqueId>,
|
||||||
referer_id: OptionId,
|
referer_id: OptionId,
|
||||||
|
@ -11,7 +11,7 @@ pub struct AfterRender<C: ComponentTrait> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Filtro para despachar [`FnActionWithComponent`] después de renderizar un componente `C`.
|
/// Filtro para despachar [`FnActionWithComponent`] después de renderizar un componente `C`.
|
||||||
impl<C: ComponentTrait> ActionDispatcher for AfterRender<C> {
|
impl<C: Component> ActionDispatcher for AfterRender<C> {
|
||||||
/// Devuelve el identificador de tipo ([`UniqueId`]) del componente `C`.
|
/// Devuelve el identificador de tipo ([`UniqueId`]) del componente `C`.
|
||||||
fn referer_type_id(&self) -> Option<UniqueId> {
|
fn referer_type_id(&self) -> Option<UniqueId> {
|
||||||
self.referer_type_id
|
self.referer_type_id
|
||||||
|
@ -28,8 +28,8 @@ impl<C: ComponentTrait> ActionDispatcher for AfterRender<C> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<C: ComponentTrait> AfterRender<C> {
|
impl<C: Component> AfterRender<C> {
|
||||||
/// Permite [registrar](ExtensionTrait::actions) una nueva acción [`FnActionWithComponent`].
|
/// Permite [registrar](Extension::actions) una nueva acción [`FnActionWithComponent`].
|
||||||
pub fn new(f: FnActionWithComponent<C>) -> Self {
|
pub fn new(f: FnActionWithComponent<C>) -> Self {
|
||||||
AfterRender {
|
AfterRender {
|
||||||
f,
|
f,
|
||||||
|
|
|
@ -3,7 +3,7 @@ use crate::prelude::*;
|
||||||
use crate::base::action::FnActionWithComponent;
|
use crate::base::action::FnActionWithComponent;
|
||||||
|
|
||||||
/// Ejecuta [`FnActionWithComponent`] antes de renderizar el componente.
|
/// Ejecuta [`FnActionWithComponent`] antes de renderizar el componente.
|
||||||
pub struct BeforeRender<C: ComponentTrait> {
|
pub struct BeforeRender<C: Component> {
|
||||||
f: FnActionWithComponent<C>,
|
f: FnActionWithComponent<C>,
|
||||||
referer_type_id: Option<UniqueId>,
|
referer_type_id: Option<UniqueId>,
|
||||||
referer_id: OptionId,
|
referer_id: OptionId,
|
||||||
|
@ -11,7 +11,7 @@ pub struct BeforeRender<C: ComponentTrait> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Filtro para despachar [`FnActionWithComponent`] antes de renderizar un componente `C`.
|
/// Filtro para despachar [`FnActionWithComponent`] antes de renderizar un componente `C`.
|
||||||
impl<C: ComponentTrait> ActionDispatcher for BeforeRender<C> {
|
impl<C: Component> ActionDispatcher for BeforeRender<C> {
|
||||||
/// Devuelve el identificador de tipo ([`UniqueId`]) del componente `C`.
|
/// Devuelve el identificador de tipo ([`UniqueId`]) del componente `C`.
|
||||||
fn referer_type_id(&self) -> Option<UniqueId> {
|
fn referer_type_id(&self) -> Option<UniqueId> {
|
||||||
self.referer_type_id
|
self.referer_type_id
|
||||||
|
@ -28,8 +28,8 @@ impl<C: ComponentTrait> ActionDispatcher for BeforeRender<C> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<C: ComponentTrait> BeforeRender<C> {
|
impl<C: Component> BeforeRender<C> {
|
||||||
/// Permite [registrar](ExtensionTrait::actions) una nueva acción [`FnActionWithComponent`].
|
/// Permite [registrar](Extension::actions) una nueva acción [`FnActionWithComponent`].
|
||||||
pub fn new(f: FnActionWithComponent<C>) -> Self {
|
pub fn new(f: FnActionWithComponent<C>) -> Self {
|
||||||
BeforeRender {
|
BeforeRender {
|
||||||
f,
|
f,
|
||||||
|
|
|
@ -8,7 +8,7 @@ use crate::prelude::*;
|
||||||
pub type FnIsRenderable<C> = fn(component: &C, cx: &Context) -> bool;
|
pub type FnIsRenderable<C> = fn(component: &C, cx: &Context) -> bool;
|
||||||
|
|
||||||
/// Con la función [`FnIsRenderable`] se puede decidir si se renderiza o no un componente.
|
/// Con la función [`FnIsRenderable`] se puede decidir si se renderiza o no un componente.
|
||||||
pub struct IsRenderable<C: ComponentTrait> {
|
pub struct IsRenderable<C: Component> {
|
||||||
f: FnIsRenderable<C>,
|
f: FnIsRenderable<C>,
|
||||||
referer_type_id: Option<UniqueId>,
|
referer_type_id: Option<UniqueId>,
|
||||||
referer_id: OptionId,
|
referer_id: OptionId,
|
||||||
|
@ -16,7 +16,7 @@ pub struct IsRenderable<C: ComponentTrait> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Filtro para despachar [`FnIsRenderable`] para decidir si se renderiza o no un componente `C`.
|
/// Filtro para despachar [`FnIsRenderable`] para decidir si se renderiza o no un componente `C`.
|
||||||
impl<C: ComponentTrait> ActionDispatcher for IsRenderable<C> {
|
impl<C: Component> ActionDispatcher for IsRenderable<C> {
|
||||||
/// Devuelve el identificador de tipo ([`UniqueId`]) del componente `C`.
|
/// Devuelve el identificador de tipo ([`UniqueId`]) del componente `C`.
|
||||||
fn referer_type_id(&self) -> Option<UniqueId> {
|
fn referer_type_id(&self) -> Option<UniqueId> {
|
||||||
self.referer_type_id
|
self.referer_type_id
|
||||||
|
@ -33,8 +33,8 @@ impl<C: ComponentTrait> ActionDispatcher for IsRenderable<C> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<C: ComponentTrait> IsRenderable<C> {
|
impl<C: Component> IsRenderable<C> {
|
||||||
/// Permite [registrar](ExtensionTrait::actions) una nueva acción [`FnIsRenderable`].
|
/// Permite [registrar](Extension::actions) una nueva acción [`FnIsRenderable`].
|
||||||
pub fn new(f: FnIsRenderable<C>) -> Self {
|
pub fn new(f: FnIsRenderable<C>) -> Self {
|
||||||
IsRenderable {
|
IsRenderable {
|
||||||
f,
|
f,
|
||||||
|
|
|
@ -22,7 +22,7 @@ impl ActionDispatcher for AfterRenderBody {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AfterRenderBody {
|
impl AfterRenderBody {
|
||||||
/// Permite [registrar](ExtensionTrait::actions) una nueva acción
|
/// Permite [registrar](Extension::actions) una nueva acción
|
||||||
/// [`FnActionWithPage`](crate::base::action::page::FnActionWithPage).
|
/// [`FnActionWithPage`](crate::base::action::page::FnActionWithPage).
|
||||||
pub fn new(f: FnActionWithPage) -> Self {
|
pub fn new(f: FnActionWithPage) -> Self {
|
||||||
AfterRenderBody { f, weight: 0 }
|
AfterRenderBody { f, weight: 0 }
|
||||||
|
|
|
@ -22,7 +22,7 @@ impl ActionDispatcher for BeforeRenderBody {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BeforeRenderBody {
|
impl BeforeRenderBody {
|
||||||
/// Permite [registrar](ExtensionTrait::actions) una nueva acción
|
/// Permite [registrar](Extension::actions) una nueva acción
|
||||||
/// [`FnActionWithPage`](crate::base::action::page::FnActionWithPage).
|
/// [`FnActionWithPage`](crate::base::action::page::FnActionWithPage).
|
||||||
pub fn new(f: FnActionWithPage) -> Self {
|
pub fn new(f: FnActionWithPage) -> Self {
|
||||||
BeforeRenderBody { f, weight: 0 }
|
BeforeRenderBody { f, weight: 0 }
|
||||||
|
|
|
@ -3,7 +3,7 @@ use crate::prelude::*;
|
||||||
use crate::base::action::FnActionWithComponent;
|
use crate::base::action::FnActionWithComponent;
|
||||||
|
|
||||||
/// Ejecuta [`FnActionWithComponent`] después de que un tema renderice el componente.
|
/// Ejecuta [`FnActionWithComponent`] después de que un tema renderice el componente.
|
||||||
pub struct AfterRender<C: ComponentTrait> {
|
pub struct AfterRender<C: Component> {
|
||||||
f: FnActionWithComponent<C>,
|
f: FnActionWithComponent<C>,
|
||||||
theme_type_id: Option<UniqueId>,
|
theme_type_id: Option<UniqueId>,
|
||||||
referer_type_id: Option<UniqueId>,
|
referer_type_id: Option<UniqueId>,
|
||||||
|
@ -11,7 +11,7 @@ pub struct AfterRender<C: ComponentTrait> {
|
||||||
|
|
||||||
/// Filtro para despachar [`FnActionWithComponent`] después de que un tema renderice el componente
|
/// Filtro para despachar [`FnActionWithComponent`] después de que un tema renderice el componente
|
||||||
/// `C`.
|
/// `C`.
|
||||||
impl<C: ComponentTrait> ActionDispatcher for AfterRender<C> {
|
impl<C: Component> ActionDispatcher for AfterRender<C> {
|
||||||
/// Devuelve el identificador de tipo ([`UniqueId`]) del tema.
|
/// Devuelve el identificador de tipo ([`UniqueId`]) del tema.
|
||||||
fn theme_type_id(&self) -> Option<UniqueId> {
|
fn theme_type_id(&self) -> Option<UniqueId> {
|
||||||
self.theme_type_id
|
self.theme_type_id
|
||||||
|
@ -23,9 +23,9 @@ impl<C: ComponentTrait> ActionDispatcher for AfterRender<C> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<C: ComponentTrait> AfterRender<C> {
|
impl<C: Component> AfterRender<C> {
|
||||||
/// Permite [registrar](ExtensionTrait::actions) una nueva acción [`FnActionWithComponent`] para
|
/// Permite [registrar](Extension::actions) una nueva acción [`FnActionWithComponent`] para un
|
||||||
/// un tema dado.
|
/// tema dado.
|
||||||
pub fn new(theme: ThemeRef, f: FnActionWithComponent<C>) -> Self {
|
pub fn new(theme: ThemeRef, f: FnActionWithComponent<C>) -> Self {
|
||||||
AfterRender {
|
AfterRender {
|
||||||
f,
|
f,
|
||||||
|
|
|
@ -3,7 +3,7 @@ use crate::prelude::*;
|
||||||
use crate::base::action::FnActionWithComponent;
|
use crate::base::action::FnActionWithComponent;
|
||||||
|
|
||||||
/// Ejecuta [`FnActionWithComponent`] antes de que un tema renderice el componente.
|
/// Ejecuta [`FnActionWithComponent`] antes de que un tema renderice el componente.
|
||||||
pub struct BeforeRender<C: ComponentTrait> {
|
pub struct BeforeRender<C: Component> {
|
||||||
f: FnActionWithComponent<C>,
|
f: FnActionWithComponent<C>,
|
||||||
theme_type_id: Option<UniqueId>,
|
theme_type_id: Option<UniqueId>,
|
||||||
referer_type_id: Option<UniqueId>,
|
referer_type_id: Option<UniqueId>,
|
||||||
|
@ -11,7 +11,7 @@ pub struct BeforeRender<C: ComponentTrait> {
|
||||||
|
|
||||||
/// Filtro para despachar [`FnActionWithComponent`] antes de que un tema renderice el componente
|
/// Filtro para despachar [`FnActionWithComponent`] antes de que un tema renderice el componente
|
||||||
/// `C`.
|
/// `C`.
|
||||||
impl<C: ComponentTrait> ActionDispatcher for BeforeRender<C> {
|
impl<C: Component> ActionDispatcher for BeforeRender<C> {
|
||||||
/// Devuelve el identificador de tipo ([`UniqueId`]) del tema.
|
/// Devuelve el identificador de tipo ([`UniqueId`]) del tema.
|
||||||
fn theme_type_id(&self) -> Option<UniqueId> {
|
fn theme_type_id(&self) -> Option<UniqueId> {
|
||||||
self.theme_type_id
|
self.theme_type_id
|
||||||
|
@ -23,9 +23,9 @@ impl<C: ComponentTrait> ActionDispatcher for BeforeRender<C> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<C: ComponentTrait> BeforeRender<C> {
|
impl<C: Component> BeforeRender<C> {
|
||||||
/// Permite [registrar](ExtensionTrait::actions) una nueva acción [`FnActionWithComponent`] para
|
/// Permite [registrar](Extension::actions) una nueva acción [`FnActionWithComponent`] para un
|
||||||
/// un tema dado.
|
/// tema dado.
|
||||||
pub fn new(theme: ThemeRef, f: FnActionWithComponent<C>) -> Self {
|
pub fn new(theme: ThemeRef, f: FnActionWithComponent<C>) -> Self {
|
||||||
BeforeRender {
|
BeforeRender {
|
||||||
f,
|
f,
|
||||||
|
|
|
@ -11,14 +11,14 @@ pub type FnPrepareRender<C> = fn(component: &C, cx: &mut Context) -> PrepareMark
|
||||||
/// Ejecuta [`FnPrepareRender`] para preparar el renderizado de un componente.
|
/// Ejecuta [`FnPrepareRender`] para preparar el renderizado de un componente.
|
||||||
///
|
///
|
||||||
/// Permite a un tema hacer una implementación nueva del renderizado de un componente.
|
/// Permite a un tema hacer una implementación nueva del renderizado de un componente.
|
||||||
pub struct PrepareRender<C: ComponentTrait> {
|
pub struct PrepareRender<C: Component> {
|
||||||
f: FnPrepareRender<C>,
|
f: FnPrepareRender<C>,
|
||||||
theme_type_id: Option<UniqueId>,
|
theme_type_id: Option<UniqueId>,
|
||||||
referer_type_id: Option<UniqueId>,
|
referer_type_id: Option<UniqueId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Filtro para despachar [`FnPrepareRender`] que modifica el renderizado de un componente `C`.
|
/// Filtro para despachar [`FnPrepareRender`] que modifica el renderizado de un componente `C`.
|
||||||
impl<C: ComponentTrait> ActionDispatcher for PrepareRender<C> {
|
impl<C: Component> ActionDispatcher for PrepareRender<C> {
|
||||||
/// Devuelve el identificador de tipo ([`UniqueId`]) del tema.
|
/// Devuelve el identificador de tipo ([`UniqueId`]) del tema.
|
||||||
fn theme_type_id(&self) -> Option<UniqueId> {
|
fn theme_type_id(&self) -> Option<UniqueId> {
|
||||||
self.theme_type_id
|
self.theme_type_id
|
||||||
|
@ -30,9 +30,9 @@ impl<C: ComponentTrait> ActionDispatcher for PrepareRender<C> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<C: ComponentTrait> PrepareRender<C> {
|
impl<C: Component> PrepareRender<C> {
|
||||||
/// Permite [registrar](ExtensionTrait::actions) una nueva acción [`FnPrepareRender`] para un
|
/// Permite [registrar](Extension::actions) una nueva acción [`FnPrepareRender`] para un tema
|
||||||
/// tema dado.
|
/// dado.
|
||||||
pub fn new(theme: ThemeRef, f: FnPrepareRender<C>) -> Self {
|
pub fn new(theme: ThemeRef, f: FnPrepareRender<C>) -> Self {
|
||||||
PrepareRender {
|
PrepareRender {
|
||||||
f,
|
f,
|
||||||
|
|
|
@ -38,7 +38,7 @@ impl Default for Html {
|
||||||
Html::with(|_| html! {})
|
Html::with(|_| html! {})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl ComponentTrait for Html {
|
impl Component for Html {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
Html::default()
|
Html::default()
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ use crate::prelude::*;
|
||||||
/// funcionando correctamente.
|
/// funcionando correctamente.
|
||||||
pub struct Welcome;
|
pub struct Welcome;
|
||||||
|
|
||||||
impl ExtensionTrait for Welcome {
|
impl Extension for Welcome {
|
||||||
fn name(&self) -> L10n {
|
fn name(&self) -> L10n {
|
||||||
L10n::l("welcome_extension_name")
|
L10n::l("welcome_extension_name")
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,13 +5,13 @@ use crate::prelude::*;
|
||||||
/// Tema básico por defecto.
|
/// Tema básico por defecto.
|
||||||
pub struct Basic;
|
pub struct Basic;
|
||||||
|
|
||||||
impl ExtensionTrait for Basic {
|
impl Extension for Basic {
|
||||||
fn theme(&self) -> Option<ThemeRef> {
|
fn theme(&self) -> Option<ThemeRef> {
|
||||||
Some(&Self)
|
Some(&Self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ThemeTrait for Basic {
|
impl Theme for Basic {
|
||||||
fn after_render_page_body(&self, page: &mut Page) {
|
fn after_render_page_body(&self, page: &mut Page) {
|
||||||
page.alter_assets(AssetsOp::AddStyleSheet(
|
page.alter_assets(AssetsOp::AddStyleSheet(
|
||||||
StyleSheet::from("/css/normalize.css")
|
StyleSheet::from("/css/normalize.css")
|
||||||
|
|
|
@ -25,7 +25,7 @@ pub use all::dispatch_actions;
|
||||||
/// ```rust,ignore
|
/// ```rust,ignore
|
||||||
/// use pagetop::prelude::*;
|
/// use pagetop::prelude::*;
|
||||||
///
|
///
|
||||||
/// impl ExtensionTrait for MyTheme {
|
/// impl Extension for MyTheme {
|
||||||
/// fn actions(&self) -> Vec<ActionBox> {
|
/// fn actions(&self) -> Vec<ActionBox> {
|
||||||
/// actions_boxed![
|
/// actions_boxed![
|
||||||
/// action::theme::BeforeRender::<Button>::new(&Self, before_render_button),
|
/// action::theme::BeforeRender::<Button>::new(&Self, before_render_button),
|
||||||
|
@ -34,7 +34,7 @@ pub use all::dispatch_actions;
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// impl ThemeTrait for MyTheme {}
|
/// impl Theme for MyTheme {}
|
||||||
///
|
///
|
||||||
/// fn before_render_button(c: &mut Button, cx: &mut Context) { todo!() }
|
/// 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) -> PrepareMarkup { todo!() }
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//! API para construir nuevos componentes.
|
//! API para construir nuevos componentes.
|
||||||
|
|
||||||
mod definition;
|
mod definition;
|
||||||
pub use definition::{ComponentRender, ComponentTrait};
|
pub use definition::{Component, ComponentRender};
|
||||||
|
|
||||||
mod children;
|
mod children;
|
||||||
pub use children::Children;
|
pub use children::Children;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::core::component::ComponentTrait;
|
use crate::core::component::Component;
|
||||||
use crate::html::{html, Context, Markup};
|
use crate::html::{html, Context, Markup};
|
||||||
use crate::{builder_fn, UniqueId};
|
use crate::{builder_fn, UniqueId};
|
||||||
|
|
||||||
|
@ -9,14 +9,14 @@ use std::vec::IntoIter;
|
||||||
|
|
||||||
/// Representa un componente encapsulado de forma segura y compartida.
|
/// Representa un componente encapsulado de forma segura y compartida.
|
||||||
///
|
///
|
||||||
/// Esta estructura permite manipular y renderizar cualquier tipo que implemente [`ComponentTrait`],
|
/// Esta estructura permite manipular y renderizar cualquier tipo que implemente [`Component`],
|
||||||
/// garantizando acceso concurrente a través de [`Arc<RwLock<_>>`].
|
/// garantizando acceso concurrente a través de [`Arc<RwLock<_>>`].
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Child(Arc<RwLock<dyn ComponentTrait>>);
|
pub struct Child(Arc<RwLock<dyn Component>>);
|
||||||
|
|
||||||
impl Child {
|
impl Child {
|
||||||
/// Crea un nuevo [`Child`] a partir de un componente.
|
/// Crea un nuevo [`Child`] a partir de un componente.
|
||||||
pub fn with(component: impl ComponentTrait) -> Self {
|
pub fn with(component: impl Component) -> Self {
|
||||||
Child(Arc::new(RwLock::new(component)))
|
Child(Arc::new(RwLock::new(component)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,15 +47,15 @@ impl Child {
|
||||||
/// Variante tipada de [`Child`] para evitar conversiones durante el uso.
|
/// Variante tipada de [`Child`] para evitar conversiones durante el uso.
|
||||||
///
|
///
|
||||||
/// Facilita el acceso a componentes del mismo tipo sin necesidad de hacer `downcast`.
|
/// Facilita el acceso a componentes del mismo tipo sin necesidad de hacer `downcast`.
|
||||||
pub struct Typed<C: ComponentTrait>(Arc<RwLock<C>>);
|
pub struct Typed<C: Component>(Arc<RwLock<C>>);
|
||||||
|
|
||||||
impl<C: ComponentTrait> Clone for Typed<C> {
|
impl<C: Component> Clone for Typed<C> {
|
||||||
fn clone(&self) -> Self {
|
fn clone(&self) -> Self {
|
||||||
Self(self.0.clone())
|
Self(self.0.clone())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<C: ComponentTrait> Typed<C> {
|
impl<C: Component> Typed<C> {
|
||||||
/// Crea un nuevo [`Typed`] a partir de un componente.
|
/// Crea un nuevo [`Typed`] a partir de un componente.
|
||||||
pub fn with(component: C) -> Self {
|
pub fn with(component: C) -> Self {
|
||||||
Typed(Arc::new(RwLock::new(component)))
|
Typed(Arc::new(RwLock::new(component)))
|
||||||
|
@ -97,7 +97,7 @@ pub enum ChildOp {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Operaciones con un componente hijo tipado [`Typed<C>`] en una lista [`Children`].
|
/// Operaciones con un componente hijo tipado [`Typed<C>`] en una lista [`Children`].
|
||||||
pub enum TypedOp<C: ComponentTrait> {
|
pub enum TypedOp<C: Component> {
|
||||||
Add(Typed<C>),
|
Add(Typed<C>),
|
||||||
InsertAfterId(&'static str, Typed<C>),
|
InsertAfterId(&'static str, Typed<C>),
|
||||||
InsertBeforeId(&'static str, Typed<C>),
|
InsertBeforeId(&'static str, Typed<C>),
|
||||||
|
@ -153,7 +153,7 @@ impl Children {
|
||||||
|
|
||||||
/// Ejecuta una operación con [`TypedOp`] en la lista.
|
/// Ejecuta una operación con [`TypedOp`] en la lista.
|
||||||
#[builder_fn]
|
#[builder_fn]
|
||||||
pub fn with_typed<C: ComponentTrait + Default>(mut self, op: TypedOp<C>) -> Self {
|
pub fn with_typed<C: Component + Default>(mut self, op: TypedOp<C>) -> Self {
|
||||||
match op {
|
match op {
|
||||||
TypedOp::Add(typed) => self.add(typed.into_child()),
|
TypedOp::Add(typed) => self.add(typed.into_child()),
|
||||||
TypedOp::InsertAfterId(id, typed) => self.insert_after_id(id, typed.into_child()),
|
TypedOp::InsertAfterId(id, typed) => self.insert_after_id(id, typed.into_child()),
|
||||||
|
|
|
@ -5,7 +5,7 @@ use crate::html::{html, Context, Markup, PrepareMarkup, Render};
|
||||||
/// Define la función de renderizado para todos los componentes.
|
/// Define la función de renderizado para todos los componentes.
|
||||||
///
|
///
|
||||||
/// Este *trait* se implementa automáticamente en cualquier tipo (componente) que implemente
|
/// Este *trait* se implementa automáticamente en cualquier tipo (componente) que implemente
|
||||||
/// [`ComponentTrait`], por lo que no requiere ninguna codificación manual.
|
/// [`Component`], por lo que no requiere ninguna codificación manual.
|
||||||
pub trait ComponentRender {
|
pub trait ComponentRender {
|
||||||
/// Renderiza el componente usando el contexto proporcionado.
|
/// Renderiza el componente usando el contexto proporcionado.
|
||||||
fn render(&mut self, cx: &mut Context) -> Markup;
|
fn render(&mut self, cx: &mut Context) -> Markup;
|
||||||
|
@ -86,7 +86,7 @@ pub trait ComponentTrait: AnyInfo + ComponentRender + Send + Sync {
|
||||||
/// 7. Despacha [`action::component::AfterRender<C>`](crate::base::action::component::AfterRender)
|
/// 7. Despacha [`action::component::AfterRender<C>`](crate::base::action::component::AfterRender)
|
||||||
/// para que otras extensiones puedan hacer sus últimos ajustes.
|
/// para que otras extensiones puedan hacer sus últimos ajustes.
|
||||||
/// 8. Finalmente devuelve un [`Markup`] del renderizado preparado en el paso 5.
|
/// 8. Finalmente devuelve un [`Markup`] del renderizado preparado en el paso 5.
|
||||||
impl<C: ComponentTrait> ComponentRender for C {
|
impl<C: Component> ComponentRender for C {
|
||||||
fn render(&mut self, cx: &mut Context) -> Markup {
|
fn render(&mut self, cx: &mut Context) -> Markup {
|
||||||
// Si no es renderizable, devuelve un bloque HTML vacío.
|
// Si no es renderizable, devuelve un bloque HTML vacío.
|
||||||
if !action::component::IsRenderable::dispatch(self, cx) {
|
if !action::component::IsRenderable::dispatch(self, cx) {
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
//! API para añadir nuevas funcionalidades usando extensiones.
|
//! API para añadir nuevas funcionalidades usando extensiones.
|
||||||
//!
|
//!
|
||||||
//! Cada funcionalidad adicional que quiera incorporarse a una aplicación `PageTop` se debe modelar
|
//! Cada funcionalidad adicional que quiera incorporarse a una aplicación `PageTop` se debe modelar
|
||||||
//! como una **extensión**. Todas comparten la misma interfaz declarada en [`ExtensionTrait`].
|
//! como una **extensión**. Todas comparten la misma interfaz declarada en [`Extension`].
|
||||||
|
|
||||||
mod definition;
|
mod definition;
|
||||||
pub use definition::{ExtensionRef, ExtensionTrait};
|
pub use definition::{Extension, ExtensionRef};
|
||||||
|
|
||||||
pub(crate) mod all;
|
pub(crate) mod all;
|
||||||
|
|
|
@ -8,7 +8,7 @@ use crate::{actions_boxed, service};
|
||||||
///
|
///
|
||||||
/// Las extensiones se definen como instancias estáticas globales para poder acceder a ellas desde
|
/// Las extensiones se definen como instancias estáticas globales para poder acceder a ellas desde
|
||||||
/// cualquier hilo de la ejecución sin necesidad de sincronización adicional.
|
/// cualquier hilo de la ejecución sin necesidad de sincronización adicional.
|
||||||
pub type ExtensionRef = &'static dyn ExtensionTrait;
|
pub type ExtensionRef = &'static dyn Extension;
|
||||||
|
|
||||||
/// Interfaz común que debe implementar cualquier extensión de `PageTop`.
|
/// Interfaz común que debe implementar cualquier extensión de `PageTop`.
|
||||||
///
|
///
|
||||||
|
@ -20,12 +20,12 @@ pub type ExtensionRef = &'static dyn ExtensionTrait;
|
||||||
///
|
///
|
||||||
/// pub struct Blog;
|
/// pub struct Blog;
|
||||||
///
|
///
|
||||||
/// impl ExtensionTrait for Blog {
|
/// impl Extension for Blog {
|
||||||
/// fn name(&self) -> L10n { L10n::n("Blog") }
|
/// fn name(&self) -> L10n { L10n::n("Blog") }
|
||||||
/// fn description(&self) -> L10n { L10n::n("Sistema de blogs") }
|
/// fn description(&self) -> L10n { L10n::n("Sistema de blogs") }
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub trait ExtensionTrait: AnyInfo + Send + Sync {
|
pub trait Extension: AnyInfo + Send + Sync {
|
||||||
/// Nombre legible para el usuario.
|
/// Nombre legible para el usuario.
|
||||||
///
|
///
|
||||||
/// Predeterminado por el [`short_name`](AnyInfo::short_name) del tipo asociado a la extensión.
|
/// Predeterminado por el [`short_name`](AnyInfo::short_name) del tipo asociado a la extensión.
|
||||||
|
@ -38,8 +38,8 @@ pub trait ExtensionTrait: AnyInfo + Send + Sync {
|
||||||
L10n::default()
|
L10n::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Los temas son extensiones que implementan [`ExtensionTrait`] y también
|
/// Los temas son extensiones que implementan [`Extension`] y también
|
||||||
/// [`ThemeTrait`](crate::core::theme::ThemeTrait).
|
/// [`Theme`](crate::core::theme::Theme).
|
||||||
///
|
///
|
||||||
/// Si la extensión no es un tema, este método devuelve `None` por defecto.
|
/// Si la extensión no es un tema, este método devuelve `None` por defecto.
|
||||||
///
|
///
|
||||||
|
@ -51,13 +51,13 @@ pub trait ExtensionTrait: AnyInfo + Send + Sync {
|
||||||
///
|
///
|
||||||
/// pub struct MyTheme;
|
/// pub struct MyTheme;
|
||||||
///
|
///
|
||||||
/// impl ExtensionTrait for MyTheme {
|
/// impl Extension for MyTheme {
|
||||||
/// fn theme(&self) -> Option<ThemeRef> {
|
/// fn theme(&self) -> Option<ThemeRef> {
|
||||||
/// Some(&Self)
|
/// Some(&Self)
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// impl ThemeTrait for MyTheme {}
|
/// impl Theme for MyTheme {}
|
||||||
/// ```
|
/// ```
|
||||||
fn theme(&self) -> Option<ThemeRef> {
|
fn theme(&self) -> Option<ThemeRef> {
|
||||||
None
|
None
|
||||||
|
@ -94,7 +94,7 @@ pub trait ExtensionTrait: AnyInfo + Send + Sync {
|
||||||
///
|
///
|
||||||
/// pub struct ExtensionSample;
|
/// pub struct ExtensionSample;
|
||||||
///
|
///
|
||||||
/// impl ExtensionTrait for ExtensionSample {
|
/// impl Extension for ExtensionSample {
|
||||||
/// fn configure_service(&self, scfg: &mut service::web::ServiceConfig) {
|
/// fn configure_service(&self, scfg: &mut service::web::ServiceConfig) {
|
||||||
/// scfg.route("/sample", web::get().to(route_sample));
|
/// scfg.route("/sample", web::get().to(route_sample));
|
||||||
/// }
|
/// }
|
||||||
|
|
|
@ -9,13 +9,12 @@
|
||||||
//! tipografías, espaciados y cualquier otro detalle visual o de comportamiento (como animaciones,
|
//! tipografías, espaciados y cualquier otro detalle visual o de comportamiento (como animaciones,
|
||||||
//! *scripts* de interfaz, etc.).
|
//! *scripts* de interfaz, etc.).
|
||||||
//!
|
//!
|
||||||
//! Es una extensión más (implementando [`ExtensionTrait`](crate::core::extension::ExtensionTrait)).
|
//! Es una extensión más (implementando [`Extension`](crate::core::extension::Extension)). Se
|
||||||
//! Se instala, activa y declara dependencias igual que el resto de extensiones; y se señala a sí
|
//! instala, activa y declara dependencias igual que el resto de extensiones; y se señala a sí misma
|
||||||
//! misma como tema (implementando [`theme()`](crate::core::extension::ExtensionTrait::theme)
|
//! como tema (implementando [`theme()`](crate::core::extension::Extension::theme) y [`Theme`]).
|
||||||
//! y [`ThemeTrait`]).
|
|
||||||
|
|
||||||
mod definition;
|
mod definition;
|
||||||
pub use definition::{ThemeRef, ThemeTrait};
|
pub use definition::{Theme, ThemeRef};
|
||||||
|
|
||||||
mod regions;
|
mod regions;
|
||||||
pub(crate) use regions::ChildrenInRegions;
|
pub(crate) use regions::ChildrenInRegions;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::core::extension::ExtensionTrait;
|
use crate::core::extension::Extension;
|
||||||
use crate::core::theme::CONTENT_REGION_NAME;
|
use crate::core::theme::CONTENT_REGION_NAME;
|
||||||
use crate::global;
|
use crate::global;
|
||||||
use crate::html::{html, Markup};
|
use crate::html::{html, Markup};
|
||||||
|
@ -8,20 +8,20 @@ use crate::response::page::Page;
|
||||||
/// Representa una referencia a un tema.
|
/// Representa una referencia a un tema.
|
||||||
///
|
///
|
||||||
/// Los temas son también extensiones. Por tanto se deben definir igual, es decir, como instancias
|
/// Los temas son también extensiones. Por tanto se deben definir igual, es decir, como instancias
|
||||||
/// estáticas globales que implementan [`ThemeTrait`], pero también [`ExtensionTrait`].
|
/// estáticas globales que implementan [`Theme`], pero también [`Extension`].
|
||||||
pub type ThemeRef = &'static dyn ThemeTrait;
|
pub type ThemeRef = &'static dyn Theme;
|
||||||
|
|
||||||
/// Interfaz común que debe implementar cualquier tema de `PageTop`.
|
/// Interfaz común que debe implementar cualquier tema de `PageTop`.
|
||||||
///
|
///
|
||||||
/// Un tema implementará [`ThemeTrait`] y los métodos que sean necesarios de [`ExtensionTrait`],
|
/// Un tema implementará [`Theme`] y los métodos que sean necesarios de [`Extension`], aunque el
|
||||||
/// aunque el único obligatorio es [`theme()`](ExtensionTrait::theme).
|
/// único obligatorio es [`theme()`](Extension::theme).
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// use pagetop::prelude::*;
|
/// use pagetop::prelude::*;
|
||||||
///
|
///
|
||||||
/// pub struct MyTheme;
|
/// pub struct MyTheme;
|
||||||
///
|
///
|
||||||
/// impl ExtensionTrait for MyTheme {
|
/// impl Extension for MyTheme {
|
||||||
/// fn name(&self) -> L10n { L10n::n("My theme") }
|
/// fn name(&self) -> L10n { L10n::n("My theme") }
|
||||||
/// fn description(&self) -> L10n { L10n::n("Un tema personal") }
|
/// fn description(&self) -> L10n { L10n::n("Un tema personal") }
|
||||||
///
|
///
|
||||||
|
@ -30,9 +30,9 @@ pub type ThemeRef = &'static dyn ThemeTrait;
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// impl ThemeTrait for MyTheme {}
|
/// impl Theme for MyTheme {}
|
||||||
/// ```
|
/// ```
|
||||||
pub trait ThemeTrait: ExtensionTrait + Send + Sync {
|
pub trait Theme: Extension + Send + Sync {
|
||||||
fn regions(&self) -> Vec<(&'static str, L10n)> {
|
fn regions(&self) -> Vec<(&'static str, L10n)> {
|
||||||
vec![(CONTENT_REGION_NAME, L10n::l("content"))]
|
vec![(CONTENT_REGION_NAME, L10n::l("content"))]
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::builder_fn;
|
use crate::builder_fn;
|
||||||
use crate::core::component::{ComponentTrait, Typed};
|
use crate::core::component::{Component, Typed};
|
||||||
use crate::html::{html, Context, Markup};
|
use crate::html::{html, Context, Markup};
|
||||||
|
|
||||||
/// Contenedor de componente para incluir en otros componentes.
|
/// Contenedor de componente para incluir en otros componentes.
|
||||||
|
@ -16,15 +16,15 @@ use crate::html::{html, Context, Markup};
|
||||||
/// let opt = OptionComponent::new(comp);
|
/// let opt = OptionComponent::new(comp);
|
||||||
/// assert!(opt.get().is_some());
|
/// assert!(opt.get().is_some());
|
||||||
/// ```
|
/// ```
|
||||||
pub struct OptionComponent<C: ComponentTrait>(Option<Typed<C>>);
|
pub struct OptionComponent<C: Component>(Option<Typed<C>>);
|
||||||
|
|
||||||
impl<C: ComponentTrait> Default for OptionComponent<C> {
|
impl<C: Component> Default for OptionComponent<C> {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
OptionComponent(None)
|
OptionComponent(None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<C: ComponentTrait> OptionComponent<C> {
|
impl<C: Component> OptionComponent<C> {
|
||||||
/// Crea un nuevo [`OptionComponent`].
|
/// Crea un nuevo [`OptionComponent`].
|
||||||
///
|
///
|
||||||
/// El componente se envuelve automáticamente en un [`Typed`] y se almacena.
|
/// El componente se envuelve automáticamente en un [`Typed`] y se almacena.
|
||||||
|
|
|
@ -5,7 +5,7 @@ pub use actix_web::Result as ResultPage;
|
||||||
|
|
||||||
use crate::base::action;
|
use crate::base::action;
|
||||||
use crate::builder_fn;
|
use crate::builder_fn;
|
||||||
use crate::core::component::{Child, ChildOp, ComponentTrait};
|
use crate::core::component::{Child, ChildOp, Component};
|
||||||
use crate::core::theme::{ChildrenInRegions, ThemeRef, CONTENT_REGION_NAME};
|
use crate::core::theme::{ChildrenInRegions, ThemeRef, CONTENT_REGION_NAME};
|
||||||
use crate::html::{html, AssetsOp, Context, Markup, DOCTYPE};
|
use crate::html::{html, AssetsOp, Context, Markup, DOCTYPE};
|
||||||
use crate::html::{ClassesOp, OptionClasses, OptionId, OptionTranslated};
|
use crate::html::{ClassesOp, OptionClasses, OptionId, OptionTranslated};
|
||||||
|
@ -121,7 +121,7 @@ impl Page {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 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 ComponentTrait) -> Self {
|
pub fn with_component(mut self, component: impl Component) -> Self {
|
||||||
self.regions
|
self.regions
|
||||||
.alter_child_in_region(CONTENT_REGION_NAME, ChildOp::Add(Child::with(component)));
|
.alter_child_in_region(CONTENT_REGION_NAME, ChildOp::Add(Child::with(component)));
|
||||||
self
|
self
|
||||||
|
@ -131,7 +131,7 @@ impl Page {
|
||||||
pub fn with_component_in(
|
pub fn with_component_in(
|
||||||
mut self,
|
mut self,
|
||||||
region_name: &'static str,
|
region_name: &'static str,
|
||||||
component: impl ComponentTrait,
|
component: impl Component,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
self.regions
|
self.regions
|
||||||
.alter_child_in_region(region_name, ChildOp::Add(Child::with(component)));
|
.alter_child_in_region(region_name, ChildOp::Add(Child::with(component)));
|
||||||
|
|
|
@ -88,7 +88,7 @@ macro_rules! include_files {
|
||||||
///
|
///
|
||||||
/// pub struct MyExtension;
|
/// pub struct MyExtension;
|
||||||
///
|
///
|
||||||
/// impl ExtensionTrait for MyExtension {
|
/// impl Extension for MyExtension {
|
||||||
/// fn configure_service(&self, scfg: &mut service::web::ServiceConfig) {
|
/// fn configure_service(&self, scfg: &mut service::web::ServiceConfig) {
|
||||||
/// include_files_service!(scfg, assets => "/public");
|
/// include_files_service!(scfg, assets => "/public");
|
||||||
/// }
|
/// }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue