🏷️ 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;
|
||||
//!
|
||||
//! impl ExtensionTrait for MyExtension {
|
||||
//! impl Extension for MyExtension {
|
||||
//! // Servicio web que publica los recursos de `guides` en `/ruta/a/guides`.
|
||||
//! fn configure_service(&self, scfg: &mut service::web::ServiceConfig) {
|
||||
//! include_files_service!(scfg, guides => "/ruta/a/guides");
|
||||
|
|
|
@ -3,7 +3,7 @@ use crate::prelude::*;
|
|||
use crate::base::action::FnActionWithComponent;
|
||||
|
||||
/// Ejecuta [`FnActionWithComponent`] después de renderizar un componente.
|
||||
pub struct AfterRender<C: ComponentTrait> {
|
||||
pub struct AfterRender<C: Component> {
|
||||
f: FnActionWithComponent<C>,
|
||||
referer_type_id: Option<UniqueId>,
|
||||
referer_id: OptionId,
|
||||
|
@ -11,7 +11,7 @@ pub struct AfterRender<C: ComponentTrait> {
|
|||
}
|
||||
|
||||
/// 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`.
|
||||
fn referer_type_id(&self) -> Option<UniqueId> {
|
||||
self.referer_type_id
|
||||
|
@ -28,8 +28,8 @@ impl<C: ComponentTrait> ActionDispatcher for AfterRender<C> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<C: ComponentTrait> AfterRender<C> {
|
||||
/// Permite [registrar](ExtensionTrait::actions) una nueva acción [`FnActionWithComponent`].
|
||||
impl<C: Component> AfterRender<C> {
|
||||
/// Permite [registrar](Extension::actions) una nueva acción [`FnActionWithComponent`].
|
||||
pub fn new(f: FnActionWithComponent<C>) -> Self {
|
||||
AfterRender {
|
||||
f,
|
||||
|
|
|
@ -3,7 +3,7 @@ use crate::prelude::*;
|
|||
use crate::base::action::FnActionWithComponent;
|
||||
|
||||
/// Ejecuta [`FnActionWithComponent`] antes de renderizar el componente.
|
||||
pub struct BeforeRender<C: ComponentTrait> {
|
||||
pub struct BeforeRender<C: Component> {
|
||||
f: FnActionWithComponent<C>,
|
||||
referer_type_id: Option<UniqueId>,
|
||||
referer_id: OptionId,
|
||||
|
@ -11,7 +11,7 @@ pub struct BeforeRender<C: ComponentTrait> {
|
|||
}
|
||||
|
||||
/// 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`.
|
||||
fn referer_type_id(&self) -> Option<UniqueId> {
|
||||
self.referer_type_id
|
||||
|
@ -28,8 +28,8 @@ impl<C: ComponentTrait> ActionDispatcher for BeforeRender<C> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<C: ComponentTrait> BeforeRender<C> {
|
||||
/// Permite [registrar](ExtensionTrait::actions) una nueva acción [`FnActionWithComponent`].
|
||||
impl<C: Component> BeforeRender<C> {
|
||||
/// Permite [registrar](Extension::actions) una nueva acción [`FnActionWithComponent`].
|
||||
pub fn new(f: FnActionWithComponent<C>) -> Self {
|
||||
BeforeRender {
|
||||
f,
|
||||
|
|
|
@ -8,7 +8,7 @@ use crate::prelude::*;
|
|||
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.
|
||||
pub struct IsRenderable<C: ComponentTrait> {
|
||||
pub struct IsRenderable<C: Component> {
|
||||
f: FnIsRenderable<C>,
|
||||
referer_type_id: Option<UniqueId>,
|
||||
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`.
|
||||
impl<C: ComponentTrait> ActionDispatcher for IsRenderable<C> {
|
||||
impl<C: Component> ActionDispatcher for IsRenderable<C> {
|
||||
/// Devuelve el identificador de tipo ([`UniqueId`]) del componente `C`.
|
||||
fn referer_type_id(&self) -> Option<UniqueId> {
|
||||
self.referer_type_id
|
||||
|
@ -33,8 +33,8 @@ impl<C: ComponentTrait> ActionDispatcher for IsRenderable<C> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<C: ComponentTrait> IsRenderable<C> {
|
||||
/// Permite [registrar](ExtensionTrait::actions) una nueva acción [`FnIsRenderable`].
|
||||
impl<C: Component> IsRenderable<C> {
|
||||
/// Permite [registrar](Extension::actions) una nueva acción [`FnIsRenderable`].
|
||||
pub fn new(f: FnIsRenderable<C>) -> Self {
|
||||
IsRenderable {
|
||||
f,
|
||||
|
|
|
@ -22,7 +22,7 @@ impl ActionDispatcher for 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).
|
||||
pub fn new(f: FnActionWithPage) -> Self {
|
||||
AfterRenderBody { f, weight: 0 }
|
||||
|
|
|
@ -22,7 +22,7 @@ impl ActionDispatcher for 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).
|
||||
pub fn new(f: FnActionWithPage) -> Self {
|
||||
BeforeRenderBody { f, weight: 0 }
|
||||
|
|
|
@ -3,7 +3,7 @@ use crate::prelude::*;
|
|||
use crate::base::action::FnActionWithComponent;
|
||||
|
||||
/// Ejecuta [`FnActionWithComponent`] después de que un tema renderice el componente.
|
||||
pub struct AfterRender<C: ComponentTrait> {
|
||||
pub struct AfterRender<C: Component> {
|
||||
f: FnActionWithComponent<C>,
|
||||
theme_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
|
||||
/// `C`.
|
||||
impl<C: ComponentTrait> ActionDispatcher for AfterRender<C> {
|
||||
impl<C: Component> ActionDispatcher for AfterRender<C> {
|
||||
/// Devuelve el identificador de tipo ([`UniqueId`]) del tema.
|
||||
fn theme_type_id(&self) -> Option<UniqueId> {
|
||||
self.theme_type_id
|
||||
|
@ -23,9 +23,9 @@ impl<C: ComponentTrait> ActionDispatcher for AfterRender<C> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<C: ComponentTrait> AfterRender<C> {
|
||||
/// Permite [registrar](ExtensionTrait::actions) una nueva acción [`FnActionWithComponent`] para
|
||||
/// un tema dado.
|
||||
impl<C: Component> AfterRender<C> {
|
||||
/// Permite [registrar](Extension::actions) una nueva acción [`FnActionWithComponent`] para un
|
||||
/// tema dado.
|
||||
pub fn new(theme: ThemeRef, f: FnActionWithComponent<C>) -> Self {
|
||||
AfterRender {
|
||||
f,
|
||||
|
|
|
@ -3,7 +3,7 @@ use crate::prelude::*;
|
|||
use crate::base::action::FnActionWithComponent;
|
||||
|
||||
/// Ejecuta [`FnActionWithComponent`] antes de que un tema renderice el componente.
|
||||
pub struct BeforeRender<C: ComponentTrait> {
|
||||
pub struct BeforeRender<C: Component> {
|
||||
f: FnActionWithComponent<C>,
|
||||
theme_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
|
||||
/// `C`.
|
||||
impl<C: ComponentTrait> ActionDispatcher for BeforeRender<C> {
|
||||
impl<C: Component> ActionDispatcher for BeforeRender<C> {
|
||||
/// Devuelve el identificador de tipo ([`UniqueId`]) del tema.
|
||||
fn theme_type_id(&self) -> Option<UniqueId> {
|
||||
self.theme_type_id
|
||||
|
@ -23,9 +23,9 @@ impl<C: ComponentTrait> ActionDispatcher for BeforeRender<C> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<C: ComponentTrait> BeforeRender<C> {
|
||||
/// Permite [registrar](ExtensionTrait::actions) una nueva acción [`FnActionWithComponent`] para
|
||||
/// un tema dado.
|
||||
impl<C: Component> BeforeRender<C> {
|
||||
/// Permite [registrar](Extension::actions) una nueva acción [`FnActionWithComponent`] para un
|
||||
/// tema dado.
|
||||
pub fn new(theme: ThemeRef, f: FnActionWithComponent<C>) -> Self {
|
||||
BeforeRender {
|
||||
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.
|
||||
///
|
||||
/// 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>,
|
||||
theme_type_id: Option<UniqueId>,
|
||||
referer_type_id: Option<UniqueId>,
|
||||
}
|
||||
|
||||
/// 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.
|
||||
fn theme_type_id(&self) -> Option<UniqueId> {
|
||||
self.theme_type_id
|
||||
|
@ -30,9 +30,9 @@ impl<C: ComponentTrait> ActionDispatcher for PrepareRender<C> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<C: ComponentTrait> PrepareRender<C> {
|
||||
/// Permite [registrar](ExtensionTrait::actions) una nueva acción [`FnPrepareRender`] para un
|
||||
/// tema dado.
|
||||
impl<C: Component> PrepareRender<C> {
|
||||
/// Permite [registrar](Extension::actions) una nueva acción [`FnPrepareRender`] para un tema
|
||||
/// dado.
|
||||
pub fn new(theme: ThemeRef, f: FnPrepareRender<C>) -> Self {
|
||||
PrepareRender {
|
||||
f,
|
||||
|
|
|
@ -38,7 +38,7 @@ impl Default for Html {
|
|||
Html::with(|_| html! {})
|
||||
}
|
||||
}
|
||||
impl ComponentTrait for Html {
|
||||
impl Component for Html {
|
||||
fn new() -> Self {
|
||||
Html::default()
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ use crate::prelude::*;
|
|||
/// funcionando correctamente.
|
||||
pub struct Welcome;
|
||||
|
||||
impl ExtensionTrait for Welcome {
|
||||
impl Extension for Welcome {
|
||||
fn name(&self) -> L10n {
|
||||
L10n::l("welcome_extension_name")
|
||||
}
|
||||
|
|
|
@ -5,13 +5,13 @@ use crate::prelude::*;
|
|||
/// Tema básico por defecto.
|
||||
pub struct Basic;
|
||||
|
||||
impl ExtensionTrait for Basic {
|
||||
impl Extension for Basic {
|
||||
fn theme(&self) -> Option<ThemeRef> {
|
||||
Some(&Self)
|
||||
}
|
||||
}
|
||||
|
||||
impl ThemeTrait for Basic {
|
||||
impl Theme for Basic {
|
||||
fn after_render_page_body(&self, page: &mut Page) {
|
||||
page.alter_assets(AssetsOp::AddStyleSheet(
|
||||
StyleSheet::from("/css/normalize.css")
|
||||
|
|
|
@ -25,7 +25,7 @@ pub use all::dispatch_actions;
|
|||
/// ```rust,ignore
|
||||
/// use pagetop::prelude::*;
|
||||
///
|
||||
/// impl ExtensionTrait for MyTheme {
|
||||
/// impl Extension for MyTheme {
|
||||
/// fn actions(&self) -> Vec<ActionBox> {
|
||||
/// actions_boxed![
|
||||
/// 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 render_error404(c: &Error404, cx: &mut Context) -> PrepareMarkup { todo!() }
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
//! API para construir nuevos componentes.
|
||||
|
||||
mod definition;
|
||||
pub use definition::{ComponentRender, ComponentTrait};
|
||||
pub use definition::{Component, ComponentRender};
|
||||
|
||||
mod 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::{builder_fn, UniqueId};
|
||||
|
||||
|
@ -9,14 +9,14 @@ use std::vec::IntoIter;
|
|||
|
||||
/// 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<_>>`].
|
||||
#[derive(Clone)]
|
||||
pub struct Child(Arc<RwLock<dyn ComponentTrait>>);
|
||||
pub struct Child(Arc<RwLock<dyn Component>>);
|
||||
|
||||
impl Child {
|
||||
/// 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)))
|
||||
}
|
||||
|
||||
|
@ -47,15 +47,15 @@ impl Child {
|
|||
/// Variante tipada de [`Child`] para evitar conversiones durante el uso.
|
||||
///
|
||||
/// 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 {
|
||||
Self(self.0.clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl<C: ComponentTrait> Typed<C> {
|
||||
impl<C: Component> Typed<C> {
|
||||
/// Crea un nuevo [`Typed`] a partir de un componente.
|
||||
pub fn with(component: C) -> Self {
|
||||
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`].
|
||||
pub enum TypedOp<C: ComponentTrait> {
|
||||
pub enum TypedOp<C: Component> {
|
||||
Add(Typed<C>),
|
||||
InsertAfterId(&'static str, Typed<C>),
|
||||
InsertBeforeId(&'static str, Typed<C>),
|
||||
|
@ -153,7 +153,7 @@ impl Children {
|
|||
|
||||
/// Ejecuta una operación con [`TypedOp`] en la lista.
|
||||
#[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 {
|
||||
TypedOp::Add(typed) => self.add(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.
|
||||
///
|
||||
/// 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 {
|
||||
/// Renderiza el componente usando el contexto proporcionado.
|
||||
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)
|
||||
/// para que otras extensiones puedan hacer sus últimos ajustes.
|
||||
/// 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 {
|
||||
// Si no es renderizable, devuelve un bloque HTML vacío.
|
||||
if !action::component::IsRenderable::dispatch(self, cx) {
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
//! API para añadir nuevas funcionalidades usando extensiones.
|
||||
//!
|
||||
//! 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;
|
||||
pub use definition::{ExtensionRef, ExtensionTrait};
|
||||
pub use definition::{Extension, ExtensionRef};
|
||||
|
||||
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
|
||||
/// 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`.
|
||||
///
|
||||
|
@ -20,12 +20,12 @@ pub type ExtensionRef = &'static dyn ExtensionTrait;
|
|||
///
|
||||
/// pub struct Blog;
|
||||
///
|
||||
/// impl ExtensionTrait for Blog {
|
||||
/// impl Extension for Blog {
|
||||
/// fn name(&self) -> L10n { L10n::n("Blog") }
|
||||
/// 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.
|
||||
///
|
||||
/// 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()
|
||||
}
|
||||
|
||||
/// Los temas son extensiones que implementan [`ExtensionTrait`] y también
|
||||
/// [`ThemeTrait`](crate::core::theme::ThemeTrait).
|
||||
/// Los temas son extensiones que implementan [`Extension`] y también
|
||||
/// [`Theme`](crate::core::theme::Theme).
|
||||
///
|
||||
/// 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;
|
||||
///
|
||||
/// impl ExtensionTrait for MyTheme {
|
||||
/// impl Extension for MyTheme {
|
||||
/// fn theme(&self) -> Option<ThemeRef> {
|
||||
/// Some(&Self)
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
/// impl ThemeTrait for MyTheme {}
|
||||
/// impl Theme for MyTheme {}
|
||||
/// ```
|
||||
fn theme(&self) -> Option<ThemeRef> {
|
||||
None
|
||||
|
@ -94,7 +94,7 @@ pub trait ExtensionTrait: AnyInfo + Send + Sync {
|
|||
///
|
||||
/// pub struct ExtensionSample;
|
||||
///
|
||||
/// impl ExtensionTrait for ExtensionSample {
|
||||
/// impl Extension for ExtensionSample {
|
||||
/// fn configure_service(&self, scfg: &mut service::web::ServiceConfig) {
|
||||
/// 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,
|
||||
//! *scripts* de interfaz, etc.).
|
||||
//!
|
||||
//! Es una extensión más (implementando [`ExtensionTrait`](crate::core::extension::ExtensionTrait)).
|
||||
//! Se instala, activa y declara dependencias igual que el resto de extensiones; y se señala a sí
|
||||
//! misma como tema (implementando [`theme()`](crate::core::extension::ExtensionTrait::theme)
|
||||
//! y [`ThemeTrait`]).
|
||||
//! Es una extensión más (implementando [`Extension`](crate::core::extension::Extension)). Se
|
||||
//! instala, activa y declara dependencias igual que el resto de extensiones; y se señala a sí misma
|
||||
//! como tema (implementando [`theme()`](crate::core::extension::Extension::theme) y [`Theme`]).
|
||||
|
||||
mod definition;
|
||||
pub use definition::{ThemeRef, ThemeTrait};
|
||||
pub use definition::{Theme, ThemeRef};
|
||||
|
||||
mod regions;
|
||||
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::global;
|
||||
use crate::html::{html, Markup};
|
||||
|
@ -8,20 +8,20 @@ use crate::response::page::Page;
|
|||
/// Representa una referencia a un tema.
|
||||
///
|
||||
/// 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`].
|
||||
pub type ThemeRef = &'static dyn ThemeTrait;
|
||||
/// estáticas globales que implementan [`Theme`], pero también [`Extension`].
|
||||
pub type ThemeRef = &'static dyn Theme;
|
||||
|
||||
/// Interfaz común que debe implementar cualquier tema de `PageTop`.
|
||||
///
|
||||
/// Un tema implementará [`ThemeTrait`] y los métodos que sean necesarios de [`ExtensionTrait`],
|
||||
/// aunque el único obligatorio es [`theme()`](ExtensionTrait::theme).
|
||||
/// Un tema implementará [`Theme`] y los métodos que sean necesarios de [`Extension`], aunque el
|
||||
/// único obligatorio es [`theme()`](Extension::theme).
|
||||
///
|
||||
/// ```rust
|
||||
/// use pagetop::prelude::*;
|
||||
///
|
||||
/// pub struct MyTheme;
|
||||
///
|
||||
/// impl ExtensionTrait for MyTheme {
|
||||
/// impl Extension for MyTheme {
|
||||
/// fn name(&self) -> L10n { L10n::n("My theme") }
|
||||
/// 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)> {
|
||||
vec![(CONTENT_REGION_NAME, L10n::l("content"))]
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::builder_fn;
|
||||
use crate::core::component::{ComponentTrait, Typed};
|
||||
use crate::core::component::{Component, Typed};
|
||||
use crate::html::{html, Context, Markup};
|
||||
|
||||
/// Contenedor de componente para incluir en otros componentes.
|
||||
|
@ -16,15 +16,15 @@ use crate::html::{html, Context, Markup};
|
|||
/// let opt = OptionComponent::new(comp);
|
||||
/// 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 {
|
||||
OptionComponent(None)
|
||||
}
|
||||
}
|
||||
|
||||
impl<C: ComponentTrait> OptionComponent<C> {
|
||||
impl<C: Component> OptionComponent<C> {
|
||||
/// Crea un nuevo [`OptionComponent`].
|
||||
///
|
||||
/// 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::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::html::{html, AssetsOp, Context, Markup, DOCTYPE};
|
||||
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.
|
||||
pub fn with_component(mut self, component: impl ComponentTrait) -> Self {
|
||||
pub fn with_component(mut self, component: impl Component) -> Self {
|
||||
self.regions
|
||||
.alter_child_in_region(CONTENT_REGION_NAME, ChildOp::Add(Child::with(component)));
|
||||
self
|
||||
|
@ -131,7 +131,7 @@ impl Page {
|
|||
pub fn with_component_in(
|
||||
mut self,
|
||||
region_name: &'static str,
|
||||
component: impl ComponentTrait,
|
||||
component: impl Component,
|
||||
) -> Self {
|
||||
self.regions
|
||||
.alter_child_in_region(region_name, ChildOp::Add(Child::with(component)));
|
||||
|
|
|
@ -88,7 +88,7 @@ macro_rules! include_files {
|
|||
///
|
||||
/// pub struct MyExtension;
|
||||
///
|
||||
/// impl ExtensionTrait for MyExtension {
|
||||
/// impl Extension for MyExtension {
|
||||
/// fn configure_service(&self, scfg: &mut service::web::ServiceConfig) {
|
||||
/// include_files_service!(scfg, assets => "/public");
|
||||
/// }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue