diff --git a/drust/src/main.rs b/drust/src/main.rs index 3f2073d2..f5167f33 100644 --- a/drust/src/main.rs +++ b/drust/src/main.rs @@ -1,11 +1,11 @@ use pagetop::prelude::*; -pub_const_handler!(APP_DRUST); +pub_handle!(APP_DRUST); struct Drust; impl ModuleTrait for Drust { - fn handler(&self) -> Handler { + fn handle(&self) -> Handle { APP_DRUST } diff --git a/pagetop-admin/src/lib.rs b/pagetop-admin/src/lib.rs index 4ddd3279..20aeac6e 100644 --- a/pagetop-admin/src/lib.rs +++ b/pagetop-admin/src/lib.rs @@ -1,15 +1,15 @@ use pagetop::prelude::*; -pub_const_handler!(MODULE_ADMIN); +pub_handle!(MODULE_ADMIN); -localize!("src/locales"); +pub_locale!("src/locales"); mod summary; pub struct Admin; impl ModuleTrait for Admin { - fn handler(&self) -> Handler { + fn handle(&self) -> Handle { MODULE_ADMIN } diff --git a/pagetop-node/src/lib.rs b/pagetop-node/src/lib.rs index ff4755fd..db9c1b44 100644 --- a/pagetop-node/src/lib.rs +++ b/pagetop-node/src/lib.rs @@ -1,8 +1,8 @@ use pagetop::prelude::*; -pub_const_handler!(MODULE_NODE); +pub_handle!(MODULE_NODE); -localize!("src/locales"); +pub_locale!("src/locales"); //mod entity; mod migration; @@ -10,7 +10,7 @@ mod migration; pub struct Node; impl ModuleTrait for Node { - fn handler(&self) -> Handler { + fn handle(&self) -> Handle { MODULE_NODE } diff --git a/pagetop-user/src/lib.rs b/pagetop-user/src/lib.rs index 22c14c41..6b192af8 100644 --- a/pagetop-user/src/lib.rs +++ b/pagetop-user/src/lib.rs @@ -1,15 +1,15 @@ use pagetop::prelude::*; -pub_const_handler!(MODULE_USER); +pub_handle!(MODULE_USER); -localize!("src/locales"); +pub_locale!("src/locales"); mod migration; pub struct User; impl ModuleTrait for User { - fn handler(&self) -> Handler { + fn handle(&self) -> Handle { MODULE_USER } diff --git a/pagetop/src/base/component/anchor.rs b/pagetop/src/base/component/anchor.rs index 110aa5ff..b91e939e 100644 --- a/pagetop/src/base/component/anchor.rs +++ b/pagetop/src/base/component/anchor.rs @@ -1,6 +1,6 @@ use crate::prelude::*; -pub_const_handler!(COMPONENT_ANCHOR); +pub_handle!(COMPONENT_ANCHOR); #[derive(Default)] pub enum AnchorType { @@ -43,7 +43,7 @@ impl ComponentTrait for Anchor { Anchor::default() } - fn handler(&self) -> Handler { + fn handle(&self) -> Handle { COMPONENT_ANCHOR } diff --git a/pagetop/src/base/component/block.rs b/pagetop/src/base/component/block.rs index c1b8a39f..af89daca 100644 --- a/pagetop/src/base/component/block.rs +++ b/pagetop/src/base/component/block.rs @@ -1,6 +1,6 @@ use crate::prelude::*; -pub_const_handler!(COMPONENT_BLOCK); +pub_handle!(COMPONENT_BLOCK); hook_before_render_component!(HOOK_BEFORE_RENDER_BLOCK, Block); @@ -21,7 +21,7 @@ impl ComponentTrait for Block { Block::default().with_classes(ClassesOp::SetDefault, "block") } - fn handler(&self) -> Handler { + fn handle(&self) -> Handle { COMPONENT_BLOCK } diff --git a/pagetop/src/base/component/container.rs b/pagetop/src/base/component/container.rs index b3522957..1024e4de 100644 --- a/pagetop/src/base/component/container.rs +++ b/pagetop/src/base/component/container.rs @@ -1,6 +1,6 @@ use crate::prelude::*; -pub_const_handler!(COMPONENT_CONTAINER); +pub_handle!(COMPONENT_CONTAINER); hook_before_render_component!(HOOK_BEFORE_RENDER_CONTAINER, Container); @@ -34,7 +34,7 @@ impl ComponentTrait for Container { .with_inner_classes(ClassesOp::SetDefault, "container") } - fn handler(&self) -> Handler { + fn handle(&self) -> Handle { COMPONENT_CONTAINER } diff --git a/pagetop/src/base/component/form_element/button.rs b/pagetop/src/base/component/form_element/button.rs index d99305f9..e20c920e 100644 --- a/pagetop/src/base/component/form_element/button.rs +++ b/pagetop/src/base/component/form_element/button.rs @@ -1,6 +1,6 @@ use crate::prelude::*; -pub_const_handler!(COMPONENT_BUTTON); +pub_handle!(COMPONENT_BUTTON); #[derive(Default)] pub enum ButtonType { @@ -31,7 +31,7 @@ impl ComponentTrait for Button { .with_classes(ClassesOp::AddFirst, "form-button") } - fn handler(&self) -> Handler { + fn handle(&self) -> Handle { COMPONENT_BUTTON } diff --git a/pagetop/src/base/component/form_element/date.rs b/pagetop/src/base/component/form_element/date.rs index 0b6fb935..910e989a 100644 --- a/pagetop/src/base/component/form_element/date.rs +++ b/pagetop/src/base/component/form_element/date.rs @@ -1,6 +1,6 @@ use crate::prelude::*; -pub_const_handler!(COMPONENT_DATE); +pub_handle!(COMPONENT_DATE); #[rustfmt::skip] #[derive(Default)] @@ -28,7 +28,7 @@ impl ComponentTrait for Date { .with_classes(ClassesOp::AddFirst, "form-type-date") } - fn handler(&self) -> Handler { + fn handle(&self) -> Handle { COMPONENT_DATE } diff --git a/pagetop/src/base/component/form_element/form.rs b/pagetop/src/base/component/form_element/form.rs index 9ff1593e..8f24800e 100644 --- a/pagetop/src/base/component/form_element/form.rs +++ b/pagetop/src/base/component/form_element/form.rs @@ -1,6 +1,6 @@ use crate::prelude::*; -pub_const_handler!(COMPONENT_FORM); +pub_handle!(COMPONENT_FORM); hook_before_render_component!(HOOK_BEFORE_RENDER_FORM, Form); @@ -32,7 +32,7 @@ impl ComponentTrait for Form { .with_charset("UTF-8") } - fn handler(&self) -> Handler { + fn handle(&self) -> Handle { COMPONENT_FORM } diff --git a/pagetop/src/base/component/form_element/hidden.rs b/pagetop/src/base/component/form_element/hidden.rs index 0ee11d83..88584cdd 100644 --- a/pagetop/src/base/component/form_element/hidden.rs +++ b/pagetop/src/base/component/form_element/hidden.rs @@ -1,6 +1,6 @@ use crate::prelude::*; -pub_const_handler!(COMPONENT_HIDDEN); +pub_handle!(COMPONENT_HIDDEN); #[rustfmt::skip] #[derive(Default)] @@ -15,7 +15,7 @@ impl ComponentTrait for Hidden { Hidden::default() } - fn handler(&self) -> Handler { + fn handle(&self) -> Handle { COMPONENT_HIDDEN } diff --git a/pagetop/src/base/component/form_element/input.rs b/pagetop/src/base/component/form_element/input.rs index 5418e0ed..1109ac3b 100644 --- a/pagetop/src/base/component/form_element/input.rs +++ b/pagetop/src/base/component/form_element/input.rs @@ -1,6 +1,6 @@ use crate::prelude::*; -pub_const_handler!(COMPONENT_INPUT); +pub_handle!(COMPONENT_INPUT); #[derive(Default)] pub enum InputType { @@ -45,7 +45,7 @@ impl ComponentTrait for Input { .with_maxlength(Some(128)) } - fn handler(&self) -> Handler { + fn handle(&self) -> Handle { COMPONENT_INPUT } diff --git a/pagetop/src/base/component/grid/column.rs b/pagetop/src/base/component/grid/column.rs index 898141f2..bb78e9c4 100644 --- a/pagetop/src/base/component/grid/column.rs +++ b/pagetop/src/base/component/grid/column.rs @@ -1,6 +1,6 @@ use crate::prelude::*; -pub_const_handler!(COMPONENT_COLUMN); +pub_handle!(COMPONENT_COLUMN); hook_before_render_component!(HOOK_BEFORE_RENDER_COLUMN, Column); @@ -53,7 +53,7 @@ impl ComponentTrait for Column { Column::default().with_classes(ClassesOp::SetDefault, SIZE__DEFAULT) } - fn handler(&self) -> Handler { + fn handle(&self) -> Handle { COMPONENT_COLUMN } diff --git a/pagetop/src/base/component/grid/row.rs b/pagetop/src/base/component/grid/row.rs index 76919287..bd2ddd94 100644 --- a/pagetop/src/base/component/grid/row.rs +++ b/pagetop/src/base/component/grid/row.rs @@ -1,6 +1,6 @@ use crate::prelude::*; -pub_const_handler!(COMPONENT_ROW); +pub_handle!(COMPONENT_ROW); hook_before_render_component!(HOOK_BEFORE_RENDER_ROW, Row); @@ -20,7 +20,7 @@ impl ComponentTrait for Row { Row::default().with_classes(ClassesOp::SetDefault, "row") } - fn handler(&self) -> Handler { + fn handle(&self) -> Handle { COMPONENT_ROW } diff --git a/pagetop/src/base/component/heading.rs b/pagetop/src/base/component/heading.rs index b3c643b6..bf90567d 100644 --- a/pagetop/src/base/component/heading.rs +++ b/pagetop/src/base/component/heading.rs @@ -1,6 +1,6 @@ use crate::prelude::*; -pub_const_handler!(COMPONENT_HEADING); +pub_handle!(COMPONENT_HEADING); #[derive(Default)] pub enum HeadingType { @@ -43,7 +43,7 @@ impl ComponentTrait for Heading { Heading::default() } - fn handler(&self) -> Handler { + fn handle(&self) -> Handle { COMPONENT_HEADING } diff --git a/pagetop/src/base/component/html.rs b/pagetop/src/base/component/html.rs index 881ef29c..dfc51289 100644 --- a/pagetop/src/base/component/html.rs +++ b/pagetop/src/base/component/html.rs @@ -1,6 +1,6 @@ use crate::prelude::*; -pub_const_handler!(COMPONENT_HTML); +pub_handle!(COMPONENT_HTML); #[rustfmt::skip] #[derive(Default)] @@ -16,7 +16,7 @@ impl ComponentTrait for Html { Html::default() } - fn handler(&self) -> Handler { + fn handle(&self) -> Handle { COMPONENT_HTML } diff --git a/pagetop/src/base/component/icon.rs b/pagetop/src/base/component/icon.rs index 657a4f7f..368fb4cc 100644 --- a/pagetop/src/base/component/icon.rs +++ b/pagetop/src/base/component/icon.rs @@ -1,6 +1,6 @@ use crate::prelude::*; -pub_const_handler!(COMPONENT_ICON); +pub_handle!(COMPONENT_ICON); #[rustfmt::skip] #[derive(Default)] @@ -16,7 +16,7 @@ impl ComponentTrait for Icon { Icon::default().with_classes(ClassesOp::SetDefault, "bi-question-circle-fill") } - fn handler(&self) -> Handler { + fn handle(&self) -> Handle { COMPONENT_ICON } diff --git a/pagetop/src/base/component/image.rs b/pagetop/src/base/component/image.rs index b3afe450..cb59442f 100644 --- a/pagetop/src/base/component/image.rs +++ b/pagetop/src/base/component/image.rs @@ -1,6 +1,6 @@ use crate::prelude::*; -pub_const_handler!(COMPONENT_IMAGE); +pub_handle!(COMPONENT_IMAGE); #[rustfmt::skip] #[derive(Default)] @@ -18,7 +18,7 @@ impl ComponentTrait for Image { Image::default().with_classes(ClassesOp::SetDefault, "img-fluid") } - fn handler(&self) -> Handler { + fn handle(&self) -> Handle { COMPONENT_IMAGE } diff --git a/pagetop/src/base/component/menu.rs b/pagetop/src/base/component/menu.rs index 2076d3fc..a95ade58 100644 --- a/pagetop/src/base/component/menu.rs +++ b/pagetop/src/base/component/menu.rs @@ -1,6 +1,6 @@ use crate::prelude::*; -pub_const_handler!(COMPONENT_MENUITEM); +pub_handle!(COMPONENT_MENUITEM); #[derive(Default)] pub enum MenuItemType { @@ -29,7 +29,7 @@ impl ComponentTrait for MenuItem { MenuItem::default() } - fn handler(&self) -> Handler { + fn handle(&self) -> Handle { COMPONENT_MENUITEM } @@ -170,7 +170,7 @@ impl MenuItem { // Menu. -pub_const_handler!(COMPONENT_MENU); +pub_handle!(COMPONENT_MENU); hook_before_render_component!(HOOK_BEFORE_RENDER_MENU, Menu); @@ -190,7 +190,7 @@ impl ComponentTrait for Menu { Menu::default().with_classes(ClassesOp::SetDefault, "sm sm-clean") } - fn handler(&self) -> Handler { + fn handle(&self) -> Handle { COMPONENT_MENU } diff --git a/pagetop/src/base/component/paragraph.rs b/pagetop/src/base/component/paragraph.rs index 52cb5c5d..fa60c233 100644 --- a/pagetop/src/base/component/paragraph.rs +++ b/pagetop/src/base/component/paragraph.rs @@ -1,6 +1,6 @@ use crate::prelude::*; -pub_const_handler!(COMPONENT_PARAGRAPH); +pub_handle!(COMPONENT_PARAGRAPH); #[derive(Default)] pub enum ParagraphDisplay { @@ -30,7 +30,7 @@ impl ComponentTrait for Paragraph { Paragraph::default() } - fn handler(&self) -> Handler { + fn handle(&self) -> Handle { COMPONENT_PARAGRAPH } diff --git a/pagetop/src/base/module/homepage.rs b/pagetop/src/base/module/homepage.rs index d48a0975..dee2e7b3 100644 --- a/pagetop/src/base/module/homepage.rs +++ b/pagetop/src/base/module/homepage.rs @@ -1,13 +1,13 @@ use crate::prelude::*; -pub_const_handler!(MODULE_DEFAULT_HOMEPAGE); +pub_handle!(MODULE_DEFAULT_HOMEPAGE); -localize!("src/base/module/homepage/locales"); +pub_locale!("src/base/module/homepage/locales"); pub struct DefaultHomePage; impl ModuleTrait for DefaultHomePage { - fn handler(&self) -> Handler { + fn handle(&self) -> Handle { MODULE_DEFAULT_HOMEPAGE } diff --git a/pagetop/src/base/theme/aliner.rs b/pagetop/src/base/theme/aliner.rs index 4afa2292..23c9c65c 100644 --- a/pagetop/src/base/theme/aliner.rs +++ b/pagetop/src/base/theme/aliner.rs @@ -1,13 +1,13 @@ use crate::prelude::*; -pub_const_handler!(THEME_ALINER); +pub_handle!(THEME_ALINER); include!(concat!(env!("OUT_DIR"), "/aliner.rs")); pub struct Aliner; impl ThemeTrait for Aliner { - fn handler(&self) -> Handler { + fn handle(&self) -> Handle { THEME_ALINER } diff --git a/pagetop/src/base/theme/bootsier.rs b/pagetop/src/base/theme/bootsier.rs index cc93fe11..04327b8f 100644 --- a/pagetop/src/base/theme/bootsier.rs +++ b/pagetop/src/base/theme/bootsier.rs @@ -1,15 +1,15 @@ use crate::prelude::*; -pub_const_handler!(THEME_BOOTSIER); +pub_handle!(THEME_BOOTSIER); + +pub_locale!("src/base/theme/bootsier/locales"); include!(concat!(env!("OUT_DIR"), "/bootsier.rs")); -localize!("src/base/theme/bootsier/locales"); - pub struct Bootsier; impl ThemeTrait for Bootsier { - fn handler(&self) -> Handler { + fn handle(&self) -> Handle { THEME_BOOTSIER } diff --git a/pagetop/src/base/theme/bulmix.rs b/pagetop/src/base/theme/bulmix.rs index a7ba960a..acac7d12 100644 --- a/pagetop/src/base/theme/bulmix.rs +++ b/pagetop/src/base/theme/bulmix.rs @@ -1,13 +1,13 @@ use crate::prelude::*; -pub_const_handler!(THEME_BULMIX); +pub_handle!(THEME_BULMIX); include!(concat!(env!("OUT_DIR"), "/bulmix.rs")); pub struct Bulmix; impl ThemeTrait for Bulmix { - fn handler(&self) -> Handler { + fn handle(&self) -> Handle { THEME_BULMIX } @@ -33,7 +33,7 @@ impl ThemeTrait for Bulmix { component: &mut dyn ComponentTrait, _context: &mut PageContext, ) { - match component.handler() { + match component.handle() { COMPONENT_ANCHOR => { let a = component_mut::(component); a.alter_classes( @@ -112,7 +112,7 @@ impl ThemeTrait for Bulmix { component: &dyn ComponentTrait, _context: &mut PageContext, ) -> Option { - match component.handler() { + match component.handle() { COMPONENT_ICON => { let icon = component_ref::(component); Some(html! { diff --git a/pagetop/src/base/theme/minimal.rs b/pagetop/src/base/theme/minimal.rs index 63c90976..fab264f1 100644 --- a/pagetop/src/base/theme/minimal.rs +++ b/pagetop/src/base/theme/minimal.rs @@ -1,11 +1,11 @@ use crate::prelude::*; -pub_const_handler!(THEME_MINIMAL); +pub_handle!(THEME_MINIMAL); pub struct Minimal; impl ThemeTrait for Minimal { - fn handler(&self) -> Handler { + fn handle(&self) -> Handle { THEME_MINIMAL } } diff --git a/pagetop/src/core/component/definition.rs b/pagetop/src/core/component/definition.rs index 6786ca9b..2b61cc3d 100644 --- a/pagetop/src/core/component/definition.rs +++ b/pagetop/src/core/component/definition.rs @@ -1,6 +1,6 @@ use crate::html::{html, Markup}; use crate::response::page::PageContext; -use crate::util::{single_type_name, Handler}; +use crate::util::{single_type_name, Handle}; pub use std::any::Any as AnyComponent; @@ -13,7 +13,7 @@ pub trait ComponentTrait: AnyComponent + BaseComponent + Send + Sync { where Self: Sized; - fn handler(&self) -> Handler; + fn handle(&self) -> Handle; fn name(&self) -> String { single_type_name::().to_owned() @@ -75,7 +75,7 @@ pub fn component_mut(component: &mut dyn ComponentTrait) -> &mut C { macro_rules! hook_before_render_component { ( $ACTION_HANDLER:ident, $Component:ty ) => { paste::paste! { - $crate::pub_const_handler!($ACTION_HANDLER); + $crate::pub_handle!($ACTION_HANDLER); type Action = fn(&$Component, &mut PageContext); @@ -92,7 +92,7 @@ macro_rules! hook_before_render_component { } } - fn handler(&self) -> Handler { + fn handle(&self) -> Handle { $ACTION_HANDLER } diff --git a/pagetop/src/core/hook/all.rs b/pagetop/src/core/hook/all.rs index a5eeb5a7..a48399fd 100644 --- a/pagetop/src/core/hook/all.rs +++ b/pagetop/src/core/hook/all.rs @@ -1,29 +1,29 @@ use super::{ActionsHolder, HookAction}; -use crate::util::Handler; +use crate::util::Handle; use crate::LazyStatic; use std::collections::HashMap; use std::sync::RwLock; // Registered actions. -static ACTIONS: LazyStatic>> = +static ACTIONS: LazyStatic>> = LazyStatic::new(|| RwLock::new(HashMap::new())); pub fn add_action(action: HookAction) { let mut actions = ACTIONS.write().unwrap(); - let action_handler = action.handler(); - if let Some(holder) = actions.get_mut(&action_handler) { + let action_handle = action.handle(); + if let Some(holder) = actions.get_mut(&action_handle) { holder.add(action); } else { - actions.insert(action_handler, ActionsHolder::new_with(action)); + actions.insert(action_handle, ActionsHolder::new_with(action)); } } -pub fn run_actions(action_handler: Handler, f: F) +pub fn run_actions(action_handle: Handle, f: F) where F: FnMut(&HookAction) -> B, { - if let Some(holder) = ACTIONS.read().unwrap().get(&action_handler) { + if let Some(holder) = ACTIONS.read().unwrap().get(&action_handle) { holder.iter_map(f) } } diff --git a/pagetop/src/core/hook/definition.rs b/pagetop/src/core/hook/definition.rs index 5808b6c9..6feb0f76 100644 --- a/pagetop/src/core/hook/definition.rs +++ b/pagetop/src/core/hook/definition.rs @@ -1,4 +1,4 @@ -use crate::util::Handler; +use crate::util::Handle; pub use std::any::Any as AnyHookAction; @@ -7,7 +7,7 @@ pub trait HookActionTrait: AnyHookAction + Send + Sync { where Self: Sized; - fn handler(&self) -> Handler; + fn handle(&self) -> Handle; fn weight(&self) -> isize { 0 diff --git a/pagetop/src/core/module/all.rs b/pagetop/src/core/module/all.rs index 3fa88947..2bbc21e2 100644 --- a/pagetop/src/core/module/all.rs +++ b/pagetop/src/core/module/all.rs @@ -31,7 +31,7 @@ pub fn register_modules(app: ModuleStaticRef) { fn add_to_discarded(list: &mut Vec, module: ModuleStaticRef) { for u in module.uninstall_modules().iter() { - if !list.iter().any(|m| m.handler() == u.handler()) { + if !list.iter().any(|m| m.handle() == u.handle()) { list.push(*u); trace::debug!("Module \"{}\" discarded", u.single_name()); } @@ -42,12 +42,12 @@ fn add_to_discarded(list: &mut Vec, module: ModuleStaticRef) { } fn add_to_enabled(list: &mut Vec, module: ModuleStaticRef) { - if !list.iter().any(|m| m.handler() == module.handler()) { + if !list.iter().any(|m| m.handle() == module.handle()) { if DISCARDED_MODULES .read() .unwrap() .iter() - .any(|m| m.handler() == module.handler()) + .any(|m| m.handle() == module.handle()) { panic!( "Trying to enable \"{}\" module which is disabled", diff --git a/pagetop/src/core/module/definition.rs b/pagetop/src/core/module/definition.rs index b15d1f26..ce425622 100644 --- a/pagetop/src/core/module/definition.rs +++ b/pagetop/src/core/module/definition.rs @@ -1,7 +1,7 @@ use crate::app; use crate::core::hook::HookAction; use crate::core::theme::ThemeStaticRef; -use crate::util::{single_type_name, Handler}; +use crate::util::{single_type_name, Handle}; #[cfg(feature = "database")] use crate::db::MigrationItem; @@ -14,7 +14,7 @@ pub trait BaseModule { /// Los módulos deben implementar este *trait*. pub trait ModuleTrait: BaseModule + Send + Sync { - fn handler(&self) -> Handler; + fn handle(&self) -> Handle; fn name(&self) -> String { self.single_name().to_owned() diff --git a/pagetop/src/core/theme/all.rs b/pagetop/src/core/theme/all.rs index 64ae5b2b..17e9bbe1 100644 --- a/pagetop/src/core/theme/all.rs +++ b/pagetop/src/core/theme/all.rs @@ -20,7 +20,7 @@ pub fn register_themes(themes: Vec) { for theme in themes { if !registered_themes .iter() - .any(|t| t.handler() == theme.handler()) + .any(|t| t.handle() == theme.handle()) { trace::debug!("Registering theme \"{}\"", theme.single_name()); registered_themes.push(theme); diff --git a/pagetop/src/core/theme/definition.rs b/pagetop/src/core/theme/definition.rs index f33be422..112bab37 100644 --- a/pagetop/src/core/theme/definition.rs +++ b/pagetop/src/core/theme/definition.rs @@ -5,7 +5,7 @@ use crate::concat_string; use crate::core::component::ComponentTrait; use crate::html::{html, Favicon, Markup}; use crate::response::page::{Page, PageContext, PageOp}; -use crate::util::{single_type_name, Handler}; +use crate::util::{single_type_name, Handle}; pub type ThemeStaticRef = &'static dyn ThemeTrait; @@ -15,7 +15,7 @@ pub trait BaseTheme { /// Los temas deben implementar este "trait". pub trait ThemeTrait: BaseTheme + Send + Sync { - fn handler(&self) -> Handler; + fn handle(&self) -> Handle; fn name(&self) -> String { self.single_name().to_owned() @@ -91,7 +91,7 @@ pub trait ThemeTrait: BaseTheme + Send + Sync { /* Cómo usarlo: - match component.handler() { + match component.handle() { BLOCK_COMPONENT => { let block = component_mut::(component); block.alter_title("New title"); @@ -111,7 +111,7 @@ pub trait ThemeTrait: BaseTheme + Send + Sync { /* Cómo usarlo: - match component.handler() { + match component.handle() { BLOCK_COMPONENT => { let block = component_ref::(component); match block.template() { diff --git a/pagetop/src/locale.rs b/pagetop/src/locale.rs index 664ad870..5b8b53da 100644 --- a/pagetop/src/locale.rs +++ b/pagetop/src/locale.rs @@ -69,16 +69,16 @@ //! # Cómo aplicar la localización en tu código //! //! Una vez hayas creado tu directorio de recursos FTL, sólo tienes que usar la poderosa macro -//! [`localize!`](crate::localize) para integrar fácilmente tus recursos de localización. +//! [`pub_locale!`](crate::pub_locale) para integrar fácilmente tus recursos de localización. //! //! Esta macro crea dos funciones para el ámbito donde se ejecuta. Por un lado la función `l()` para //! traducciones directas de etiquetas. Y por otro la función `t()` para traducciones que requieren //! argumentos: //! //! ``` -//! use pagetop::{args, localize}; +//! use pagetop::{args, pub_locale}; //! -//! localize!("en-US"); +//! pub_locale!("en-US"); //! //! fn demo() { //! println!("* {}", l("hello-world")); @@ -100,7 +100,7 @@ pub use fluent_templates::{static_loader as static_locale, Loader as Locale}; #[macro_export] /// Permite integrar fácilmente localización en temas, módulos y componentes. -macro_rules! localize { +macro_rules! pub_locale { ( $dir_locales:literal $(, $core_locales:literal)? ) => { use $crate::locale::*; use $crate::app::locale::LANGID; diff --git a/pagetop/src/prelude.rs b/pagetop/src/prelude.rs index 241f1e82..ab2d1df4 100644 --- a/pagetop/src/prelude.rs +++ b/pagetop/src/prelude.rs @@ -2,11 +2,13 @@ pub use crate::{concat_string, LazyStatic}; // Macros. -pub use crate::{args, configure_service_for_static_files, predefined_settings, pub_const_handler}; +pub use crate::{ + args, configure_service_for_static_files, predefined_settings, pub_handle, pub_locale, +}; // Helpers. pub use crate::util; -pub use crate::util::{Handler, HashMapResources}; +pub use crate::util::{Handle, HashMapResources}; // ************************************************************************************************* @@ -14,8 +16,6 @@ pub use crate::config; pub use crate::trace; -pub use crate::localize; - pub use crate::html::*; #[cfg(feature = "database")] diff --git a/pagetop/src/response/page/hook.rs b/pagetop/src/response/page/hook.rs index 09363f35..0c01f27d 100644 --- a/pagetop/src/response/page/hook.rs +++ b/pagetop/src/response/page/hook.rs @@ -1,9 +1,9 @@ use super::Page; use crate::core::hook::{AnyHookAction, HookActionTrait}; -use crate::pub_const_handler; -use crate::util::Handler; +use crate::pub_handle; +use crate::util::Handle; -pub_const_handler!(HOOK_BEFORE_RENDER_PAGE); +pub_handle!(HOOK_BEFORE_RENDER_PAGE); type Hook = fn(&mut Page); @@ -20,7 +20,7 @@ impl HookActionTrait for BeforeRenderPageHook { } } - fn handler(&self) -> Handler { + fn handle(&self) -> Handle { HOOK_BEFORE_RENDER_PAGE } diff --git a/pagetop/src/util.rs b/pagetop/src/util.rs index 5caa741b..91d9c07d 100644 --- a/pagetop/src/util.rs +++ b/pagetop/src/util.rs @@ -87,15 +87,15 @@ pub fn bundle_resources( bundle.build() } -pub type Handler = u64; +pub type Handle = u64; // https://stackoverflow.com/a/71464396 -pub const fn handler( +pub const fn handle( module_path: &'static str, file: &'static str, line: u32, column: u32, -) -> Handler { +) -> Handle { let mut hash = 0xcbf29ce484222325; let prime = 0x00000100000001B3; @@ -124,10 +124,10 @@ pub const fn handler( } #[macro_export] -macro_rules! pub_const_handler { - ( $HANDLER:ident ) => { - pub const $HANDLER: $crate::util::Handler = - $crate::util::handler(module_path!(), file!(), line!(), column!()); +macro_rules! pub_handle { + ( $HANDLE:ident ) => { + pub const $HANDLE: $crate::util::Handle = + $crate::util::handle(module_path!(), file!(), line!(), column!()); }; }