💥 Better names for main macros

This commit is contained in:
Manuel Cillero 2023-07-15 11:34:28 +02:00
parent eee481cfcb
commit 6df57a0c12
44 changed files with 146 additions and 140 deletions

View file

@ -28,7 +28,7 @@ macro_rules! actions_for_component {
// ACTION BEFORE PREPARE COMPONENT
// *************************************************************************************
$crate::use_handle!([<ACTION_BEFORE_PREPARE_ $Component:upper>] for Action);
$crate::create_handle!([<ACTION_BEFORE_PREPARE_ $Component:upper>] for Action);
pub struct [<BeforePrepare $Component>] {
action: Option<[<Action $Component>]>,
@ -87,7 +87,7 @@ macro_rules! actions_for_component {
// ACTION AFTER PREPARE COMPONENT
// *************************************************************************************
$crate::use_handle!([<ACTION_AFTER_PREPARE_ $Component:upper>] for Action);
$crate::create_handle!([<ACTION_AFTER_PREPARE_ $Component:upper>] for Action);
pub struct [<AfterPrepare $Component>] {
action: Option<[<Action $Component>]>,

View file

@ -1,8 +1,8 @@
use crate::core::component::{ComponentTrait, Context};
use crate::html::{html, Markup, PrepareMarkup};
use crate::{fn_builder, use_handle, Handle};
use crate::{create_handle, fn_builder, Handle};
use_handle!(COMPONENT_HTML);
create_handle!(COMPONENT_HTML);
#[derive(Default)]
pub struct Html(Markup);

View file

@ -1,11 +1,11 @@
use crate::core::component::{ComponentTrait, Context};
use crate::html::{html, PreEscaped, PrepareMarkup};
use crate::locale::{Loader, Locales};
use crate::{fn_builder, use_handle, Handle};
use crate::{create_handle, fn_builder, Handle};
use std::collections::HashMap;
use_handle!(COMPONENT_L10N);
create_handle!(COMPONENT_L10N);
#[derive(Default)]
pub enum L10nOp {

View file

@ -4,11 +4,11 @@ use crate::core::theme::{ThemeStaticRef, ThemeTrait};
use crate::html::{Favicon, StyleSheet};
use crate::response::page::Page;
use crate::service;
use crate::{serve_static_files, use_handle, use_static, Handle};
use crate::{create_handle, serve_static_files, static_files, Handle};
use_handle!(THEME_BASIC);
create_handle!(THEME_BASIC);
use_static!(theme);
static_files!(theme);
pub struct Basic;

View file

@ -3,7 +3,7 @@ use crate::core::component::{ComponentTrait, Context};
use crate::core::module::ModuleTrait;
use crate::html::{html, Favicon, Markup};
use crate::response::page::Page;
use crate::{config, LOCALE_PAGETOP};
use crate::{config, LOCALES_PAGETOP};
pub type ThemeStaticRef = &'static dyn ThemeTrait;
@ -12,11 +12,11 @@ pub trait ThemeTrait: ModuleTrait + Send + Sync {
#[rustfmt::skip]
fn regions(&self) -> Vec<(&'static str, L10n)> {
vec![
("header", L10n::t("header", &LOCALE_PAGETOP)),
("pagetop", L10n::t("pagetop", &LOCALE_PAGETOP)),
("content", L10n::t("content", &LOCALE_PAGETOP)),
("sidebar", L10n::t("sidebar", &LOCALE_PAGETOP)),
("footer", L10n::t("footer", &LOCALE_PAGETOP)),
("header", L10n::t("header", &LOCALES_PAGETOP)),
("pagetop", L10n::t("pagetop", &LOCALES_PAGETOP)),
("content", L10n::t("content", &LOCALES_PAGETOP)),
("sidebar", L10n::t("sidebar", &LOCALES_PAGETOP)),
("footer", L10n::t("footer", &LOCALES_PAGETOP)),
]
}

View file

@ -42,7 +42,7 @@
//! ```rust
//! use pagetop::prelude::*;
//!
//! use_handle!(APP_HELLO_WORLD);
//! create_handle!(APP_HELLO_WORLD);
//!
//! struct HelloWorld;
//!
@ -116,7 +116,7 @@ pub type HashMapResources = std::collections::HashMap<&'static str, StaticResour
pub type Handle = u64;
use_locale!(LOCALE_PAGETOP);
static_locales!(LOCALES_PAGETOP);
// *************************************************************************************************
// APIs PÚBLICAS.

View file

@ -70,13 +70,13 @@
//! # Cómo aplicar la localización en tu código
//!
//! Una vez hayas creado tu directorio de recursos FTL usa la macro
//! [`use_locale!`](crate::use_locale) para integrarlos en tu módulo o aplicación. Si tus recursos
//! se encuentran en el directorio `"src/locale"` bastará con declarar:
//! [`static_locales!`](crate::static_locales) para integrarlos en tu módulo o aplicación. Si tus
//! recursos se encuentran en el directorio `"src/locale"` bastará con declarar:
//!
//! ```
//! use pagetop::prelude::*;
//!
//! use_locale!(LOCALE_SAMPLE);
//! static_locales!(LOCALES_SAMPLE);
//! ```
//!
//! Y si están en otro directorio, entonces puedes usar:
@ -84,7 +84,7 @@
//! ```
//! use pagetop::prelude::*;
//!
//! use_locale!(LOCALE_SAMPLE in "path/to/locale");
//! static_locales!(LOCALES_SAMPLE in "path/to/locale");
//! ```
//!
//! Usa el componente [L10n](crate::core::component::l10n::L10n) para incluir textos y contenidos

View file

@ -8,7 +8,8 @@ pub use crate::{
// Funciones y macros útiles.
pub use crate::util;
pub use crate::{action, actions_for_component};
pub use crate::{default_settings, kv, serve_static_files, use_handle, use_locale, use_static};
pub use crate::{create_handle, default_settings, kv};
pub use crate::{serve_static_files, static_files, static_locales};
// *************************************************************************************************

View file

@ -1,8 +1,8 @@
use crate::core::component::{ComponentTrait, Context};
use crate::html::{html, PrepareMarkup};
use crate::{use_handle, Handle};
use crate::{create_handle, Handle};
use_handle!(ERROR_403);
create_handle!(ERROR_403);
pub struct Error403;

View file

@ -1,8 +1,8 @@
use crate::core::component::{ComponentTrait, Context};
use crate::html::{html, PrepareMarkup};
use crate::{use_handle, Handle};
use crate::{create_handle, Handle};
use_handle!(ERROR_404);
create_handle!(ERROR_404);
pub struct Error404;

View file

@ -1,9 +1,9 @@
use crate::core::action::{action_ref, run_actions, ActionTrait};
use crate::response::page::action::ActionPage;
use crate::response::page::Page;
use crate::{use_handle, Handle};
use crate::{create_handle, Handle};
use_handle!(ACTION_AFTER_PREPARE_BODY for Action);
create_handle!(ACTION_AFTER_PREPARE_BODY for Action);
pub struct ActionAfterPrepareBody {
action: Option<ActionPage>,

View file

@ -1,9 +1,9 @@
use crate::core::action::{action_ref, run_actions, ActionTrait};
use crate::response::page::action::ActionPage;
use crate::response::page::Page;
use crate::{use_handle, Handle};
use crate::{create_handle, Handle};
use_handle!(ACTION_BEFORE_PREPARE_BODY for Action);
create_handle!(ACTION_BEFORE_PREPARE_BODY for Action);
pub struct ActionBeforePrepareBody {
action: Option<ActionPage>,

View file

@ -89,8 +89,8 @@ macro_rules! kv {
macro_rules! default_settings {
( $($key:literal => $value:literal),* $(,)? ) => {
#[doc = concat!(
"Assigned or predefined values for configuration settings associated with the ",
"[`Settings`] structure."
"Assigned or predefined values for configuration settings associated to the ",
"[`Settings`] type."
)]
pub static SETTINGS: $crate::LazyStatic<Settings> = $crate::LazyStatic::new(|| {
let mut settings = $crate::config::CONFIG.clone();
@ -106,7 +106,7 @@ macro_rules! default_settings {
}
#[macro_export]
macro_rules! use_handle {
macro_rules! create_handle {
( $HANDLE:ident ) => {
/// Public constant handle to represent a unique PageTop building element.
pub const $HANDLE: $crate::Handle =
@ -121,7 +121,7 @@ macro_rules! use_handle {
#[macro_export]
/// Define un conjunto de elementos de localización y funciones locales de traducción.
macro_rules! use_locale {
macro_rules! static_locales {
( $LOCALES:ident $(, $core_locales:literal)? ) => {
use $crate::locale::*;
@ -153,21 +153,21 @@ macro_rules! use_locale {
}
#[macro_export]
macro_rules! use_static {
macro_rules! static_files {
( $bundle:ident ) => {
$crate::paste! {
mod [<static_bundle_ $bundle>] {
mod [<static_files_ $bundle>] {
include!(concat!(env!("OUT_DIR"), "/", stringify!($bundle), ".rs"));
}
}
};
( $bundle:ident => $STATIC:ident ) => {
$crate::paste! {
mod [<static_bundle_ $bundle>] {
mod [<static_files_ $bundle>] {
include!(concat!(env!("OUT_DIR"), "/", stringify!($bundle), ".rs"));
}
static $STATIC: LazyStatic<HashMapResources> = LazyStatic::new([
<static_bundle_ $bundle>]::$bundle
<static_files_ $bundle>]::$bundle
);
}
};
@ -181,7 +181,7 @@ macro_rules! serve_static_files {
if static_files.is_empty() {
$cfg.service($crate::service::ResourceFiles::new(
$path,
[<static_bundle_ $bundle>]::$bundle(),
[<static_files_ $bundle>]::$bundle(),
));
} else {
$cfg.service(