(base): Añade componente Pager

Incluye soporte HTMX vía `sort_link()`/`hx_pager` para navegación sin
recarga.
This commit is contained in:
Manuel Cillero 2026-08-06 22:37:28 +02:00
parent e8bba0803d
commit 3b01894024
14 changed files with 881 additions and 31 deletions

View file

@ -73,9 +73,9 @@ impl RoutePath {
/// Un `value` vacío no se distingue de [`with_flag()`](Self::with_flag): ambos se renderizan
/// como `?key`, sin `=`.
#[builder_fn]
pub fn with_param(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
pub fn with_param(mut self, key: impl Into<String>, value: impl AsRef<str>) -> Self {
self.query
.insert(key.into(), Self::encode_query_value(&value.into()));
.insert(key.into(), Self::encode_query_value(value.as_ref()));
self
}
@ -91,6 +91,16 @@ impl RoutePath {
&self.path
}
/// Devuelve el valor de un parámetro de consulta ya almacenado, si existe.
///
/// El valor se devuelve tal como se almacenó, es decir, ya codificado según RFC 3986 (ver
/// [`with_param()`](Self::with_param)). Para valores que sólo usen caracteres sin reservar
/// (letras, dígitos, `-`, `_`, `.`, `~`), como un identificador de idioma BCP 47, no hay
/// diferencia con el valor original.
pub fn param(&self, key: impl AsRef<str>) -> Option<&str> {
self.query.get(key.as_ref()).map(String::as_str)
}
/// Indica si el *path* **parece** una URL externa por su prefijo (ver
/// [`util::url_looks_external()`](crate::util::url_looks_external)).
pub fn is_external(&self) -> bool {

View file

@ -99,9 +99,25 @@ impl SortDir {
}
}
/// Permite pasar un [`SortDir`] allí donde se espere `impl AsRef<str>`, por ejemplo, en el
/// parámetro `value` de [`RoutePath::with_param()`](crate::html::RoutePath::with_param) o su
/// equivalente `alter_param()`, sin tener que escribir `.as_str()` a mano.
///
/// ```rust
/// use pagetop::html::SortDir;
///
/// assert_eq!(SortDir::Asc.as_ref(), "asc");
/// assert_eq!(SortDir::Desc.as_ref(), "desc");
/// ```
impl AsRef<str> for SortDir {
fn as_ref(&self) -> &str {
self.as_str()
}
}
/// Permite pasar un [`SortDir`] allí donde se espere `impl Into<String>`, por ejemplo, en
/// [`RoutePath::with_param()`](crate::html::RoutePath::with_param) o su equivalente
/// `alter_param()`, sin tener que escribir `as_str().to_owned()` a mano.
/// [`Pager::with_extra_query()`](crate::base::component::Pager::with_extra_query), sin tener que
/// escribir `as_str().to_owned()` a mano.
///
/// ```rust
/// use pagetop::html::SortDir;