🚧 Revisa macros externas al core

This commit is contained in:
Manuel Cillero 2023-07-10 20:01:07 +02:00
parent ab795d17ff
commit 0a7f756709
4 changed files with 29 additions and 28 deletions

View file

@ -2,7 +2,7 @@ use pagetop::prelude::*;
use_handle!(MODULE_MENU);
use_locale!(LOCALE_MENU["src/module/menu/locales"]);
use_locale!(LOCALE_MENU in "src/module/menu/locales");
pub struct Menu;

View file

@ -119,6 +119,7 @@ mod path;
mod source;
mod value;
use crate::default_settings;
use crate::LazyStatic;
use crate::config::data::ConfigData;
@ -158,31 +159,6 @@ pub static CONFIG: LazyStatic<ConfigData> = LazyStatic::new(|| {
settings
});
#[macro_export]
/// Define un conjunto de ajustes de configuración usando tipos seguros y valores predefinidos.
///
/// Detiene la aplicación con un panic! si no pueden asignarse los ajustes de configuración.
///
/// Ver [`Cómo añadir ajustes de configuración`](config/index.html#cómo-añadir-ajustes-de-configuración).
macro_rules! default_settings {
( $($key:literal => $value:literal),* $(,)? ) => {
#[doc = concat!(
"Assigned or predefined values for configuration settings associated with the ",
"[`Settings`] structure."
)]
pub static SETTINGS: $crate::LazyStatic<Settings> = $crate::LazyStatic::new(|| {
let mut settings = $crate::config::CONFIG.clone();
$(
settings.set_default($key, $value).unwrap();
)*
match settings.try_into() {
Ok(s) => s,
Err(e) => panic!("Error parsing settings: {}", e),
}
});
};
}
#[derive(Debug, Deserialize)]
/// Configuration settings for the [`[app]`](App), [`[database]`](Database), [`[dev]`](Dev),
/// [`[log]`](Log), and [`[server]`](Server) sections (see [`SETTINGS`]).

View file

@ -84,7 +84,7 @@
//! ```
//! use pagetop::prelude::*;
//!
//! use_locale!(LOCALE_SAMPLE["path/to/locale"]);
//! use_locale!(LOCALE_SAMPLE in "path/to/locale");
//! ```
//!
//! Usa el componente [L10n](crate::core::component::l10n::L10n) para incluir textos y contenidos

View file

@ -80,6 +80,31 @@ macro_rules! kv {
}};
}
#[macro_export]
/// Define un conjunto de ajustes de configuración usando tipos seguros y valores predefinidos.
///
/// Detiene la aplicación con un panic! si no pueden asignarse los ajustes de configuración.
///
/// Ver [`Cómo añadir ajustes de configuración`](config/index.html#cómo-añadir-ajustes-de-configuración).
macro_rules! default_settings {
( $($key:literal => $value:literal),* $(,)? ) => {
#[doc = concat!(
"Assigned or predefined values for configuration settings associated with the ",
"[`Settings`] structure."
)]
pub static SETTINGS: $crate::LazyStatic<Settings> = $crate::LazyStatic::new(|| {
let mut settings = $crate::config::CONFIG.clone();
$(
settings.set_default($key, $value).unwrap();
)*
match settings.try_into() {
Ok(s) => s,
Err(e) => panic!("Error parsing settings: {}", e),
}
});
};
}
#[macro_export]
macro_rules! use_handle {
( $HANDLE:ident ) => {
@ -111,7 +136,7 @@ macro_rules! use_locale {
};
}
};
( $LOCALES:ident[$dir_locales:literal] $(, $core_locales:literal)? ) => {
( $LOCALES:ident in $dir_locales:literal $(, $core_locales:literal)? ) => {
use $crate::locale::*;
fluent_templates::static_loader! {