✨ [pagetop] Añade macro Getters para estructuras
This commit is contained in:
parent
0f76cfe28b
commit
4944af073f
17 changed files with 154 additions and 390 deletions
|
|
@ -4,12 +4,15 @@ 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*).
|
||||
#[rustfmt::skip]
|
||||
#[derive(AutoDefault)]
|
||||
#[derive(AutoDefault, Getters)]
|
||||
pub struct Block {
|
||||
id : AttrId,
|
||||
classes : AttrClasses,
|
||||
title : L10n,
|
||||
#[getters(skip)]
|
||||
id: AttrId,
|
||||
/// Devuelve las clases CSS asociadas al bloque.
|
||||
classes: AttrClasses,
|
||||
/// Devuelve el título del bloque.
|
||||
title: L10n,
|
||||
/// Devuelve la lista de componentes hijo del bloque.
|
||||
children: Children,
|
||||
}
|
||||
|
||||
|
|
@ -83,21 +86,4 @@ impl Block {
|
|||
self.children.alter_child(op);
|
||||
self
|
||||
}
|
||||
|
||||
// **< Block GETTERS >**************************************************************************
|
||||
|
||||
/// Devuelve las clases CSS asociadas al bloque.
|
||||
pub fn classes(&self) -> &AttrClasses {
|
||||
&self.classes
|
||||
}
|
||||
|
||||
/// Devuelve el título del bloque.
|
||||
pub fn title(&self) -> &L10n {
|
||||
&self.title
|
||||
}
|
||||
|
||||
/// Devuelve la lista de componentes (`children`) del bloque.
|
||||
pub fn children(&self) -> &Children {
|
||||
&self.children
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,12 +76,17 @@ pub enum IntroOpening {
|
|||
/// })),
|
||||
/// );
|
||||
/// ```
|
||||
#[rustfmt::skip]
|
||||
#[derive(Getters)]
|
||||
pub struct Intro {
|
||||
title : L10n,
|
||||
slogan : L10n,
|
||||
button : Option<(L10n, FnPathByContext)>,
|
||||
opening : IntroOpening,
|
||||
/// Devuelve el título de entrada.
|
||||
title: L10n,
|
||||
/// Devuelve el eslogan de la entrada.
|
||||
slogan: L10n,
|
||||
/// Devuelve el botón de llamada a la acción, si existe.
|
||||
button: Option<(L10n, FnPathByContext)>,
|
||||
/// Devuelve el modo de apertura configurado.
|
||||
opening: IntroOpening,
|
||||
/// Devuelve la lista de componentes hijo de la intro.
|
||||
children: Children,
|
||||
}
|
||||
|
||||
|
|
@ -110,7 +115,7 @@ impl Component for Intro {
|
|||
}
|
||||
|
||||
fn prepare_component(&self, cx: &mut Context) -> PrepareMarkup {
|
||||
if self.opening() == IntroOpening::PageTop {
|
||||
if *self.opening() == IntroOpening::PageTop {
|
||||
cx.alter_assets(ContextOp::AddJavaScript(JavaScript::on_load_async("intro-js", |cx|
|
||||
util::indoc!(r#"
|
||||
try {
|
||||
|
|
@ -163,7 +168,7 @@ impl Component for Intro {
|
|||
}
|
||||
}
|
||||
div class="intro-text__children" {
|
||||
@if self.opening() == IntroOpening::PageTop {
|
||||
@if *self.opening() == IntroOpening::PageTop {
|
||||
p { (L10n::l("intro_text1").using(cx)) }
|
||||
div id="intro-badges" {
|
||||
img
|
||||
|
|
@ -289,31 +294,4 @@ impl Intro {
|
|||
self.children.alter_child(op);
|
||||
self
|
||||
}
|
||||
|
||||
// **< Intro GETTERS >**************************************************************************
|
||||
|
||||
/// Devuelve el título de entrada.
|
||||
pub fn title(&self) -> &L10n {
|
||||
&self.title
|
||||
}
|
||||
|
||||
/// Devuelve el eslogan de la entrada.
|
||||
pub fn slogan(&self) -> &L10n {
|
||||
&self.slogan
|
||||
}
|
||||
|
||||
/// Devuelve el botón de llamada a la acción, si existe.
|
||||
pub fn button(&self) -> Option<(&L10n, &FnPathByContext)> {
|
||||
self.button.as_ref().map(|(txt, lnk)| (txt, lnk))
|
||||
}
|
||||
|
||||
/// Devuelve el modo de apertura configurado.
|
||||
pub fn opening(&self) -> IntroOpening {
|
||||
self.opening
|
||||
}
|
||||
|
||||
/// Devuelve la lista de componentes (`children`) de la intro.
|
||||
pub fn children(&self) -> &Children {
|
||||
&self.children
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,8 +8,9 @@ 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)]
|
||||
#[derive(AutoDefault, Getters)]
|
||||
pub struct PoweredBy {
|
||||
/// Devuelve el texto de copyright actual, si existe.
|
||||
copyright: Option<String>,
|
||||
}
|
||||
|
||||
|
|
@ -56,11 +57,4 @@ impl PoweredBy {
|
|||
self.copyright = copyright.map(Into::into);
|
||||
self
|
||||
}
|
||||
|
||||
// **< PoweredBy GETTERS >**********************************************************************
|
||||
|
||||
/// Devuelve el texto de copyright actual, si existe.
|
||||
pub fn copyright(&self) -> Option<&str> {
|
||||
self.copyright.as_deref()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -137,6 +137,8 @@ pub use pagetop_macros::{builder_fn, html, main, test, AutoDefault};
|
|||
|
||||
pub use pagetop_statics::{resource, StaticResource};
|
||||
|
||||
pub use getter_methods::Getters;
|
||||
|
||||
/// Contenedor para un conjunto de recursos embebidos.
|
||||
#[derive(AutoDefault)]
|
||||
pub struct StaticResources {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ pub use crate::PAGETOP_VERSION;
|
|||
|
||||
pub use crate::{builder_fn, html, main, test};
|
||||
|
||||
pub use crate::{AutoDefault, StaticResources, UniqueId, Weight};
|
||||
pub use crate::{AutoDefault, Getters, StaticResources, UniqueId, Weight};
|
||||
|
||||
// MACROS.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue