🚚 Renombra AssetsOp
por ContextOp
This commit is contained in:
parent
423b30475b
commit
de06afce65
4 changed files with 33 additions and 28 deletions
|
@ -52,32 +52,32 @@ impl Theme for Basic {
|
||||||
_ => "/css/basic.css",
|
_ => "/css/basic.css",
|
||||||
};
|
};
|
||||||
let pkg_version = env!("CARGO_PKG_VERSION");
|
let pkg_version = env!("CARGO_PKG_VERSION");
|
||||||
page.alter_assets(AssetsOp::AddStyleSheet(
|
page.alter_assets(ContextOp::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(AssetsOp::AddStyleSheet(
|
.alter_assets(ContextOp::AddStyleSheet(
|
||||||
StyleSheet::from("/css/root.css")
|
StyleSheet::from("/css/root.css")
|
||||||
.with_version(pkg_version)
|
.with_version(pkg_version)
|
||||||
.with_weight(-99),
|
.with_weight(-99),
|
||||||
))
|
))
|
||||||
.alter_assets(AssetsOp::AddStyleSheet(
|
.alter_assets(ContextOp::AddStyleSheet(
|
||||||
StyleSheet::from("/css/components.css")
|
StyleSheet::from("/css/components.css")
|
||||||
.with_version(pkg_version)
|
.with_version(pkg_version)
|
||||||
.with_weight(-99),
|
.with_weight(-99),
|
||||||
))
|
))
|
||||||
.alter_assets(AssetsOp::AddStyleSheet(
|
.alter_assets(ContextOp::AddStyleSheet(
|
||||||
StyleSheet::from("/css/menu.css")
|
StyleSheet::from("/css/menu.css")
|
||||||
.with_version(pkg_version)
|
.with_version(pkg_version)
|
||||||
.with_weight(-99),
|
.with_weight(-99),
|
||||||
))
|
))
|
||||||
.alter_assets(AssetsOp::AddStyleSheet(
|
.alter_assets(ContextOp::AddStyleSheet(
|
||||||
StyleSheet::from(styles)
|
StyleSheet::from(styles)
|
||||||
.with_version(pkg_version)
|
.with_version(pkg_version)
|
||||||
.with_weight(-99),
|
.with_weight(-99),
|
||||||
))
|
))
|
||||||
.alter_assets(AssetsOp::AddJavaScript(
|
.alter_assets(ContextOp::AddJavaScript(
|
||||||
JavaScript::defer("/js/menu.js")
|
JavaScript::defer("/js/menu.js")
|
||||||
.with_version(pkg_version)
|
.with_version(pkg_version)
|
||||||
.with_weight(-99),
|
.with_weight(-99),
|
||||||
|
@ -169,7 +169,7 @@ fn render_intro(page: &mut Page) -> Markup {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_pagetop_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#"
|
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");
|
||||||
|
|
|
@ -14,7 +14,8 @@ pub use assets::{Asset, Assets};
|
||||||
// **< HTML DOCUMENT CONTEXT >**********************************************************************
|
// **< HTML DOCUMENT CONTEXT >**********************************************************************
|
||||||
|
|
||||||
mod 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;
|
pub type FnPathByContext = fn(cx: &Context) -> &str;
|
||||||
|
|
||||||
// **< HTML ATTRIBUTES >****************************************************************************
|
// **< HTML ATTRIBUTES >****************************************************************************
|
||||||
|
|
|
@ -10,8 +10,12 @@ use crate::{builder_fn, join};
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
/// Operaciones para modificar el contexto ([`Context`]) de un documento.
|
/// **Obsoleto desde la versión 0.4.0**: usar [`ContextOp`] en su lugar.
|
||||||
pub enum AssetsOp {
|
#[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.
|
// Favicon.
|
||||||
/// Define el *favicon* del documento. Sobrescribe cualquier valor anterior.
|
/// Define el *favicon* del documento. Sobrescribe cualquier valor anterior.
|
||||||
SetFavicon(Option<Favicon>),
|
SetFavicon(Option<Favicon>),
|
||||||
|
@ -55,7 +59,7 @@ pub enum ErrorParam {
|
||||||
/// - Almacenar la **solicitud HTTP** de origen.
|
/// - Almacenar la **solicitud HTTP** de origen.
|
||||||
/// - Seleccionar **tema** y **composición** (*layout*) de renderizado.
|
/// - Seleccionar **tema** y **composición** (*layout*) 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 [`AssetsOp`].
|
/// [`StyleSheet`] o los scripts [`JavaScript`] mediante [`ContextOp`].
|
||||||
/// - 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.
|
||||||
///
|
///
|
||||||
|
@ -71,9 +75,9 @@ pub enum ErrorParam {
|
||||||
/// cx.with_langid(&LangMatch::resolve("es-ES"))
|
/// cx.with_langid(&LangMatch::resolve("es-ES"))
|
||||||
/// .with_theme("aliner")
|
/// .with_theme("aliner")
|
||||||
/// .with_layout("default")
|
/// .with_layout("default")
|
||||||
/// .with_assets(AssetsOp::SetFavicon(Some(Favicon::new().with_icon("/favicon.ico"))))
|
/// .with_assets(ContextOp::SetFavicon(Some(Favicon::new().with_icon("/favicon.ico"))))
|
||||||
/// .with_assets(AssetsOp::AddStyleSheet(StyleSheet::from("/css/app.css")))
|
/// .with_assets(ContextOp::AddStyleSheet(StyleSheet::from("/css/app.css")))
|
||||||
/// .with_assets(AssetsOp::AddJavaScript(JavaScript::defer("/js/app.js")))
|
/// .with_assets(ContextOp::AddJavaScript(JavaScript::defer("/js/app.js")))
|
||||||
/// .with_param("usuario_id", 42_i32)
|
/// .with_param("usuario_id", 42_i32)
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -100,9 +104,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 [`AssetsOp`].
|
/// Define los recursos del contexto usando [`ContextOp`].
|
||||||
#[builder_fn]
|
#[builder_fn]
|
||||||
fn with_assets(self, op: AssetsOp) -> Self;
|
fn with_assets(self, op: ContextOp) -> Self;
|
||||||
|
|
||||||
// **< Contextual GETTERS >*********************************************************************
|
// **< Contextual GETTERS >*********************************************************************
|
||||||
|
|
||||||
|
@ -172,11 +176,11 @@ pub trait Contextual: LangId {
|
||||||
/// // Selecciona un tema (por su nombre corto).
|
/// // Selecciona un tema (por su nombre corto).
|
||||||
/// .with_theme("aliner")
|
/// .with_theme("aliner")
|
||||||
/// // Asigna un favicon.
|
/// // 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.
|
/// // 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.
|
/// // 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.
|
/// // Añade un parámetro dinámico al contexto.
|
||||||
/// .with_param("usuario_id", 42)
|
/// .with_param("usuario_id", 42)
|
||||||
/// }
|
/// }
|
||||||
|
@ -442,29 +446,29 @@ impl Contextual for Context {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[builder_fn]
|
#[builder_fn]
|
||||||
fn with_assets(mut self, op: AssetsOp) -> Self {
|
fn with_assets(mut self, op: ContextOp) -> Self {
|
||||||
match op {
|
match op {
|
||||||
// Favicon.
|
// Favicon.
|
||||||
AssetsOp::SetFavicon(favicon) => {
|
ContextOp::SetFavicon(favicon) => {
|
||||||
self.favicon = favicon;
|
self.favicon = favicon;
|
||||||
}
|
}
|
||||||
AssetsOp::SetFaviconIfNone(icon) => {
|
ContextOp::SetFaviconIfNone(icon) => {
|
||||||
if self.favicon.is_none() {
|
if self.favicon.is_none() {
|
||||||
self.favicon = Some(icon);
|
self.favicon = Some(icon);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Stylesheets.
|
// Stylesheets.
|
||||||
AssetsOp::AddStyleSheet(css) => {
|
ContextOp::AddStyleSheet(css) => {
|
||||||
self.stylesheets.add(css);
|
self.stylesheets.add(css);
|
||||||
}
|
}
|
||||||
AssetsOp::RemoveStyleSheet(path) => {
|
ContextOp::RemoveStyleSheet(path) => {
|
||||||
self.stylesheets.remove(path);
|
self.stylesheets.remove(path);
|
||||||
}
|
}
|
||||||
// JavaScripts.
|
// JavaScripts.
|
||||||
AssetsOp::AddJavaScript(js) => {
|
ContextOp::AddJavaScript(js) => {
|
||||||
self.javascripts.add(js);
|
self.javascripts.add(js);
|
||||||
}
|
}
|
||||||
AssetsOp::RemoveJavaScript(path) => {
|
ContextOp::RemoveJavaScript(path) => {
|
||||||
self.javascripts.remove(path);
|
self.javascripts.remove(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,9 +8,9 @@ use crate::core::component::{Child, ChildOp, Component};
|
||||||
use crate::core::theme::{ChildrenInRegions, ThemeRef, REGION_CONTENT};
|
use crate::core::theme::{ChildrenInRegions, ThemeRef, REGION_CONTENT};
|
||||||
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};
|
||||||
use crate::html::{AssetsOp, Context, Contextual};
|
|
||||||
use crate::html::{AttrClasses, ClassesOp};
|
use crate::html::{AttrClasses, ClassesOp};
|
||||||
use crate::html::{AttrId, AttrL10n};
|
use crate::html::{AttrId, AttrL10n};
|
||||||
|
use crate::html::{Context, ContextOp, Contextual};
|
||||||
use crate::locale::{CharacterDirection, L10n, LangId, LanguageIdentifier};
|
use crate::locale::{CharacterDirection, L10n, LangId, LanguageIdentifier};
|
||||||
use crate::service::HttpRequest;
|
use crate::service::HttpRequest;
|
||||||
use crate::{builder_fn, AutoDefault};
|
use crate::{builder_fn, AutoDefault};
|
||||||
|
@ -286,7 +286,7 @@ impl Contextual for Page {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[builder_fn]
|
#[builder_fn]
|
||||||
fn with_assets(mut self, op: AssetsOp) -> Self {
|
fn with_assets(mut self, op: ContextOp) -> Self {
|
||||||
self.context.alter_assets(op);
|
self.context.alter_assets(op);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue