🚚 Renombra ContextOp a AssetsOp
El nombre anterior era ambiguo (podría referirse a cualquier operación del contexto); `AssetsOp` describe exactamente lo que hace: operar sobre los recursos del documento.
This commit is contained in:
parent
3e1bc0fb0e
commit
c3feff9efd
8 changed files with 32 additions and 32 deletions
|
|
@ -105,17 +105,17 @@ impl Extension for Aliner {
|
|||
|
||||
impl Theme for Aliner {
|
||||
fn before_render_page_body(&self, page: &mut Page) {
|
||||
page.alter_assets(ContextOp::AddStyleSheet(
|
||||
page.alter_assets(AssetsOp::AddStyleSheet(
|
||||
StyleSheet::from("/css/normalize.css")
|
||||
.with_version("8.0.1")
|
||||
.with_weight(-99),
|
||||
))
|
||||
.alter_assets(ContextOp::AddStyleSheet(
|
||||
.alter_assets(AssetsOp::AddStyleSheet(
|
||||
StyleSheet::from("/css/basic.css")
|
||||
.with_version(PAGETOP_VERSION)
|
||||
.with_weight(-99),
|
||||
))
|
||||
.alter_assets(ContextOp::AddStyleSheet(
|
||||
.alter_assets(AssetsOp::AddStyleSheet(
|
||||
StyleSheet::from("/aliner/css/styles.css")
|
||||
.with_version(env!("CARGO_PKG_VERSION"))
|
||||
.with_weight(-99),
|
||||
|
|
|
|||
|
|
@ -151,12 +151,12 @@ impl Theme for Bootsier {
|
|||
}
|
||||
|
||||
fn before_render_page_body(&self, page: &mut Page) {
|
||||
page.alter_assets(ContextOp::AddStyleSheet(
|
||||
page.alter_assets(AssetsOp::AddStyleSheet(
|
||||
StyleSheet::from("/bootsier/bs/bootstrap.min.css")
|
||||
.with_version(BOOTSTRAP_VERSION)
|
||||
.with_weight(-90),
|
||||
))
|
||||
.alter_assets(ContextOp::AddJavaScript(
|
||||
.alter_assets(AssetsOp::AddJavaScript(
|
||||
JavaScript::defer("/bootsier/js/bootstrap.bundle.min.js")
|
||||
.with_version(BOOTSTRAP_VERSION)
|
||||
.with_weight(-90),
|
||||
|
|
|
|||
|
|
@ -110,14 +110,14 @@ impl Component for Intro {
|
|||
}
|
||||
|
||||
fn setup_before_prepare(&mut self, cx: &mut Context) {
|
||||
cx.alter_assets(ContextOp::AddStyleSheet(
|
||||
cx.alter_assets(AssetsOp::AddStyleSheet(
|
||||
StyleSheet::from("/css/intro.css").with_version(PAGETOP_VERSION),
|
||||
));
|
||||
}
|
||||
|
||||
fn prepare_component(&self, cx: &mut Context) -> Markup {
|
||||
if *self.opening() == IntroOpening::PageTop {
|
||||
cx.alter_assets(ContextOp::AddJavaScript(JavaScript::on_load_async("intro-js", |cx|
|
||||
cx.alter_assets(AssetsOp::AddJavaScript(JavaScript::on_load_async("intro-js", |cx|
|
||||
util::indoc!(r#"
|
||||
try {
|
||||
const resp = await fetch("https://crates.io/api/v1/crates/pagetop");
|
||||
|
|
|
|||
|
|
@ -12,12 +12,12 @@ impl Extension for Basic {
|
|||
|
||||
impl Theme for Basic {
|
||||
fn before_render_page_body(&self, page: &mut Page) {
|
||||
page.alter_assets(ContextOp::AddStyleSheet(
|
||||
page.alter_assets(AssetsOp::AddStyleSheet(
|
||||
StyleSheet::from("/css/normalize.css")
|
||||
.with_version("8.0.1")
|
||||
.with_weight(-99),
|
||||
))
|
||||
.alter_assets(ContextOp::AddStyleSheet(
|
||||
.alter_assets(AssetsOp::AddStyleSheet(
|
||||
StyleSheet::from("/css/basic.css")
|
||||
.with_version(PAGETOP_VERSION)
|
||||
.with_weight(-99),
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ pub use children::{Child, ChildOp};
|
|||
pub use children::{Typed, TypedOp};
|
||||
|
||||
mod context;
|
||||
pub use context::{Context, ContextError, ContextOp, Contextual};
|
||||
pub use context::{AssetsOp, Context, ContextError, Contextual};
|
||||
|
||||
/// Alias de función (*callback*) para **determinar si un componente se renderiza o no**.
|
||||
///
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ use std::collections::HashMap;
|
|||
use std::fmt;
|
||||
|
||||
/// Operaciones para modificar recursos asociados al [`Context`] de un documento.
|
||||
pub enum ContextOp {
|
||||
pub enum AssetsOp {
|
||||
/// Define el *favicon* del documento. Sobrescribe cualquier valor anterior.
|
||||
SetFavicon(Option<Favicon>),
|
||||
/// Define el *favicon* solo si no se ha establecido previamente.
|
||||
|
|
@ -73,7 +73,7 @@ impl std::error::Error for ContextError {}
|
|||
/// - Almacenar la **petición HTTP** de origen.
|
||||
/// - Seleccionar el **tema** y la **plantilla** de renderizado.
|
||||
/// - Administrar **recursos** del documento como el icono [`Favicon`], las hojas de estilo
|
||||
/// [`StyleSheet`] o los scripts [`JavaScript`] mediante [`ContextOp`].
|
||||
/// [`StyleSheet`] o los scripts [`JavaScript`] mediante [`AssetsOp`].
|
||||
/// - Leer y mantener **parámetros dinámicos tipados** de contexto.
|
||||
/// - Generar **identificadores únicos** por tipo de componente.
|
||||
///
|
||||
|
|
@ -89,9 +89,9 @@ impl std::error::Error for ContextError {}
|
|||
/// cx.with_langid(&Locale::resolve("es-ES"))
|
||||
/// .with_theme(&Aliner)
|
||||
/// .with_template(&DefaultTemplate::Standard)
|
||||
/// .with_assets(ContextOp::SetFavicon(Some(Favicon::new().with_icon("/favicon.ico"))))
|
||||
/// .with_assets(ContextOp::AddStyleSheet(StyleSheet::from("/css/app.css")))
|
||||
/// .with_assets(ContextOp::AddJavaScript(JavaScript::defer("/js/app.js")))
|
||||
/// .with_assets(AssetsOp::SetFavicon(Some(Favicon::new().with_icon("/favicon.ico"))))
|
||||
/// .with_assets(AssetsOp::AddStyleSheet(StyleSheet::from("/css/app.css")))
|
||||
/// .with_assets(AssetsOp::AddJavaScript(JavaScript::defer("/js/app.js")))
|
||||
/// .with_param("usuario_id", 42_i32)
|
||||
/// }
|
||||
/// ```
|
||||
|
|
@ -118,9 +118,9 @@ pub trait Contextual: LangId {
|
|||
#[builder_fn]
|
||||
fn with_param<T: 'static>(self, key: &'static str, value: T) -> Self;
|
||||
|
||||
/// Define los recursos del contexto usando [`ContextOp`].
|
||||
/// Define los recursos del contexto usando [`AssetsOp`].
|
||||
#[builder_fn]
|
||||
fn with_assets(self, op: ContextOp) -> Self;
|
||||
fn with_assets(self, op: AssetsOp) -> Self;
|
||||
|
||||
/// Opera con [`ChildOp`] en una región del documento.
|
||||
#[builder_fn]
|
||||
|
|
@ -194,11 +194,11 @@ pub trait Contextual: LangId {
|
|||
/// // Establece el tema para renderizar.
|
||||
/// .with_theme(&Aliner)
|
||||
/// // Asigna un favicon.
|
||||
/// .with_assets(ContextOp::SetFavicon(Some(Favicon::new().with_icon("/favicon.ico"))))
|
||||
/// .with_assets(AssetsOp::SetFavicon(Some(Favicon::new().with_icon("/favicon.ico"))))
|
||||
/// // Añade una hoja de estilo externa.
|
||||
/// .with_assets(ContextOp::AddStyleSheet(StyleSheet::from("/css/style.css")))
|
||||
/// .with_assets(AssetsOp::AddStyleSheet(StyleSheet::from("/css/style.css")))
|
||||
/// // Añade un script JavaScript.
|
||||
/// .with_assets(ContextOp::AddJavaScript(JavaScript::defer("/js/main.js")))
|
||||
/// .with_assets(AssetsOp::AddJavaScript(JavaScript::defer("/js/main.js")))
|
||||
/// // Añade un parámetro dinámico al contexto.
|
||||
/// .with_param("usuario_id", 42)
|
||||
/// }
|
||||
|
|
@ -471,29 +471,29 @@ impl Contextual for Context {
|
|||
}
|
||||
|
||||
#[builder_fn]
|
||||
fn with_assets(mut self, op: ContextOp) -> Self {
|
||||
fn with_assets(mut self, op: AssetsOp) -> Self {
|
||||
match op {
|
||||
// Favicon.
|
||||
ContextOp::SetFavicon(favicon) => {
|
||||
AssetsOp::SetFavicon(favicon) => {
|
||||
self.favicon = favicon;
|
||||
}
|
||||
ContextOp::SetFaviconIfNone(icon) => {
|
||||
AssetsOp::SetFaviconIfNone(icon) => {
|
||||
if self.favicon.is_none() {
|
||||
self.favicon = Some(icon);
|
||||
}
|
||||
}
|
||||
// Stylesheets.
|
||||
ContextOp::AddStyleSheet(css) => {
|
||||
AssetsOp::AddStyleSheet(css) => {
|
||||
self.stylesheets.add(css);
|
||||
}
|
||||
ContextOp::RemoveStyleSheet(path) => {
|
||||
AssetsOp::RemoveStyleSheet(path) => {
|
||||
self.stylesheets.remove(path);
|
||||
}
|
||||
// Scripts JavaScript.
|
||||
ContextOp::AddJavaScript(js) => {
|
||||
AssetsOp::AddJavaScript(js) => {
|
||||
self.javascripts.add(js);
|
||||
}
|
||||
ContextOp::RemoveJavaScript(path) => {
|
||||
AssetsOp::RemoveJavaScript(path) => {
|
||||
self.javascripts.remove(path);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -117,13 +117,13 @@ use std::ops::Deref;
|
|||
/// impl Theme for MyTheme {
|
||||
/// fn before_render_page_body(&self, page: &mut Page) {
|
||||
/// page
|
||||
/// .alter_assets(ContextOp::AddStyleSheet(
|
||||
/// .alter_assets(AssetsOp::AddStyleSheet(
|
||||
/// StyleSheet::from("/css/normalize.css").with_version("8.0.1"),
|
||||
/// ))
|
||||
/// .alter_assets(ContextOp::AddStyleSheet(
|
||||
/// .alter_assets(AssetsOp::AddStyleSheet(
|
||||
/// StyleSheet::from("/css/basic.css").with_version(PAGETOP_VERSION),
|
||||
/// ))
|
||||
/// .alter_assets(ContextOp::AddStyleSheet(
|
||||
/// .alter_assets(AssetsOp::AddStyleSheet(
|
||||
/// StyleSheet::from("/mytheme/styles.css").with_version(env!("CARGO_PKG_VERSION")),
|
||||
/// ));
|
||||
/// }
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@ pub use error::ErrorPage;
|
|||
pub use actix_web::Result as ResultPage;
|
||||
|
||||
use crate::base::action;
|
||||
use crate::core::component::{AssetsOp, Context, Contextual};
|
||||
use crate::core::component::{Child, ChildOp, Component};
|
||||
use crate::core::component::{Context, ContextOp, Contextual};
|
||||
use crate::core::theme::{DefaultRegion, Region, RegionRef, TemplateRef, ThemeRef};
|
||||
use crate::html::{html, Markup, DOCTYPE};
|
||||
use crate::html::{Assets, Favicon, JavaScript, StyleSheet};
|
||||
|
|
@ -334,7 +334,7 @@ impl Contextual for Page {
|
|||
}
|
||||
|
||||
#[builder_fn]
|
||||
fn with_assets(mut self, op: ContextOp) -> Self {
|
||||
fn with_assets(mut self, op: AssetsOp) -> Self {
|
||||
self.context.alter_assets(op);
|
||||
self
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue