🚚 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:
Manuel Cillero 2026-03-21 11:12:46 +01:00
parent 3e1bc0fb0e
commit c3feff9efd
8 changed files with 32 additions and 32 deletions

View file

@ -105,17 +105,17 @@ impl Extension for Aliner {
impl Theme for Aliner { impl Theme for Aliner {
fn before_render_page_body(&self, page: &mut Page) { fn before_render_page_body(&self, page: &mut Page) {
page.alter_assets(ContextOp::AddStyleSheet( page.alter_assets(AssetsOp::AddStyleSheet(
StyleSheet::from("/css/normalize.css") StyleSheet::from("/css/normalize.css")
.with_version("8.0.1") .with_version("8.0.1")
.with_weight(-99), .with_weight(-99),
)) ))
.alter_assets(ContextOp::AddStyleSheet( .alter_assets(AssetsOp::AddStyleSheet(
StyleSheet::from("/css/basic.css") StyleSheet::from("/css/basic.css")
.with_version(PAGETOP_VERSION) .with_version(PAGETOP_VERSION)
.with_weight(-99), .with_weight(-99),
)) ))
.alter_assets(ContextOp::AddStyleSheet( .alter_assets(AssetsOp::AddStyleSheet(
StyleSheet::from("/aliner/css/styles.css") StyleSheet::from("/aliner/css/styles.css")
.with_version(env!("CARGO_PKG_VERSION")) .with_version(env!("CARGO_PKG_VERSION"))
.with_weight(-99), .with_weight(-99),

View file

@ -151,12 +151,12 @@ impl Theme for Bootsier {
} }
fn before_render_page_body(&self, page: &mut Page) { 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") StyleSheet::from("/bootsier/bs/bootstrap.min.css")
.with_version(BOOTSTRAP_VERSION) .with_version(BOOTSTRAP_VERSION)
.with_weight(-90), .with_weight(-90),
)) ))
.alter_assets(ContextOp::AddJavaScript( .alter_assets(AssetsOp::AddJavaScript(
JavaScript::defer("/bootsier/js/bootstrap.bundle.min.js") JavaScript::defer("/bootsier/js/bootstrap.bundle.min.js")
.with_version(BOOTSTRAP_VERSION) .with_version(BOOTSTRAP_VERSION)
.with_weight(-90), .with_weight(-90),

View file

@ -110,14 +110,14 @@ impl Component for Intro {
} }
fn setup_before_prepare(&mut self, cx: &mut Context) { 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), StyleSheet::from("/css/intro.css").with_version(PAGETOP_VERSION),
)); ));
} }
fn prepare_component(&self, cx: &mut Context) -> Markup { fn prepare_component(&self, cx: &mut Context) -> Markup {
if *self.opening() == IntroOpening::PageTop { 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#" util::indoc!(r#"
try { try {
const resp = await fetch("https://crates.io/api/v1/crates/pagetop"); const resp = await fetch("https://crates.io/api/v1/crates/pagetop");

View file

@ -12,12 +12,12 @@ impl Extension for Basic {
impl Theme for Basic { impl Theme for Basic {
fn before_render_page_body(&self, page: &mut Page) { fn before_render_page_body(&self, page: &mut Page) {
page.alter_assets(ContextOp::AddStyleSheet( page.alter_assets(AssetsOp::AddStyleSheet(
StyleSheet::from("/css/normalize.css") StyleSheet::from("/css/normalize.css")
.with_version("8.0.1") .with_version("8.0.1")
.with_weight(-99), .with_weight(-99),
)) ))
.alter_assets(ContextOp::AddStyleSheet( .alter_assets(AssetsOp::AddStyleSheet(
StyleSheet::from("/css/basic.css") StyleSheet::from("/css/basic.css")
.with_version(PAGETOP_VERSION) .with_version(PAGETOP_VERSION)
.with_weight(-99), .with_weight(-99),

View file

@ -11,7 +11,7 @@ pub use children::{Child, ChildOp};
pub use children::{Typed, TypedOp}; pub use children::{Typed, TypedOp};
mod context; 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**. /// Alias de función (*callback*) para **determinar si un componente se renderiza o no**.
/// ///

View file

@ -13,7 +13,7 @@ use std::collections::HashMap;
use std::fmt; use std::fmt;
/// Operaciones para modificar recursos asociados al [`Context`] de un documento. /// 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. /// Define el *favicon* del documento. Sobrescribe cualquier valor anterior.
SetFavicon(Option<Favicon>), SetFavicon(Option<Favicon>),
/// Define el *favicon* solo si no se ha establecido previamente. /// 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. /// - Almacenar la **petición HTTP** de origen.
/// - Seleccionar el **tema** y la **plantilla** de renderizado. /// - Seleccionar el **tema** y la **plantilla** de renderizado.
/// - Administrar **recursos** del documento como el icono [`Favicon`], las hojas de estilo /// - 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. /// - Leer y mantener **parámetros dinámicos tipados** de contexto.
/// - Generar **identificadores únicos** por tipo de componente. /// - Generar **identificadores únicos** por tipo de componente.
/// ///
@ -89,9 +89,9 @@ impl std::error::Error for ContextError {}
/// cx.with_langid(&Locale::resolve("es-ES")) /// cx.with_langid(&Locale::resolve("es-ES"))
/// .with_theme(&Aliner) /// .with_theme(&Aliner)
/// .with_template(&DefaultTemplate::Standard) /// .with_template(&DefaultTemplate::Standard)
/// .with_assets(ContextOp::SetFavicon(Some(Favicon::new().with_icon("/favicon.ico")))) /// .with_assets(AssetsOp::SetFavicon(Some(Favicon::new().with_icon("/favicon.ico"))))
/// .with_assets(ContextOp::AddStyleSheet(StyleSheet::from("/css/app.css"))) /// .with_assets(AssetsOp::AddStyleSheet(StyleSheet::from("/css/app.css")))
/// .with_assets(ContextOp::AddJavaScript(JavaScript::defer("/js/app.js"))) /// .with_assets(AssetsOp::AddJavaScript(JavaScript::defer("/js/app.js")))
/// .with_param("usuario_id", 42_i32) /// .with_param("usuario_id", 42_i32)
/// } /// }
/// ``` /// ```
@ -118,9 +118,9 @@ pub trait Contextual: LangId {
#[builder_fn] #[builder_fn]
fn with_param<T: 'static>(self, key: &'static str, value: T) -> Self; 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] #[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. /// Opera con [`ChildOp`] en una región del documento.
#[builder_fn] #[builder_fn]
@ -194,11 +194,11 @@ pub trait Contextual: LangId {
/// // Establece el tema para renderizar. /// // Establece el tema para renderizar.
/// .with_theme(&Aliner) /// .with_theme(&Aliner)
/// // Asigna un favicon. /// // 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. /// // 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. /// // 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. /// // Añade un parámetro dinámico al contexto.
/// .with_param("usuario_id", 42) /// .with_param("usuario_id", 42)
/// } /// }
@ -471,29 +471,29 @@ impl Contextual for Context {
} }
#[builder_fn] #[builder_fn]
fn with_assets(mut self, op: ContextOp) -> Self { fn with_assets(mut self, op: AssetsOp) -> Self {
match op { match op {
// Favicon. // Favicon.
ContextOp::SetFavicon(favicon) => { AssetsOp::SetFavicon(favicon) => {
self.favicon = favicon; self.favicon = favicon;
} }
ContextOp::SetFaviconIfNone(icon) => { AssetsOp::SetFaviconIfNone(icon) => {
if self.favicon.is_none() { if self.favicon.is_none() {
self.favicon = Some(icon); self.favicon = Some(icon);
} }
} }
// Stylesheets. // Stylesheets.
ContextOp::AddStyleSheet(css) => { AssetsOp::AddStyleSheet(css) => {
self.stylesheets.add(css); self.stylesheets.add(css);
} }
ContextOp::RemoveStyleSheet(path) => { AssetsOp::RemoveStyleSheet(path) => {
self.stylesheets.remove(path); self.stylesheets.remove(path);
} }
// Scripts JavaScript. // Scripts JavaScript.
ContextOp::AddJavaScript(js) => { AssetsOp::AddJavaScript(js) => {
self.javascripts.add(js); self.javascripts.add(js);
} }
ContextOp::RemoveJavaScript(path) => { AssetsOp::RemoveJavaScript(path) => {
self.javascripts.remove(path); self.javascripts.remove(path);
} }
} }

View file

@ -117,13 +117,13 @@ use std::ops::Deref;
/// impl Theme for MyTheme { /// impl Theme for MyTheme {
/// fn before_render_page_body(&self, page: &mut Page) { /// fn before_render_page_body(&self, page: &mut Page) {
/// page /// page
/// .alter_assets(ContextOp::AddStyleSheet( /// .alter_assets(AssetsOp::AddStyleSheet(
/// StyleSheet::from("/css/normalize.css").with_version("8.0.1"), /// 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), /// 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")), /// StyleSheet::from("/mytheme/styles.css").with_version(env!("CARGO_PKG_VERSION")),
/// )); /// ));
/// } /// }

View file

@ -19,8 +19,8 @@ pub use error::ErrorPage;
pub use actix_web::Result as ResultPage; pub use actix_web::Result as ResultPage;
use crate::base::action; use crate::base::action;
use crate::core::component::{AssetsOp, Context, Contextual};
use crate::core::component::{Child, ChildOp, Component}; 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::core::theme::{DefaultRegion, Region, RegionRef, TemplateRef, ThemeRef};
use crate::html::{html, Markup, DOCTYPE}; use crate::html::{html, Markup, DOCTYPE};
use crate::html::{Assets, Favicon, JavaScript, StyleSheet}; use crate::html::{Assets, Favicon, JavaScript, StyleSheet};
@ -334,7 +334,7 @@ impl Contextual for Page {
} }
#[builder_fn] #[builder_fn]
fn with_assets(mut self, op: ContextOp) -> Self { fn with_assets(mut self, op: AssetsOp) -> Self {
self.context.alter_assets(op); self.context.alter_assets(op);
self self
} }