diff --git a/extensions/pagetop-aliner/src/lib.rs b/extensions/pagetop-aliner/src/lib.rs index 5e915578..80e6ca15 100644 --- a/extensions/pagetop-aliner/src/lib.rs +++ b/extensions/pagetop-aliner/src/lib.rs @@ -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())), + ); } } diff --git a/src/app.rs b/src/app.rs index c8ffba11..6ecff369 100644 --- a/src/app.rs +++ b/src/app.rs @@ -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() ); } } diff --git a/src/base/component/intro.rs b/src/base/component/intro.rs index 5de7349a..ea01ccc8 100644 --- a/src/base/component/intro.rs +++ b/src/base/component/intro.rs @@ -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), )); } diff --git a/src/base/theme/basic.rs b/src/base/theme/basic.rs index 63ebe7a3..83dc4a8d 100644 --- a/src/base/theme/basic.rs +++ b/src/base/theme/basic.rs @@ -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())), + ); } } diff --git a/src/lib.rs b/src/lib.rs index a2683495..caa74536 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 { +/// 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}; diff --git a/src/prelude.rs b/src/prelude.rs index 15121036..1d649fec 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -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};