From 9122508f0f43ea7b269cc6b131fb915f16d78cab Mon Sep 17 00:00:00 2001 From: Manuel Cillero Date: Sun, 20 Aug 2023 23:24:03 +0200 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Compacts=20the=20component?= =?UTF-8?q?=20core=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pagetop/src/core/component.rs | 7 +++++-- pagetop/src/core/module/definition.rs | 2 +- pagetop/src/core/theme/default.rs | 2 +- pagetop/src/core/theme/definition.rs | 3 +-- pagetop/src/html.rs | 10 ++++++++++ pagetop/src/lib.rs | 8 ++++---- pagetop/src/prelude.rs | 6 ++---- pagetop/src/response/fatal_error.rs | 2 +- pagetop/src/response/page.rs | 4 ++-- 9 files changed, 27 insertions(+), 17 deletions(-) diff --git a/pagetop/src/core/component.rs b/pagetop/src/core/component.rs index 166459fc..671a41d9 100644 --- a/pagetop/src/core/component.rs +++ b/pagetop/src/core/component.rs @@ -14,8 +14,11 @@ pub use arc::{ArcComponent, ArcComponents, ArcOp}; mod typed; pub use typed::{TypedComponent, TypedComponents, TypedOp}; -pub mod html; -pub mod l10n; +mod html; +pub use html::{Html, COMPONENT_HTML}; + +mod l10n; +pub use l10n::{L10n, COMPONENT_L10N}; #[macro_export] macro_rules! actions_for_component { diff --git a/pagetop/src/core/module/definition.rs b/pagetop/src/core/module/definition.rs index 76c0a5b5..17f76af6 100644 --- a/pagetop/src/core/module/definition.rs +++ b/pagetop/src/core/module/definition.rs @@ -1,5 +1,5 @@ use crate::core::action::Action; -use crate::core::component::l10n::L10n; +use crate::core::component::L10n; use crate::core::theme::ThemeRef; use crate::{service, util, Handle}; diff --git a/pagetop/src/core/theme/default.rs b/pagetop/src/core/theme/default.rs index 50ce1ca1..deea8dad 100644 --- a/pagetop/src/core/theme/default.rs +++ b/pagetop/src/core/theme/default.rs @@ -1,4 +1,4 @@ -use crate::core::component::{l10n::L10n, ContextOp}; +use crate::core::component::{ContextOp, L10n}; use crate::core::module::ModuleTrait; use crate::core::theme::{ThemeRef, ThemeTrait}; use crate::html::{Favicon, StyleSheet}; diff --git a/pagetop/src/core/theme/definition.rs b/pagetop/src/core/theme/definition.rs index fd4b53a1..3650f00e 100644 --- a/pagetop/src/core/theme/definition.rs +++ b/pagetop/src/core/theme/definition.rs @@ -1,5 +1,4 @@ -use crate::core::component::l10n::L10n; -use crate::core::component::{ComponentTrait, Context}; +use crate::core::component::{ComponentTrait, Context, L10n}; use crate::core::module::ModuleTrait; use crate::html::{html, Favicon, Markup}; use crate::response::page::Page; diff --git a/pagetop/src/html.rs b/pagetop/src/html.rs index a67d8274..18e16fea 100644 --- a/pagetop/src/html.rs +++ b/pagetop/src/html.rs @@ -48,3 +48,13 @@ impl PrepareMarkup { } } } + +impl ToString for PrepareMarkup { + fn to_string(&self) -> String { + match self { + PrepareMarkup::None => "".to_owned(), + PrepareMarkup::Text(text) => text.to_string(), + PrepareMarkup::With(markup) => markup.to_owned().into_string(), + } + } +} diff --git a/pagetop/src/lib.rs b/pagetop/src/lib.rs index f0031fcf..5d3b9509 100644 --- a/pagetop/src/lib.rs +++ b/pagetop/src/lib.rs @@ -18,10 +18,10 @@ //! //! * Registro de trazas y eventos de la aplicación ([`trace`]). //! -//! * Localización ([`locale`]). -//! //! * HTML en código ([`html`]). //! +//! * Localización ([`locale`]). +//! //! * [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date and time handling ([`datetime`]). //! //! * Acceso unificado y normalizado a base de datos ([`db`]). @@ -136,10 +136,10 @@ pub mod util; pub mod config; // Registro de trazas y eventos de la aplicación. pub mod trace; -// Localización. -pub mod locale; // HTML en código. pub mod html; +// Localización. +pub mod locale; // Date and time for PageTop. pub mod datetime; diff --git a/pagetop/src/prelude.rs b/pagetop/src/prelude.rs index e86b436a..3cb64adf 100644 --- a/pagetop/src/prelude.rs +++ b/pagetop/src/prelude.rs @@ -29,10 +29,10 @@ pub use crate::config; pub use crate::trace; -pub use crate::locale::*; - pub use crate::html::*; +pub use crate::locale::*; + pub use crate::datetime::*; #[cfg(feature = "database")] @@ -42,8 +42,6 @@ pub use crate::service; pub use crate::service::HttpMessage; pub use crate::core::action::*; -pub use crate::core::component::html::*; -pub use crate::core::component::l10n::*; pub use crate::core::component::*; pub use crate::core::module::*; pub use crate::core::theme::*; diff --git a/pagetop/src/response/fatal_error.rs b/pagetop/src/response/fatal_error.rs index 60df2239..5725e601 100644 --- a/pagetop/src/response/fatal_error.rs +++ b/pagetop/src/response/fatal_error.rs @@ -3,7 +3,7 @@ pub use error403::ERROR_403; mod error404; pub use error404::ERROR_404; -use crate::core::component::l10n::L10n; +use crate::core::component::L10n; use crate::response::{page::Page, ResponseError}; use crate::service::http::{header::ContentType, StatusCode}; use crate::service::{HttpRequest, HttpResponse}; diff --git a/pagetop/src/response/page.rs b/pagetop/src/response/page.rs index 59977503..3fdfa820 100644 --- a/pagetop/src/response/page.rs +++ b/pagetop/src/response/page.rs @@ -1,8 +1,8 @@ mod action; pub use action::*; -use crate::core::component::l10n::L10n; -use crate::core::component::{ArcComponent, ComponentTrait, Context, ContextOp, TypedComponent}; +use crate::core::component::{ArcComponent, ComponentTrait, TypedComponent}; +use crate::core::component::{Context, ContextOp, L10n}; use crate::core::theme::ComponentsRegions; use crate::html::{html, Classes, ClassesOp, Favicon, Markup, DOCTYPE}; use crate::response::fatal_error::FatalError;