From 3366a6acdc3870b793efc31930796aab1003e30b Mon Sep 17 00:00:00 2001 From: Manuel Cillero Date: Sat, 7 May 2022 23:51:04 +0200 Subject: [PATCH] =?UTF-8?q?Actualiza=20textos=20y=20formato=20del=20c?= =?UTF-8?q?=C3=B3digo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pagetop/src/api/action/holder.rs | 6 +----- pagetop/src/api/component/assets.rs | 9 ++++++--- pagetop/src/api/component/definition.rs | 2 +- pagetop/src/api/mod.rs | 6 +++--- pagetop/src/api/module/definition.rs | 3 +-- pagetop/src/api/theme/definition.rs | 3 +-- pagetop/src/base/component/block.rs | 2 +- pagetop/src/base/component/menu.rs | 2 +- pagetop/src/lib.rs | 4 ++-- 9 files changed, 17 insertions(+), 20 deletions(-) diff --git a/pagetop/src/api/action/holder.rs b/pagetop/src/api/action/holder.rs index ab3e2405..7009e103 100644 --- a/pagetop/src/api/action/holder.rs +++ b/pagetop/src/api/action/holder.rs @@ -30,11 +30,7 @@ impl ActionsHolder { actions.sort_by_key(|a| a.weight()); } - pub fn iter_map(&self, f: F) - where - Self: Sized, - F: FnMut(&ActionItem) -> B, - { + pub fn iter_map(&self, f: F) where Self: Sized, F: FnMut(&ActionItem) -> B { let _: Vec<_> = self.0.read().unwrap().iter().map(f).collect(); } } diff --git a/pagetop/src/api/component/assets.rs b/pagetop/src/api/component/assets.rs index 30a6e4b1..aa05ebd5 100644 --- a/pagetop/src/api/component/assets.rs +++ b/pagetop/src/api/component/assets.rs @@ -1,4 +1,4 @@ -use crate::{Lazy, base, concat_string}; +use crate::{Lazy, base, concat_string, util}; use crate::config::SETTINGS; use crate::html::{Markup, PreEscaped, html}; use crate::api::theme::*; @@ -281,11 +281,14 @@ impl Assets { // Assets EXTRAS. - pub fn serial_id(&mut self, prefix: &str, id: &Option) -> String { + pub fn required_id(&mut self, id: &Option) -> String { match id { Some(id) => id.to_string(), None => { - let prefix = prefix.trim().replace(" ", "_").to_lowercase(); + let prefix = util::single_type_name::() + .trim() + .replace(" ", "_") + .to_lowercase(); let prefix = if prefix.is_empty() { "prefix".to_owned() } else { diff --git a/pagetop/src/api/component/definition.rs b/pagetop/src/api/component/definition.rs index a807a36f..4381b08e 100644 --- a/pagetop/src/api/component/definition.rs +++ b/pagetop/src/api/component/definition.rs @@ -1,6 +1,6 @@ +use crate::util; use crate::html::{Markup, html}; use crate::api::action::{action_ref, run_actions}; -use crate::util; use super::{BEFORE_RENDER_COMPONENT_ACTION, BeforeRenderComponentAction}; use super::Assets; diff --git a/pagetop/src/api/mod.rs b/pagetop/src/api/mod.rs index b69ec91b..ff5daff9 100644 --- a/pagetop/src/api/mod.rs +++ b/pagetop/src/api/mod.rs @@ -1,4 +1,4 @@ pub mod action; // API to define functions that alter the behavior of PageTop core. -pub mod component; // API para crear nuevos componentes. -pub mod module; // API para añadir módulos con nuevas funcionalidades. -pub mod theme; // API para crear temas. +pub mod component; // API to build new components. +pub mod module; // API to add new features with modules. +pub mod theme; // API to create themes. diff --git a/pagetop/src/api/module/definition.rs b/pagetop/src/api/module/definition.rs index 7ee26e5d..1deb7d80 100644 --- a/pagetop/src/api/module/definition.rs +++ b/pagetop/src/api/module/definition.rs @@ -1,6 +1,5 @@ -use crate::app; +use crate::{app, util}; use crate::api::action::ActionItem; -use crate::util; #[cfg(any(feature = "mysql", feature = "postgres", feature = "sqlite"))] use crate::db::MigrationItem; diff --git a/pagetop/src/api/theme/definition.rs b/pagetop/src/api/theme/definition.rs index 6bfa63d5..e063b355 100644 --- a/pagetop/src/api/theme/definition.rs +++ b/pagetop/src/api/theme/definition.rs @@ -1,10 +1,9 @@ -use crate::{app, concat_string}; +use crate::{app, concat_string, util}; use crate::config::SETTINGS; use crate::html::{Markup, html}; use crate::api::component::{Assets, ComponentTrait, Favicon}; use crate::response::page::Page; use crate::base::component::Chunck; -use crate::util; /// Los temas deben implementar este "trait". pub trait ThemeTrait: Send + Sync { diff --git a/pagetop/src/base/component/block.rs b/pagetop/src/base/component/block.rs index dafe4497..4f120434 100644 --- a/pagetop/src/base/component/block.rs +++ b/pagetop/src/base/component/block.rs @@ -38,7 +38,7 @@ impl ComponentTrait for Block { } fn default_render(&self, assets: &mut Assets) -> Markup { - let id = assets.serial_id("block", self.id()); + let id = assets.required_id::(self.id()); html! { div id=(id) class=[self.classes()] { @match self.title() { diff --git a/pagetop/src/base/component/menu.rs b/pagetop/src/base/component/menu.rs index 0434b90f..450bc92e 100644 --- a/pagetop/src/base/component/menu.rs +++ b/pagetop/src/base/component/menu.rs @@ -219,7 +219,7 @@ impl ComponentTrait for Menu { )) .add_jquery(); - let id = assets.serial_id("menu", self.id()); + let id = assets.required_id::(self.id()); html! { ul id=(id) class=[self.classes()] { (self.items().render(assets)) diff --git a/pagetop/src/lib.rs b/pagetop/src/lib.rs index 2c298184..20a25229 100644 --- a/pagetop/src/lib.rs +++ b/pagetop/src/lib.rs @@ -1,4 +1,4 @@ -// External. +// External re-exports. pub use once_cell::sync::Lazy; pub use concat_string::concat_string; @@ -25,6 +25,6 @@ pub mod app; // Aplicación y servidor web. pub mod base; // Base de componentes, módulos y temas. pub mod util; // Macros y funciones útiles. -// Re-exports. +// Internal re-exports. pub mod prelude;