🚧 Añade constante PAGETOP_VERSION
This commit is contained in:
parent
1c7db48323
commit
a272dbf39b
6 changed files with 72 additions and 18 deletions
|
|
@ -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())),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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())),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
34
src/lib.rs
34
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<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};
|
||||
|
|
|
|||
|
|
@ -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};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue