Compare commits

...

2 commits

10 changed files with 81 additions and 27 deletions

View file

@ -105,15 +105,24 @@ impl Extension for Aliner {
impl Theme for Aliner {
fn before_render_page_body(&self, page: &mut Page) {
page.alter_param("include_basic_assets", true)
.alter_assets(ContextOp::AddStyleSheet(
StyleSheet::from("/aliner/css/styles.css")
.with_version(env!("CARGO_PKG_VERSION"))
.with_weight(-90),
))
.alter_child_in(
Region::FOOTER,
ChildOp::AddIfEmpty(Child::with(PoweredBy::new())),
);
page.alter_assets(ContextOp::AddStyleSheet(
StyleSheet::from("/css/normalize.css")
.with_version("8.0.1")
.with_weight(-99),
))
.alter_assets(ContextOp::AddStyleSheet(
StyleSheet::from("/css/basic.css")
.with_version(PAGETOP_VERSION)
.with_weight(-99),
))
.alter_assets(ContextOp::AddStyleSheet(
StyleSheet::from("/aliner/css/styles.css")
.with_version(env!("CARGO_PKG_VERSION"))
.with_weight(-99),
))
.alter_child_in(
Region::FOOTER,
ChildOp::AddIfEmpty(Child::with(PoweredBy::new())),
);
}
}

View file

@ -73,7 +73,7 @@ impl Component for Navbar {
return PrepareMarkup::None;
}
// Asegura que la barra tiene un id estable para poder asociarlo al colapso/offcanvas.
// Asegura que la barra tiene un `id` para poder asociarlo al colapso/offcanvas.
let id = cx.required_id::<Self>(self.id());
PrepareMarkup::With(html! {

View file

@ -6,7 +6,7 @@ use crate::core::{extension, extension::ExtensionRef};
use crate::html::Markup;
use crate::response::page::{ErrorPage, ResultPage};
use crate::service::HttpRequest;
use crate::{global, locale, service, trace};
use crate::{global, locale, service, trace, PAGETOP_VERSION};
use actix_session::config::{BrowserSession, PersistentSession, SessionLifecycle};
use actix_session::storage::CookieSessionStore;
@ -108,7 +108,7 @@ impl Application {
println!(
"{} {}\n",
"Powered by PageTop".yellow(),
env!("CARGO_PKG_VERSION").yellow()
PAGETOP_VERSION.yellow()
);
}
}

View file

@ -1,6 +1,6 @@
use crate::prelude::*;
/// Componente básico para renderizar dinámicamente código HTML recibiendo el contexto.
/// 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
/// opcionalmente al contexto de renderizado.

View file

@ -29,7 +29,7 @@ pub enum IntroOpening {
/// opta por [`IntroOpening::PageTop`]) y bloques ([`Block`](crate::base::component::Block)) de
/// contenido libre para crear párrafos vistosos de texto. Aunque admite todo tipo de componentes.
///
/// ### Ejemplos
/// # Ejemplos
///
/// **Intro mínima por defecto**
///
@ -105,7 +105,7 @@ impl Component for Intro {
fn setup_before_prepare(&mut self, cx: &mut Context) {
cx.alter_assets(ContextOp::AddStyleSheet(
StyleSheet::from("/css/intro.css").with_version(env!("CARGO_PKG_VERSION")),
StyleSheet::from("/css/intro.css").with_version(PAGETOP_VERSION),
));
}

View file

@ -3,7 +3,7 @@ use crate::prelude::*;
// Enlace a la página oficial de PageTop.
const LINK: &str = "<a href=\"https://pagetop.cillero.es\" rel=\"noopener noreferrer\">PageTop</a>";
/// Componente que informa del 'Powered by' (*Funciona con*) típica del pie de página.
/// Componente que muestra el típico mensaje *Powered by* (*Funciona con*) en el pie de página.
///
/// 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
@ -17,7 +17,7 @@ impl Component for PoweredBy {
/// Crea una nueva instancia de `PoweredBy`.
///
/// El copyright se genera automáticamente con el año actual y el nombre de la aplicación
/// configurada en [`global::SETTINGS`].
/// configurada en [`global::SETTINGS`], en el formato `YYYY © Nombre de la aplicación`.
fn new() -> Self {
let year = Utc::now().format("%Y").to_string();
let c = join!(year, " © ", global::SETTINGS.app.name);

View file

@ -12,10 +12,19 @@ impl Extension for Basic {
impl Theme for Basic {
fn before_render_page_body(&self, page: &mut Page) {
page.alter_param("include_basic_assets", true)
.alter_child_in(
Region::FOOTER,
ChildOp::AddIfEmpty(Child::with(PoweredBy::new())),
);
page.alter_assets(ContextOp::AddStyleSheet(
StyleSheet::from("/css/normalize.css")
.with_version("8.0.1")
.with_weight(-99),
))
.alter_assets(ContextOp::AddStyleSheet(
StyleSheet::from("/css/basic.css")
.with_version(PAGETOP_VERSION)
.with_weight(-99),
))
.alter_child_in(
Region::FOOTER,
ChildOp::AddIfEmpty(Child::with(PoweredBy::new())),
);
}
}

View file

@ -167,7 +167,7 @@ impl fmt::Display for UnitValue {
/// Convierte una cadena a [`UnitValue`] siguiendo una gramática CSS acotada.
///
/// ## Acepta
/// # Acepta
///
/// - `""` para `UnitValue::None`
/// - `"auto"`
@ -178,7 +178,7 @@ impl fmt::Display for UnitValue {
///
/// (Se toleran espacios entre número y unidad: `"12 px"`, `"1.5 rem"`).
///
/// ## Ejemplo
/// # Ejemplo
///
/// ```rust
/// # use pagetop::prelude::*;
@ -188,7 +188,7 @@ impl fmt::Display for UnitValue {
/// assert!(UnitValue::from_str("12").is_err());
/// ```
///
/// ## Errores de interpretación
/// # Errores de interpretación
///
/// - Falta la unidad cuando es necesaria (p. ej., `"12"`, excepto para el valor cero).
/// - Decimales en valores que deben ser absolutos (p. ej. `"1.5px"`).
@ -262,7 +262,7 @@ impl FromStr for UnitValue {
/// Deserializa desde una cadena usando la misma gramática que [`FromStr`].
///
/// ### Ejemplo con `serde_json`
/// # Ejemplo con `serde_json`
/// ```rust
/// # use pagetop::prelude::*;
/// use serde::Deserialize;

View file

@ -99,6 +99,40 @@ use std::ops::Deref;
// **< RE-EXPORTED >********************************************************************************
/// Versión del *crate* `pagetop`, obtenida en tiempo de compilación (`CARGO_PKG_VERSION`).
///
/// Útil para versionar recursos estáticos de PageTop desde otros *crates*. Por ejemplo:
///
/// ```rust
/// use pagetop::prelude::*;
///
/// pub struct MyTheme;
///
/// impl Extension for MyTheme {
/// fn theme(&self) -> Option<ThemeRef> {
/// Some(&Self)
/// }
/// }
///
/// impl Theme for MyTheme {
/// fn before_render_page_body(&self, page: &mut Page) {
/// page
/// .alter_assets(ContextOp::AddStyleSheet(
/// StyleSheet::from("/css/normalize.css").with_version("8.0.1"),
/// ))
/// .alter_assets(ContextOp::AddStyleSheet(
/// StyleSheet::from("/css/basic.css").with_version(PAGETOP_VERSION),
/// ))
/// .alter_assets(ContextOp::AddStyleSheet(
/// StyleSheet::from("/mytheme/styles.css").with_version(env!("CARGO_PKG_VERSION")),
/// ));
/// }
/// }
/// ```
/// Donde `PAGETOP_VERSION` identifica la versión de PageTop y `env!("CARGO_PKG_VERSION")` hace
/// referencia a la versión del *crate* que lo usa.
pub const PAGETOP_VERSION: &str = env!("CARGO_PKG_VERSION");
pub use pagetop_macros::{builder_fn, html, main, test, AutoDefault};
pub use pagetop_statics::{resource, StaticResource};

View file

@ -2,6 +2,8 @@
// RE-EXPORTED.
pub use crate::PAGETOP_VERSION;
pub use crate::{builder_fn, html, main, test};
pub use crate::{AutoDefault, StaticResources, UniqueId, Weight};