♻️ Cambia Self::default() por Tipo::default()

This commit is contained in:
Manuel Cillero 2025-12-28 13:18:18 +01:00
parent 47c47ba9a0
commit 25d32ec5de
21 changed files with 69 additions and 68 deletions

View file

@ -22,7 +22,7 @@ pub struct Container {
impl Component for Container {
fn new() -> Self {
Container::default()
Self::default()
}
fn id(&self) -> Option<String> {
@ -82,7 +82,7 @@ impl Component for Container {
impl Container {
/// Crea un contenedor de tipo `Main` (`<main>`).
pub fn main() -> Self {
Container {
Self {
container_kind: container::Kind::Main,
..Default::default()
}
@ -90,7 +90,7 @@ impl Container {
/// Crea un contenedor de tipo `Header` (`<header>`).
pub fn header() -> Self {
Container {
Self {
container_kind: container::Kind::Header,
..Default::default()
}
@ -98,7 +98,7 @@ impl Container {
/// Crea un contenedor de tipo `Footer` (`<footer>`).
pub fn footer() -> Self {
Container {
Self {
container_kind: container::Kind::Footer,
..Default::default()
}
@ -106,7 +106,7 @@ impl Container {
/// Crea un contenedor de tipo `Section` (`<section>`).
pub fn section() -> Self {
Container {
Self {
container_kind: container::Kind::Section,
..Default::default()
}
@ -114,7 +114,7 @@ impl Container {
/// Crea un contenedor de tipo `Article` (`<article>`).
pub fn article() -> Self {
Container {
Self {
container_kind: container::Kind::Article,
..Default::default()
}

View file

@ -49,7 +49,7 @@ pub struct Dropdown {
impl Component for Dropdown {
fn new() -> Self {
Dropdown::default()
Self::default()
}
fn id(&self) -> Option<String> {

View file

@ -55,7 +55,7 @@ pub struct Item {
impl Component for Item {
fn new() -> Self {
Item::default()
Self::default()
}
fn id(&self) -> Option<String> {
@ -158,7 +158,7 @@ impl Component for Item {
impl Item {
/// Crea un elemento de tipo texto, mostrado sin interacción.
pub fn label(label: L10n) -> Self {
Item {
Self {
item_kind: ItemKind::Label(label),
..Default::default()
}
@ -170,7 +170,7 @@ impl Item {
/// [`RoutePath`] en función del [`Context`]. El enlace se marca como `active` si la ruta actual
/// del *request* coincide con la ruta de destino (devuelta por `RoutePath::path`).
pub fn link(label: L10n, route: FnPathByContext) -> Self {
Item {
Self {
item_kind: ItemKind::Link {
label,
route,
@ -183,7 +183,7 @@ impl Item {
/// Crea un enlace deshabilitado que no permite la interacción.
pub fn link_disabled(label: L10n, route: FnPathByContext) -> Self {
Item {
Self {
item_kind: ItemKind::Link {
label,
route,
@ -196,7 +196,7 @@ impl Item {
/// Crea un enlace que se abre en una nueva ventana o pestaña.
pub fn link_blank(label: L10n, route: FnPathByContext) -> Self {
Item {
Self {
item_kind: ItemKind::Link {
label,
route,
@ -209,7 +209,7 @@ impl Item {
/// Crea un enlace inicialmente deshabilitado que se abriría en una nueva ventana.
pub fn link_blank_disabled(label: L10n, route: FnPathByContext) -> Self {
Item {
Self {
item_kind: ItemKind::Link {
label,
route,
@ -222,7 +222,7 @@ impl Item {
/// Crea un botón de acción local, sin navegación asociada.
pub fn button(label: L10n) -> Self {
Item {
Self {
item_kind: ItemKind::Button {
label,
disabled: false,
@ -233,7 +233,7 @@ impl Item {
/// Crea un botón deshabilitado.
pub fn button_disabled(label: L10n) -> Self {
Item {
Self {
item_kind: ItemKind::Button {
label,
disabled: true,
@ -244,7 +244,7 @@ impl Item {
/// Crea un encabezado para un grupo de elementos dentro del menú.
pub fn header(label: L10n) -> Self {
Item {
Self {
item_kind: ItemKind::Header(label),
..Default::default()
}
@ -252,7 +252,7 @@ impl Item {
/// Crea un separador visual entre bloques de elementos.
pub fn divider() -> Self {
Item {
Self {
item_kind: ItemKind::Divider,
..Default::default()
}

View file

@ -23,7 +23,7 @@ pub struct Icon {
impl Component for Icon {
fn new() -> Self {
Icon::default()
Self::default()
}
fn setup_before_prepare(&mut self, _cx: &mut Context) {
@ -75,22 +75,22 @@ impl Component for Icon {
impl Icon {
pub fn font() -> Self {
Icon::default().with_icon_kind(IconKind::Font(FontSize::default()))
Self::default().with_icon_kind(IconKind::Font(FontSize::default()))
}
pub fn font_sized(font_size: FontSize) -> Self {
Icon::default().with_icon_kind(IconKind::Font(font_size))
Self::default().with_icon_kind(IconKind::Font(font_size))
}
pub fn svg(shapes: Markup) -> Self {
Icon::default().with_icon_kind(IconKind::Svg {
Self::default().with_icon_kind(IconKind::Svg {
shapes,
viewbox: AttrValue::default(),
})
}
pub fn svg_with_viewbox(shapes: Markup, viewbox: impl AsRef<str>) -> Self {
Icon::default().with_icon_kind(IconKind::Svg {
Self::default().with_icon_kind(IconKind::Svg {
shapes,
viewbox: AttrValue::new(viewbox),
})

View file

@ -25,7 +25,7 @@ pub struct Image {
impl Component for Image {
fn new() -> Self {
Image::default()
Self::default()
}
fn id(&self) -> Option<String> {
@ -73,7 +73,7 @@ impl Component for Image {
impl Image {
/// Crea rápidamente una imagen especificando su origen.
pub fn with(source: image::Source) -> Self {
Image::default().with_source(source)
Self::default().with_source(source)
}
// **< Image BUILDER >**************************************************************************

View file

@ -26,7 +26,7 @@ pub struct Nav {
impl Component for Nav {
fn new() -> Self {
Nav::default()
Self::default()
}
fn id(&self) -> Option<String> {
@ -59,17 +59,17 @@ impl Component for Nav {
impl Nav {
/// Crea un `Nav` usando pestañas para los elementos (*Tabs*).
pub fn tabs() -> Self {
Nav::default().with_kind(nav::Kind::Tabs)
Self::default().with_kind(nav::Kind::Tabs)
}
/// Crea un `Nav` usando botones para los elementos (*Pills*).
pub fn pills() -> Self {
Nav::default().with_kind(nav::Kind::Pills)
Self::default().with_kind(nav::Kind::Pills)
}
/// Crea un `Nav` usando elementos subrayados (*Underline*).
pub fn underline() -> Self {
Nav::default().with_kind(nav::Kind::Underline)
Self::default().with_kind(nav::Kind::Underline)
}
// **< Nav BUILDER >****************************************************************************

View file

@ -88,7 +88,7 @@ pub struct Item {
impl Component for Item {
fn new() -> Self {
Item::default()
Self::default()
}
fn id(&self) -> Option<String> {
@ -196,7 +196,7 @@ impl Component for Item {
impl Item {
/// Crea un elemento de tipo texto, mostrado sin interacción.
pub fn label(label: L10n) -> Self {
Item {
Self {
item_kind: ItemKind::Label(label),
..Default::default()
}
@ -208,7 +208,7 @@ impl Item {
/// [`RoutePath`] en función del [`Context`]. El enlace se marca como `active` si la ruta actual
/// del *request* coincide con la ruta de destino (devuelta por `RoutePath::path`).
pub fn link(label: L10n, route: FnPathByContext) -> Self {
Item {
Self {
item_kind: ItemKind::Link {
label,
route,
@ -221,7 +221,7 @@ impl Item {
/// Crea un enlace deshabilitado que no permite la interacción.
pub fn link_disabled(label: L10n, route: FnPathByContext) -> Self {
Item {
Self {
item_kind: ItemKind::Link {
label,
route,
@ -234,7 +234,7 @@ impl Item {
/// Crea un enlace que se abre en una nueva ventana o pestaña.
pub fn link_blank(label: L10n, route: FnPathByContext) -> Self {
Item {
Self {
item_kind: ItemKind::Link {
label,
route,
@ -247,7 +247,7 @@ impl Item {
/// Crea un enlace inicialmente deshabilitado que se abriría en una nueva ventana.
pub fn link_blank_disabled(label: L10n, route: FnPathByContext) -> Self {
Item {
Self {
item_kind: ItemKind::Link {
label,
route,
@ -263,7 +263,7 @@ impl Item {
/// El contenido se renderiza tal cual lo devuelve el componente [`Html`], dentro de un `<li>`
/// con las clases de navegación asociadas a [`Item`].
pub fn html(html: Html) -> Self {
Item {
Self {
item_kind: ItemKind::Html(Typed::with(html)),
..Default::default()
}
@ -275,7 +275,7 @@ impl Item {
/// lista de elementos** del [`Dropdown`]; el resto de propiedades del componente no afectarán
/// a su representación en [`Nav`].
pub fn dropdown(menu: Dropdown) -> Self {
Item {
Self {
item_kind: ItemKind::Dropdown(Typed::with(menu)),
..Default::default()
}

View file

@ -29,7 +29,7 @@ pub struct Brand {
impl Component for Brand {
fn new() -> Self {
Brand::default()
Self::default()
}
fn id(&self) -> Option<String> {

View file

@ -32,7 +32,7 @@ pub struct Navbar {
impl Component for Navbar {
fn new() -> Self {
Navbar::default()
Self::default()
}
fn id(&self) -> Option<String> {
@ -169,37 +169,37 @@ impl Component for Navbar {
impl Navbar {
/// Crea una barra de navegación **simple**, sin marca y sin botón.
pub fn simple() -> Self {
Navbar::default().with_layout(navbar::Layout::Simple)
Self::default().with_layout(navbar::Layout::Simple)
}
/// Crea una barra de navegación **simple pero colapsable**, con botón a la izquierda.
pub fn simple_toggle() -> Self {
Navbar::default().with_layout(navbar::Layout::SimpleToggle)
Self::default().with_layout(navbar::Layout::SimpleToggle)
}
/// Crea una barra de navegación **con marca a la izquierda**, siempre visible.
pub fn simple_brand_left(brand: navbar::Brand) -> Self {
Navbar::default().with_layout(navbar::Layout::SimpleBrandLeft(Typed::with(brand)))
Self::default().with_layout(navbar::Layout::SimpleBrandLeft(Typed::with(brand)))
}
/// Crea una barra de navegación con **marca a la izquierda** y **botón a la derecha**.
pub fn brand_left(brand: navbar::Brand) -> Self {
Navbar::default().with_layout(navbar::Layout::BrandLeft(Typed::with(brand)))
Self::default().with_layout(navbar::Layout::BrandLeft(Typed::with(brand)))
}
/// Crea una barra de navegación con **botón a la izquierda** y **marca a la derecha**.
pub fn brand_right(brand: navbar::Brand) -> Self {
Navbar::default().with_layout(navbar::Layout::BrandRight(Typed::with(brand)))
Self::default().with_layout(navbar::Layout::BrandRight(Typed::with(brand)))
}
/// Crea una barra de navegación cuyo contenido se muestra en un **offcanvas**.
pub fn offcanvas(oc: Offcanvas) -> Self {
Navbar::default().with_layout(navbar::Layout::Offcanvas(Typed::with(oc)))
Self::default().with_layout(navbar::Layout::Offcanvas(Typed::with(oc)))
}
/// Crea una barra de navegación con **marca a la izquierda** y contenido en **offcanvas**.
pub fn offcanvas_brand_left(brand: navbar::Brand, oc: Offcanvas) -> Self {
Navbar::default().with_layout(navbar::Layout::OffcanvasBrandLeft(
Self::default().with_layout(navbar::Layout::OffcanvasBrandLeft(
Typed::with(brand),
Typed::with(oc),
))
@ -207,7 +207,7 @@ impl Navbar {
/// Crea una barra de navegación con **marca a la derecha** y contenido en **offcanvas**.
pub fn offcanvas_brand_right(brand: navbar::Brand, oc: Offcanvas) -> Self {
Navbar::default().with_layout(navbar::Layout::OffcanvasBrandRight(
Self::default().with_layout(navbar::Layout::OffcanvasBrandRight(
Typed::with(brand),
Typed::with(oc),
))

View file

@ -26,7 +26,7 @@ pub enum Item {
impl Component for Item {
fn new() -> Self {
Item::default()
Self::default()
}
fn id(&self) -> Option<String> {

View file

@ -45,7 +45,7 @@ pub struct Offcanvas {
impl Component for Offcanvas {
fn new() -> Self {
Offcanvas::default()
Self::default()
}
fn id(&self) -> Option<String> {

View file

@ -18,7 +18,7 @@ pub struct Block {
impl Component for Block {
fn new() -> Self {
Block::default()
Self::default()
}
fn id(&self) -> Option<String> {

View file

@ -33,12 +33,13 @@ pub struct Html(Box<dyn Fn(&mut Context) -> Markup + Send + Sync>);
impl Default for Html {
fn default() -> Self {
Html::with(|_| html! {})
Self::with(|_| html! {})
}
}
impl Component for Html {
fn new() -> Self {
Html::default()
Self::default()
}
fn prepare_component(&self, cx: &mut Context) -> PrepareMarkup {

View file

@ -106,7 +106,7 @@ impl Default for Intro {
impl Component for Intro {
fn new() -> Self {
Intro::default()
Self::default()
}
fn setup_before_prepare(&mut self, cx: &mut Context) {

View file

@ -10,7 +10,7 @@ pub struct ActionsList(RwLock<Vec<ActionBox>>);
impl ActionsList {
pub fn new() -> Self {
ActionsList::default()
Self::default()
}
pub fn add(&mut self, action: ActionBox) {

View file

@ -208,12 +208,12 @@ pub struct Children(Vec<Child>);
impl Children {
/// Crea una lista vacía.
pub fn new() -> Self {
Children::default()
Self::default()
}
/// Crea una lista con un componente hijo inicial.
pub fn with(child: Child) -> Self {
Children::default().with_child(ChildOp::Add(child))
Self::default().with_child(ChildOp::Add(child))
}
/// Fusiona varias listas de `Children` en una sola.

View file

@ -49,7 +49,7 @@ impl Favicon {
/// Equivalente a `Favicon::default()`. Se recomienda iniciar la secuencia de configuración
/// desde aquí.
pub fn new() -> Self {
Favicon::default()
Self::default()
}
// **< Favicon BUILDER >************************************************************************

View file

@ -88,7 +88,7 @@ impl JavaScript {
///
/// Equivale a `<script src="...">`.
pub fn from(path: impl Into<String>) -> Self {
JavaScript {
Self {
source: Source::From(path.into()),
..Default::default()
}
@ -100,7 +100,7 @@ impl JavaScript {
/// Equivale a `<script src="..." defer>`. Suele ser la opción recomendada para scripts no
/// críticos.
pub fn defer(path: impl Into<String>) -> Self {
JavaScript {
Self {
source: Source::Defer(path.into()),
..Default::default()
}
@ -111,7 +111,7 @@ impl JavaScript {
///
/// Equivale a `<script src="..." async>`. **No garantiza** el orden relativo con otros scripts.
pub fn asynchronous(path: impl Into<String>) -> Self {
JavaScript {
Self {
source: Source::Async(path.into()),
..Default::default()
}
@ -127,7 +127,7 @@ impl JavaScript {
where
F: Fn(&mut Context) -> String + Send + Sync + 'static,
{
JavaScript {
Self {
source: Source::Inline(name.into(), Box::new(f)),
..Default::default()
}
@ -147,7 +147,7 @@ impl JavaScript {
where
F: Fn(&mut Context) -> String + Send + Sync + 'static,
{
JavaScript {
Self {
source: Source::OnLoad(name.into(), Box::new(f)),
..Default::default()
}
@ -165,7 +165,7 @@ impl JavaScript {
where
F: Fn(&mut Context) -> String + Send + Sync + 'static,
{
JavaScript {
Self {
source: Source::OnLoadAsync(name.into(), Box::new(f)),
..Default::default()
}

View file

@ -91,7 +91,7 @@ impl StyleSheet {
///
/// Equivale a `<link rel="stylesheet" href="...">`.
pub fn from(path: impl Into<String>) -> Self {
StyleSheet {
Self {
source: Source::From(path.into()),
..Default::default()
}
@ -107,7 +107,7 @@ impl StyleSheet {
where
F: Fn(&mut Context) -> String + Send + Sync + 'static,
{
StyleSheet {
Self {
source: Source::Inline(name.into(), Box::new(f)),
..Default::default()
}

View file

@ -44,7 +44,7 @@ pub struct AttrClasses(Vec<String>);
impl AttrClasses {
pub fn new(classes: impl AsRef<str>) -> Self {
AttrClasses::default().with_value(ClassesOp::Prepend, classes)
Self::default().with_value(ClassesOp::Prepend, classes)
}
// **< AttrClasses BUILDER >********************************************************************

View file

@ -66,7 +66,7 @@ pub struct L10n {
impl L10n {
/// **n** = *“native”*. Crea una instancia con una cadena literal sin traducción.
pub fn n(text: impl Into<Cow<'static, str>>) -> Self {
L10n {
Self {
op: L10nOp::Text(text.into()),
..Default::default()
}
@ -75,7 +75,7 @@ impl L10n {
/// **l** = *“lookup”*. Crea una instancia para traducir usando una clave del conjunto de
/// traducciones predefinidas.
pub fn l(key: impl Into<Cow<'static, str>>) -> Self {
L10n {
Self {
op: L10nOp::Translate(key.into()),
..Default::default()
}
@ -84,7 +84,7 @@ impl L10n {
/// **t** = *“translate”*. Crea una instancia para traducir usando una clave de un conjunto de
/// traducciones específico.
pub fn t(key: impl Into<Cow<'static, str>>, locales: &'static Locales) -> Self {
L10n {
Self {
op: L10nOp::Translate(key.into()),
locales,
..Default::default()