Compare commits
No commits in common. "8912bbc8ec83f16892b759ed0703c25e85dc57c9" and "de06afce65c5ec4b4a2e51a94d9bec7edceda27e" have entirely different histories.
8912bbc8ec
...
de06afce65
13 changed files with 44 additions and 79 deletions
|
|
@ -7,7 +7,3 @@ mod children;
|
|||
pub use children::Children;
|
||||
pub use children::{Child, ChildOp};
|
||||
pub use children::{Typed, TypedOp};
|
||||
|
||||
mod context;
|
||||
pub use context::{Context, ContextError, ContextOp, Contextual};
|
||||
pub type FnPathByContext = fn(cx: &Context) -> &str;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use crate::core::component::{Component, Context};
|
||||
use crate::html::{html, Markup};
|
||||
use crate::core::component::Component;
|
||||
use crate::html::{html, Context, Markup};
|
||||
use crate::{builder_fn, AutoDefault, UniqueId};
|
||||
|
||||
use parking_lot::RwLock;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
use crate::base::action;
|
||||
use crate::core::component::Context;
|
||||
use crate::core::{AnyInfo, TypeInfo};
|
||||
use crate::html::{html, Markup, PrepareMarkup};
|
||||
use crate::html::{html, Context, Markup, PrepareMarkup};
|
||||
|
||||
/// Define la función de renderizado para todos los componentes.
|
||||
///
|
||||
|
|
|
|||
|
|
@ -50,11 +50,11 @@ pub struct App {
|
|||
pub theme: String,
|
||||
/// Idioma por defecto para la aplicación.
|
||||
///
|
||||
/// Si no está definido o no es válido, [`LangId`](crate::locale::LangId) determinará el idioma
|
||||
/// efectivo para el renderizado en este orden: primero intentará usar el establecido mediante
|
||||
/// [`Contextual::with_langid()`](crate::core::component::Contextual::with_langid); si no se ha
|
||||
/// definido explícitamente, probará el indicado en la cabecera `Accept-Language` del navegador;
|
||||
/// y, si ninguno aplica, se empleará el idioma de respaldo ("en-US").
|
||||
/// Si no está definido o no es válido, el idioma efectivo para el renderizado se resolverá
|
||||
/// según la implementación de [`LangId`](crate::locale::LangId) en este orden: primero intenta
|
||||
/// con el establecido en [`Contextual::with_langid()`](crate::html::Contextual::with_langid);
|
||||
/// pero si no se ha definido explícitamente, usará el indicado en la cabecera `Accept-Language`
|
||||
/// del navegador; y, si ninguno aplica, se empleará el idioma de respaldo ("en-US").
|
||||
pub language: String,
|
||||
/// Banner ASCII mostrado al inicio: *"Off"* (desactivado), *"Slant"*, *"Small"*, *"Speed"* o
|
||||
/// *"Starwars"*.
|
||||
|
|
|
|||
32
src/html.rs
32
src/html.rs
|
|
@ -13,34 +13,10 @@ pub use assets::{Asset, Assets};
|
|||
|
||||
// **< HTML DOCUMENT CONTEXT >**********************************************************************
|
||||
|
||||
/// **Obsoleto desde la versión 0.5.0**: usar [`core::component::Context`] en su lugar.
|
||||
#[deprecated(since = "0.5.0", note = "Moved to `pagetop::core::component::Context`")]
|
||||
pub type Context = crate::core::component::Context;
|
||||
|
||||
/// **Obsoleto desde la versión 0.5.0**: usar [`core::component::ContextOp`] en su lugar.
|
||||
#[deprecated(
|
||||
since = "0.5.0",
|
||||
note = "Moved to `pagetop::core::component::ContextOp`"
|
||||
)]
|
||||
pub type ContextOp = crate::core::component::ContextOp;
|
||||
|
||||
/// **Obsoleto desde la versión 0.5.0**: usar [`core::component::Contextual`] en su lugar.
|
||||
#[deprecated(
|
||||
since = "0.5.0",
|
||||
note = "Moved to `pagetop::core::component::Contextual`"
|
||||
)]
|
||||
pub trait Contextual: crate::core::component::Contextual {}
|
||||
|
||||
/// **Obsoleto desde la versión 0.5.0**: usar [`core::component::ContextError`] en su lugar.
|
||||
#[deprecated(
|
||||
since = "0.5.0",
|
||||
note = "Moved to `pagetop::core::component::ContextError`"
|
||||
)]
|
||||
pub type ContextError = crate::core::component::ContextError;
|
||||
|
||||
/// **Obsoleto desde la versión 0.5.0**: usar [`ContextOp`] en su lugar.
|
||||
#[deprecated(since = "0.5.0", note = "Use `ContextOp` instead")]
|
||||
pub type AssetsOp = crate::core::component::ContextOp;
|
||||
mod context;
|
||||
#[allow(deprecated)]
|
||||
pub use context::{AssetsOp, Context, ContextOp, Contextual, ErrorParam};
|
||||
pub type FnPathByContext = fn(cx: &Context) -> &str;
|
||||
|
||||
// **< HTML ATTRIBUTES >****************************************************************************
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@ pub mod favicon;
|
|||
pub mod javascript;
|
||||
pub mod stylesheet;
|
||||
|
||||
use crate::core::component::Context;
|
||||
use crate::html::{html, Markup};
|
||||
use crate::html::{html, Context, Markup};
|
||||
use crate::{AutoDefault, Weight};
|
||||
|
||||
/// Representación genérica de un script [`JavaScript`](crate::html::JavaScript) o una hoja de
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
use crate::core::component::Context;
|
||||
use crate::html::{html, Markup};
|
||||
use crate::html::{html, Context, Markup};
|
||||
use crate::AutoDefault;
|
||||
|
||||
/// Un **Favicon** es un recurso gráfico que usa el navegador como icono asociado al sitio.
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
use crate::core::component::Context;
|
||||
use crate::html::assets::Asset;
|
||||
use crate::html::{html, Markup, PreEscaped};
|
||||
use crate::html::{html, Context, Markup, PreEscaped};
|
||||
use crate::{join, join_pair, AutoDefault, Weight};
|
||||
|
||||
// Define el origen del recurso JavaScript y cómo debe cargarse en el navegador.
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
use crate::core::component::Context;
|
||||
use crate::html::assets::Asset;
|
||||
use crate::html::{html, Markup, PreEscaped};
|
||||
use crate::html::{html, Context, Markup, PreEscaped};
|
||||
use crate::{join_pair, AutoDefault, Weight};
|
||||
|
||||
// Define el origen del recurso CSS y cómo se incluye en el documento.
|
||||
|
|
|
|||
|
|
@ -10,7 +10,11 @@ use crate::{builder_fn, join};
|
|||
use std::any::Any;
|
||||
use std::collections::HashMap;
|
||||
|
||||
/// Operaciones para modificar recursos asociados al contexto ([`Context`]) de un documento.
|
||||
/// **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.
|
||||
|
|
@ -33,14 +37,14 @@ pub enum ContextOp {
|
|||
|
||||
/// Errores de acceso a parámetros dinámicos del contexto.
|
||||
///
|
||||
/// - [`ContextError::ParamNotFound`]: la clave no existe.
|
||||
/// - [`ContextError::ParamTypeMismatch`]: la clave existe, pero el valor guardado no coincide con
|
||||
/// el tipo solicitado. Incluye nombre de la clave (`key`), tipo esperado (`expected`) y tipo
|
||||
/// realmente guardado (`saved`) para facilitar el diagnóstico.
|
||||
/// - [`ErrorParam::NotFound`]: la clave no existe.
|
||||
/// - [`ErrorParam::TypeMismatch`]: la clave existe, pero el valor guardado no coincide con el tipo
|
||||
/// solicitado. Incluye nombre de la clave (`key`), tipo esperado (`expected`) y tipo realmente
|
||||
/// guardado (`saved`) para facilitar el diagnóstico.
|
||||
#[derive(Debug)]
|
||||
pub enum ContextError {
|
||||
ParamNotFound,
|
||||
ParamTypeMismatch {
|
||||
pub enum ErrorParam {
|
||||
NotFound,
|
||||
TypeMismatch {
|
||||
key: &'static str,
|
||||
expected: &'static str,
|
||||
saved: &'static str,
|
||||
|
|
@ -60,7 +64,7 @@ pub enum ContextError {
|
|||
/// - Generar **identificadores únicos** por tipo de componente.
|
||||
///
|
||||
/// Lo implementan, típicamente, estructuras que representan el contexto de renderizado, como
|
||||
/// [`Context`](crate::core::component::Context) o [`Page`](crate::response::page::Page).
|
||||
/// [`Context`](crate::html::Context) o [`Page`](crate::response::page::Page).
|
||||
///
|
||||
/// # Ejemplo
|
||||
///
|
||||
|
|
@ -290,8 +294,8 @@ impl Context {
|
|||
/// Devuelve:
|
||||
///
|
||||
/// - `Ok(&T)` si la clave existe y el tipo coincide.
|
||||
/// - `Err(ContextError::ParamNotFound)` si la clave no existe.
|
||||
/// - `Err(ContextError::ParamTypeMismatch)` si la clave existe pero el tipo no coincide.
|
||||
/// - `Err(ErrorParam::NotFound)` si la clave no existe.
|
||||
/// - `Err(ErrorParam::TypeMismatch)` si la clave existe pero el tipo no coincide.
|
||||
///
|
||||
/// # Ejemplos
|
||||
///
|
||||
|
|
@ -308,10 +312,10 @@ impl Context {
|
|||
/// // Error de tipo:
|
||||
/// assert!(cx.get_param::<String>("usuario_id").is_err());
|
||||
/// ```
|
||||
pub fn get_param<T: 'static>(&self, key: &'static str) -> Result<&T, ContextError> {
|
||||
let (any, type_name) = self.params.get(key).ok_or(ContextError::ParamNotFound)?;
|
||||
pub fn get_param<T: 'static>(&self, key: &'static str) -> Result<&T, ErrorParam> {
|
||||
let (any, type_name) = self.params.get(key).ok_or(ErrorParam::NotFound)?;
|
||||
any.downcast_ref::<T>()
|
||||
.ok_or_else(|| ContextError::ParamTypeMismatch {
|
||||
.ok_or_else(|| ErrorParam::TypeMismatch {
|
||||
key,
|
||||
expected: TypeInfo::FullName.of::<T>(),
|
||||
saved: type_name,
|
||||
|
|
@ -323,8 +327,8 @@ impl Context {
|
|||
/// Devuelve:
|
||||
///
|
||||
/// - `Ok(T)` si la clave existía y el tipo coincide.
|
||||
/// - `Err(ContextError::ParamNotFound)` si la clave no existe.
|
||||
/// - `Err(ContextError::ParamTypeMismatch)` si el tipo no coincide.
|
||||
/// - `Err(ErrorParam::NotFound)` si la clave no existe.
|
||||
/// - `Err(ErrorParam::TypeMismatch)` si el tipo no coincide.
|
||||
///
|
||||
/// # Ejemplos
|
||||
///
|
||||
|
|
@ -341,12 +345,12 @@ impl Context {
|
|||
/// // Error de tipo:
|
||||
/// assert!(cx.take_param::<i32>("titulo").is_err());
|
||||
/// ```
|
||||
pub fn take_param<T: 'static>(&mut self, key: &'static str) -> Result<T, ContextError> {
|
||||
let (boxed, saved) = self.params.remove(key).ok_or(ContextError::ParamNotFound)?;
|
||||
pub fn take_param<T: 'static>(&mut self, key: &'static str) -> Result<T, ErrorParam> {
|
||||
let (boxed, saved) = self.params.remove(key).ok_or(ErrorParam::NotFound)?;
|
||||
boxed
|
||||
.downcast::<T>()
|
||||
.map(|b| *b)
|
||||
.map_err(|_| ContextError::ParamTypeMismatch {
|
||||
.map_err(|_| ErrorParam::TypeMismatch {
|
||||
key,
|
||||
expected: TypeInfo::FullName.of::<T>(),
|
||||
saved,
|
||||
|
|
@ -371,7 +375,7 @@ impl Context {
|
|||
}
|
||||
}
|
||||
|
||||
/// Permite a [`Context`](crate::core::component::Context) actuar como proveedor de idioma.
|
||||
/// Permite a [`Context`](crate::html::Context) actuar como proveedor de idioma.
|
||||
///
|
||||
/// Devuelve un [`LanguageIdentifier`] siguiendo este orden de prioridad:
|
||||
///
|
||||
|
|
@ -28,14 +28,7 @@ pub use crate::global;
|
|||
|
||||
pub use crate::trace;
|
||||
|
||||
// No se usa `pub use crate::html::*;` para evitar duplicar alias marcados como obsoletos
|
||||
// (*deprecated*) porque han sido trasladados a `crate::core::component`. Cuando se retiren estos
|
||||
// alias obsoletos se volverá a declarar como `pub use crate::html::*;`.
|
||||
pub use crate::html::{
|
||||
display, html_private, Asset, Assets, AttrClasses, AttrId, AttrL10n, AttrName, AttrValue,
|
||||
ClassesOp, Escaper, Favicon, JavaScript, Markup, PreEscaped, PrepareMarkup, StyleSheet,
|
||||
TargetMedia, DOCTYPE,
|
||||
};
|
||||
pub use crate::html::*;
|
||||
|
||||
pub use crate::locale::*;
|
||||
|
||||
|
|
|
|||
|
|
@ -4,12 +4,13 @@ pub use error::ErrorPage;
|
|||
pub use actix_web::Result as ResultPage;
|
||||
|
||||
use crate::base::action;
|
||||
use crate::core::component::{Child, ChildOp, Component, Context, ContextOp, Contextual};
|
||||
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::{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};
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use crate::base::component::Html;
|
||||
use crate::core::component::Contextual;
|
||||
use crate::html::Contextual;
|
||||
use crate::locale::L10n;
|
||||
use crate::response::ResponseError;
|
||||
use crate::service::http::{header::ContentType, StatusCode};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue