✨ Implementa Debug en comp./tipos principales
This commit is contained in:
parent
c3feff9efd
commit
a0b14aec36
21 changed files with 61 additions and 32 deletions
|
|
@ -4,7 +4,7 @@ use crate::prelude::*;
|
|||
///
|
||||
/// Los bloques se utilizan como contenedores de otros componentes o contenidos, con un título
|
||||
/// opcional y un cuerpo que sólo se renderiza si existen componentes hijos (*children*).
|
||||
#[derive(AutoDefault, Getters)]
|
||||
#[derive(AutoDefault, Debug, Getters)]
|
||||
pub struct Block {
|
||||
#[getters(skip)]
|
||||
id: AttrId,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
use crate::prelude::*;
|
||||
|
||||
use std::fmt;
|
||||
|
||||
/// Componente básico que renderiza dinámicamente código HTML según el contexto.
|
||||
///
|
||||
/// Este componente permite generar contenido HTML arbitrario, usando la macro `html!` y accediendo
|
||||
|
|
@ -31,6 +33,14 @@ use crate::prelude::*;
|
|||
/// ```
|
||||
pub struct Html(Box<dyn Fn(&mut Context) -> Markup + Send + Sync>);
|
||||
|
||||
impl fmt::Debug for Html {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_tuple("Html")
|
||||
.field(&"Fn(&mut Context) -> Markup")
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Html {
|
||||
fn default() -> Self {
|
||||
Self::with(|_| html! {})
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ pub enum IntroOpening {
|
|||
/// })),
|
||||
/// );
|
||||
/// ```
|
||||
#[derive(Getters)]
|
||||
#[derive(Debug, Getters)]
|
||||
pub struct Intro {
|
||||
/// Devuelve el título de entrada.
|
||||
title: L10n,
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ const LINK: &str = "<a href=\"https://pagetop.cillero.es\" rel=\"noopener norefe
|
|||
/// Por defecto, usando [`default()`](Self::default) sólo se muestra un reconocimiento a PageTop.
|
||||
/// Sin embargo, se puede usar [`new()`](Self::new) para crear una instancia con un texto de
|
||||
/// copyright predeterminado.
|
||||
#[derive(AutoDefault, Getters)]
|
||||
#[derive(AutoDefault, Debug, Getters)]
|
||||
pub struct PoweredBy {
|
||||
/// Devuelve el texto de copyright actual, si existe.
|
||||
copyright: Option<String>,
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ use parking_lot::RwLock;
|
|||
pub use parking_lot::RwLockReadGuard as ComponentReadGuard;
|
||||
pub use parking_lot::RwLockWriteGuard as ComponentWriteGuard;
|
||||
|
||||
use std::fmt;
|
||||
use std::sync::Arc;
|
||||
use std::vec::IntoIter;
|
||||
|
||||
|
|
@ -17,6 +18,15 @@ use std::vec::IntoIter;
|
|||
#[derive(AutoDefault, Clone)]
|
||||
pub struct Child(Option<Arc<RwLock<dyn Component>>>);
|
||||
|
||||
impl fmt::Debug for Child {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match &self.0 {
|
||||
None => write!(f, "Child(None)"),
|
||||
Some(c) => write!(f, "Child({})", c.read().name()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Child {
|
||||
/// Crea un nuevo `Child` a partir de un componente.
|
||||
pub fn with(component: impl Component) -> Self {
|
||||
|
|
@ -71,6 +81,15 @@ impl Child {
|
|||
#[derive(AutoDefault, Clone)]
|
||||
pub struct Typed<C: Component>(Option<Arc<RwLock<C>>>);
|
||||
|
||||
impl<C: Component> fmt::Debug for Typed<C> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match &self.0 {
|
||||
None => write!(f, "Typed(None)"),
|
||||
Some(c) => write!(f, "Typed({})", c.read().name()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<C: Component> Typed<C> {
|
||||
/// Crea un nuevo `Typed` a partir de un componente.
|
||||
pub fn with(component: C) -> Self {
|
||||
|
|
@ -202,7 +221,7 @@ pub enum TypedOp<C: Component> {
|
|||
/// Esta lista permite añadir, modificar, renderizar y consultar componentes hijo en orden de
|
||||
/// inserción, soportando operaciones avanzadas como inserción relativa o reemplazo por
|
||||
/// identificador.
|
||||
#[derive(AutoDefault, Clone)]
|
||||
#[derive(AutoDefault, Clone, Debug)]
|
||||
pub struct Children(Vec<Child>);
|
||||
|
||||
impl Children {
|
||||
|
|
|
|||
|
|
@ -62,6 +62,17 @@ pub struct L10n {
|
|||
args: Vec<(CowStr, CowStr)>,
|
||||
}
|
||||
|
||||
impl fmt::Debug for L10n {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("L10n")
|
||||
.field("op", &self.op)
|
||||
.field("args", &self.args)
|
||||
// No se puede mostrar `locales`; se representa con un texto fijo.
|
||||
.field("locales", &"<StaticLoader>")
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl L10n {
|
||||
/// **n** = *“native”*. Crea una instancia con una cadena literal sin traducción.
|
||||
pub fn n(text: impl Into<CowStr>) -> Self {
|
||||
|
|
@ -177,14 +188,3 @@ impl L10n {
|
|||
PreEscaped(self.lookup(language).unwrap_or_default())
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for L10n {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("L10n")
|
||||
.field("op", &self.op)
|
||||
.field("args", &self.args)
|
||||
// No se puede mostrar `locales`; se representa con un texto fijo.
|
||||
.field("locales", &"<StaticLoader>")
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue