From c3feff9efd5c5d01ce0845325a1266e89c7a2b9c Mon Sep 17 00:00:00 2001 From: Manuel Cillero Date: Sat, 21 Mar 2026 11:12:46 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=9A=20Renombra=20`ContextOp`=20a=20`As?= =?UTF-8?q?setsOp`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- extensions/pagetop-aliner/src/lib.rs | 6 ++--- extensions/pagetop-bootsier/src/lib.rs | 4 +-- src/base/component/intro.rs | 4 +-- src/base/theme/basic.rs | 4 +-- src/core/component.rs | 2 +- src/core/component/context.rs | 34 +++++++++++++------------- src/lib.rs | 6 ++--- src/response/page.rs | 4 +-- 8 files changed, 32 insertions(+), 32 deletions(-) diff --git a/extensions/pagetop-aliner/src/lib.rs b/extensions/pagetop-aliner/src/lib.rs index 04b5ad1a..30621b21 100644 --- a/extensions/pagetop-aliner/src/lib.rs +++ b/extensions/pagetop-aliner/src/lib.rs @@ -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), diff --git a/extensions/pagetop-bootsier/src/lib.rs b/extensions/pagetop-bootsier/src/lib.rs index 5c88959a..0281fe7a 100644 --- a/extensions/pagetop-bootsier/src/lib.rs +++ b/extensions/pagetop-bootsier/src/lib.rs @@ -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), diff --git a/src/base/component/intro.rs b/src/base/component/intro.rs index 793ad8b7..fd68d2bc 100644 --- a/src/base/component/intro.rs +++ b/src/base/component/intro.rs @@ -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"); diff --git a/src/base/theme/basic.rs b/src/base/theme/basic.rs index ca3c4a82..858f5d2b 100644 --- a/src/base/theme/basic.rs +++ b/src/base/theme/basic.rs @@ -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), diff --git a/src/core/component.rs b/src/core/component.rs index 0eb347e5..79d524cc 100644 --- a/src/core/component.rs +++ b/src/core/component.rs @@ -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**. /// diff --git a/src/core/component/context.rs b/src/core/component/context.rs index 3e159c26..e2a220b7 100644 --- a/src/core/component/context.rs +++ b/src/core/component/context.rs @@ -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), /// 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(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); } } diff --git a/src/lib.rs b/src/lib.rs index 6369df88..6ee31d60 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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")), /// )); /// } diff --git a/src/response/page.rs b/src/response/page.rs index 83fe00ba..5af063e4 100644 --- a/src/response/page.rs +++ b/src/response/page.rs @@ -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 }