From de06afce65c5ec4b4a2e51a94d9bec7edceda27e Mon Sep 17 00:00:00 2001 From: Manuel Cillero Date: Tue, 30 Sep 2025 20:21:06 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=9A=20Renombra=20`AssetsOp`=20por=20`C?= =?UTF-8?q?ontextOp`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/base/theme/basic.rs | 14 +++++++------- src/html.rs | 3 ++- src/html/context.rs | 40 ++++++++++++++++++++++------------------ src/response/page.rs | 4 ++-- 4 files changed, 33 insertions(+), 28 deletions(-) diff --git a/src/base/theme/basic.rs b/src/base/theme/basic.rs index 20f5199..ecd6485 100644 --- a/src/base/theme/basic.rs +++ b/src/base/theme/basic.rs @@ -52,32 +52,32 @@ impl Theme for Basic { _ => "/css/basic.css", }; let pkg_version = env!("CARGO_PKG_VERSION"); - page.alter_assets(AssetsOp::AddStyleSheet( + page.alter_assets(ContextOp::AddStyleSheet( StyleSheet::from("/css/normalize.css") .with_version("8.0.1") .with_weight(-99), )) - .alter_assets(AssetsOp::AddStyleSheet( + .alter_assets(ContextOp::AddStyleSheet( StyleSheet::from("/css/root.css") .with_version(pkg_version) .with_weight(-99), )) - .alter_assets(AssetsOp::AddStyleSheet( + .alter_assets(ContextOp::AddStyleSheet( StyleSheet::from("/css/components.css") .with_version(pkg_version) .with_weight(-99), )) - .alter_assets(AssetsOp::AddStyleSheet( + .alter_assets(ContextOp::AddStyleSheet( StyleSheet::from("/css/menu.css") .with_version(pkg_version) .with_weight(-99), )) - .alter_assets(AssetsOp::AddStyleSheet( + .alter_assets(ContextOp::AddStyleSheet( StyleSheet::from(styles) .with_version(pkg_version) .with_weight(-99), )) - .alter_assets(AssetsOp::AddJavaScript( + .alter_assets(ContextOp::AddJavaScript( JavaScript::defer("/js/menu.js") .with_version(pkg_version) .with_weight(-99), @@ -169,7 +169,7 @@ fn render_intro(page: &mut Page) -> Markup { } fn render_pagetop_intro(page: &mut Page) -> Markup { - page.alter_assets(AssetsOp::AddJavaScript(JavaScript::on_load_async("intro-js", |cx| + page.alter_assets(ContextOp::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/html.rs b/src/html.rs index c4195a9..679d433 100644 --- a/src/html.rs +++ b/src/html.rs @@ -14,7 +14,8 @@ pub use assets::{Asset, Assets}; // **< HTML DOCUMENT CONTEXT >********************************************************************** mod context; -pub use context::{AssetsOp, Context, Contextual, ErrorParam}; +#[allow(deprecated)] +pub use context::{AssetsOp, Context, ContextOp, Contextual, ErrorParam}; pub type FnPathByContext = fn(cx: &Context) -> &str; // **< HTML ATTRIBUTES >**************************************************************************** diff --git a/src/html/context.rs b/src/html/context.rs index 355ccea..94f24bf 100644 --- a/src/html/context.rs +++ b/src/html/context.rs @@ -10,8 +10,12 @@ use crate::{builder_fn, join}; use std::any::Any; use std::collections::HashMap; -/// Operaciones para modificar el contexto ([`Context`]) de un documento. -pub enum AssetsOp { +/// **Obsoleto desde la versión 0.4.0**: usar [`ContextOp`] en su lugar. +#[deprecated(since = "0.5.0", note = "Use `ContextOp` instead")] +pub type AssetsOp = ContextOp; + +/// Operaciones para modificar los recursos asociados al contexto ([`Context`]) de un documento. +pub enum ContextOp { // Favicon. /// Define el *favicon* del documento. Sobrescribe cualquier valor anterior. SetFavicon(Option), @@ -55,7 +59,7 @@ pub enum ErrorParam { /// - Almacenar la **solicitud HTTP** de origen. /// - Seleccionar **tema** y **composición** (*layout*) de renderizado. /// - Administrar **recursos** del documento como el icono [`Favicon`], las hojas de estilo -/// [`StyleSheet`] o los scripts [`JavaScript`] mediante [`AssetsOp`]. +/// [`StyleSheet`] o los scripts [`JavaScript`] mediante [`ContextOp`]. /// - Leer y mantener **parámetros dinámicos tipados** de contexto. /// - Generar **identificadores únicos** por tipo de componente. /// @@ -71,9 +75,9 @@ pub enum ErrorParam { /// cx.with_langid(&LangMatch::resolve("es-ES")) /// .with_theme("aliner") /// .with_layout("default") -/// .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_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_param("usuario_id", 42_i32) /// } /// ``` @@ -100,9 +104,9 @@ pub trait Contextual: LangId { #[builder_fn] fn with_param(self, key: &'static str, value: T) -> Self; - /// Define los recursos del contexto usando [`AssetsOp`]. + /// Define los recursos del contexto usando [`ContextOp`]. #[builder_fn] - fn with_assets(self, op: AssetsOp) -> Self; + fn with_assets(self, op: ContextOp) -> Self; // **< Contextual GETTERS >********************************************************************* @@ -172,11 +176,11 @@ pub trait Contextual: LangId { /// // Selecciona un tema (por su nombre corto). /// .with_theme("aliner") /// // Asigna un favicon. -/// .with_assets(AssetsOp::SetFavicon(Some(Favicon::new().with_icon("/favicon.ico")))) +/// .with_assets(ContextOp::SetFavicon(Some(Favicon::new().with_icon("/favicon.ico")))) /// // Añade una hoja de estilo externa. -/// .with_assets(AssetsOp::AddStyleSheet(StyleSheet::from("/css/style.css"))) +/// .with_assets(ContextOp::AddStyleSheet(StyleSheet::from("/css/style.css"))) /// // Añade un script JavaScript. -/// .with_assets(AssetsOp::AddJavaScript(JavaScript::defer("/js/main.js"))) +/// .with_assets(ContextOp::AddJavaScript(JavaScript::defer("/js/main.js"))) /// // Añade un parámetro dinámico al contexto. /// .with_param("usuario_id", 42) /// } @@ -442,29 +446,29 @@ impl Contextual for Context { } #[builder_fn] - fn with_assets(mut self, op: AssetsOp) -> Self { + fn with_assets(mut self, op: ContextOp) -> Self { match op { // Favicon. - AssetsOp::SetFavicon(favicon) => { + ContextOp::SetFavicon(favicon) => { self.favicon = favicon; } - AssetsOp::SetFaviconIfNone(icon) => { + ContextOp::SetFaviconIfNone(icon) => { if self.favicon.is_none() { self.favicon = Some(icon); } } // Stylesheets. - AssetsOp::AddStyleSheet(css) => { + ContextOp::AddStyleSheet(css) => { self.stylesheets.add(css); } - AssetsOp::RemoveStyleSheet(path) => { + ContextOp::RemoveStyleSheet(path) => { self.stylesheets.remove(path); } // JavaScripts. - AssetsOp::AddJavaScript(js) => { + ContextOp::AddJavaScript(js) => { self.javascripts.add(js); } - AssetsOp::RemoveJavaScript(path) => { + ContextOp::RemoveJavaScript(path) => { self.javascripts.remove(path); } } diff --git a/src/response/page.rs b/src/response/page.rs index e9d3067..135ab19 100644 --- a/src/response/page.rs +++ b/src/response/page.rs @@ -8,9 +8,9 @@ use crate::core::component::{Child, ChildOp, Component}; use crate::core::theme::{ChildrenInRegions, ThemeRef, REGION_CONTENT}; use crate::html::{html, Markup, DOCTYPE}; use crate::html::{Assets, Favicon, JavaScript, StyleSheet}; -use crate::html::{AssetsOp, Context, Contextual}; use crate::html::{AttrClasses, ClassesOp}; use crate::html::{AttrId, AttrL10n}; +use crate::html::{Context, ContextOp, Contextual}; use crate::locale::{CharacterDirection, L10n, LangId, LanguageIdentifier}; use crate::service::HttpRequest; use crate::{builder_fn, AutoDefault}; @@ -286,7 +286,7 @@ impl Contextual for Page { } #[builder_fn] - fn with_assets(mut self, op: AssetsOp) -> Self { + fn with_assets(mut self, op: ContextOp) -> Self { self.context.alter_assets(op); self }