diff --git a/src/app.rs b/src/app.rs index a9bc6246..62a3a0f7 100644 --- a/src/app.rs +++ b/src/app.rs @@ -6,7 +6,7 @@ use crate::core::{package, package::PackageRef}; use crate::html::Markup; use crate::response::page::{ErrorPage, ResultPage}; use crate::service::HttpRequest; -use crate::{config, locale, service, trace}; +use crate::{global, locale, service, trace}; use actix_session::config::{BrowserSession, PersistentSession, SessionLifecycle}; use actix_session::storage::CookieSessionStore; @@ -63,9 +63,9 @@ impl Application { fn show_banner() { use terminal_size::{terminal_size, Width}; - if config::SETTINGS.app.startup_banner.to_lowercase() != "off" { + if global::SETTINGS.app.startup_banner.to_lowercase() != "off" { // Application name, formatted for the terminal width if necessary. - let mut app_name = config::SETTINGS.app.name.to_string(); + let mut app_name = global::SETTINGS.app.name.to_string(); if let Some((Width(term_width), _)) = terminal_size() { if term_width >= 80 { let maxlen: usize = ((term_width / 10) - 2).into(); @@ -81,8 +81,8 @@ impl Application { println!("\n{app_name}"); // Application description. - if !config::SETTINGS.app.description.is_empty() { - println!("{}\n", config::SETTINGS.app.description); + if !global::SETTINGS.app.description.is_empty() { + println!("{}\n", global::SETTINGS.app.description); }; // PageTop version. @@ -101,12 +101,12 @@ impl Application { .wrap(tracing_actix_web::TracingLogger::default()) .wrap( SessionMiddleware::builder(CookieSessionStore::default(), secret_key.clone()) - .session_lifecycle(match config::SETTINGS.server.session_lifetime { + .session_lifecycle(match global::SETTINGS.server.session_lifetime { 0 => SessionLifecycle::BrowserSession(BrowserSession::default()), _ => SessionLifecycle::PersistentSession( PersistentSession::default().session_ttl( service::cookie::time::Duration::seconds( - config::SETTINGS.server.session_lifetime, + global::SETTINGS.server.session_lifetime, ), ), ), @@ -116,8 +116,8 @@ impl Application { }) .bind(format!( "{}:{}", - &config::SETTINGS.server.bind_address, - &config::SETTINGS.server.bind_port + &global::SETTINGS.server.bind_address, + &global::SETTINGS.server.bind_port ))? .run()) } diff --git a/src/app/figfont.rs b/src/app/figfont.rs index 7999b55b..1da9d9b9 100644 --- a/src/app/figfont.rs +++ b/src/app/figfont.rs @@ -1,4 +1,4 @@ -use crate::config; +use crate::global; use std::sync::LazyLock; @@ -11,7 +11,7 @@ pub static FIGFONT: LazyLock = LazyLock::new(|| { let starwars = include_str!("starwars.flf"); FIGfont::from_content( - match config::SETTINGS.app.startup_banner.to_lowercase().as_str() { + match global::SETTINGS.app.startup_banner.to_lowercase().as_str() { "off" => slant, "slant" => slant, "small" => small, @@ -20,7 +20,7 @@ pub static FIGFONT: LazyLock = LazyLock::new(|| { _ => { println!( "\n FIGfont \"{}\" not found for banner. Using \"Slant\". Check settings files.", - config::SETTINGS.app.startup_banner, + global::SETTINGS.app.startup_banner, ); slant } diff --git a/src/base/component/branding.rs b/src/base/component/branding.rs index e4f9b439..08ba8b01 100644 --- a/src/base/component/branding.rs +++ b/src/base/component/branding.rs @@ -4,7 +4,7 @@ use crate::prelude::*; #[derive(AutoDefault)] pub struct Branding { id : OptionId, - #[default(_code = "config::SETTINGS.app.name.to_owned()")] + #[default(_code = "global::SETTINGS.app.name.to_owned()")] app_name : String, slogan : OptionTranslated, logo : OptionComponent, diff --git a/src/base/component/powered_by.rs b/src/base/component/powered_by.rs index 35c9133d..62c7b76b 100644 --- a/src/base/component/powered_by.rs +++ b/src/base/component/powered_by.rs @@ -22,7 +22,7 @@ pub struct PoweredBy { impl ComponentTrait for PoweredBy { fn new() -> Self { let year = Utc::now().format("%Y").to_string(); - let c = concat_string!(year, " © ", config::SETTINGS.app.name); + let c = concat_string!(year, " © ", global::SETTINGS.app.name); PoweredBy { copyright: Some(c), ..Default::default() diff --git a/src/base/package/welcome.rs b/src/base/package/welcome.rs index 77d2180b..99a15e90 100644 --- a/src/base/package/welcome.rs +++ b/src/base/package/welcome.rs @@ -70,7 +70,7 @@ fn hello_world() -> flex::Container { "app", format!( "{}", - &config::SETTINGS.app.name, + &global::SETTINGS.app.name, ), )) .with_font_size(FontSize::Medium), @@ -125,7 +125,7 @@ fn welcome() -> flex::Container { "app", format!( "{}", - &config::SETTINGS.app.name + &global::SETTINGS.app.name ), )) .with_size(HeadingSize::Subtitle), @@ -230,7 +230,7 @@ fn reporting_issues() -> flex::Container { "app", format!( "{}", - &config::SETTINGS.app.name, + &global::SETTINGS.app.name, ), ), )), diff --git a/src/config.rs b/src/config.rs index 88442aba..a5baab60 100644 --- a/src/config.rs +++ b/src/config.rs @@ -51,8 +51,8 @@ //! serde = { version = "1.0", features = ["derive"] } //! ``` //! -//! Y luego inicializa con la macro [`default_settings!`](crate::default_settings) tus ajustes, -//! usando tipos seguros y asignando los valores predefinidos para la estructura asociada: +//! Y luego inicializa con la macro [`config_defaults!`](crate::config_defaults) tus ajustes, usando +//! tipos seguros y asignando los valores predefinidos para la estructura asociada: //! //! ``` //! use pagetop::prelude::*; @@ -71,12 +71,12 @@ //! pub height: u16, //! } //! -//! default_settings!( +//! config_defaults!(SETTINGS: Settings => [ //! // [myapp] //! "myapp.name" => "Value Name", //! "myapp.width" => 900, //! "myapp.height" => 320, -//! ); +//! ]); //! ``` //! //! De hecho, así se declaran los ajustes globales de la configuración (ver [`SETTINGS`]). @@ -98,16 +98,17 @@ //! //! ``` //! use pagetop::prelude::*; +//! use crate::config; //! //! fn global_settings() { -//! println!("App name: {}", &config::SETTINGS.app.name); -//! println!("App description: {}", &config::SETTINGS.app.description); -//! println!("Value of PAGETOP_RUN_MODE: {}", &config::SETTINGS.app.run_mode); +//! println!("App name: {}", &global::SETTINGS.app.name); +//! println!("App description: {}", &global::SETTINGS.app.description); +//! println!("Value of PAGETOP_RUN_MODE: {}", &global::SETTINGS.app.run_mode); //! } //! //! fn package_settings() { -//! println!("{} - {:?}", &SETTINGS.myapp.name, &SETTINGS.myapp.description); -//! println!("{}", &SETTINGS.myapp.width); +//! println!("{} - {:?}", &config::SETTINGS.myapp.name, &config::SETTINGS.myapp.description); +//! println!("{}", &config::SETTINGS.myapp.width); //! } //! ``` @@ -123,8 +124,6 @@ use crate::concat_string; use crate::config::data::ConfigData; use crate::config::file::File; -use serde::Deserialize; - use std::sync::LazyLock; use std::env; @@ -136,7 +135,7 @@ const CONFIG_DIR: &str = "config"; /// archivos de configuración. #[rustfmt::skip] -pub static CONFIG: LazyLock = LazyLock::new(|| { +pub static CONFIG_DATA: LazyLock = LazyLock::new(|| { // Modo de ejecución según la variable de entorno PAGETOP_RUN_MODE. Por defecto 'default'. let run_mode = env::var("PAGETOP_RUN_MODE").unwrap_or_else(|_| "default".into()); @@ -178,14 +177,14 @@ pub static CONFIG: LazyLock = LazyLock::new(|| { /// 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),* $(,)? ) => { +macro_rules! config_defaults { + ( $SETTINGS:ident: $Settings:ty => [ $($key:literal => $value:literal),* $(,)? ] ) => { #[doc = concat!( "Assigned or predefined values for configuration settings associated to the ", - "[`Settings`] type." + "[`", stringify!($Settings), "`] type." )] - pub static SETTINGS: std::sync::LazyLock = std::sync::LazyLock::new(|| { - let mut settings = $crate::config::CONFIG.clone(); + pub static $SETTINGS: std::sync::LazyLock<$Settings> = std::sync::LazyLock::new(|| { + let mut settings = $crate::config::CONFIG_DATA.clone(); $( settings.set_default($key, $value).unwrap(); )* @@ -196,120 +195,3 @@ macro_rules! default_settings { }); }; } - -#[derive(Debug, Deserialize)] -/// Configuration settings for the [`[app]`](App), [`[dev]`](Dev), [`[log]`](Log), and -/// [`[server]`](Server) sections (see [`SETTINGS`]). -pub struct Settings { - pub app: App, - pub dev: Dev, - pub log: Log, - pub server: Server, -} - -#[derive(Debug, Deserialize)] -/// Section `[app]` of the configuration settings. -/// -/// See [`Settings`]. -pub struct App { - /// El nombre de la aplicación. - /// Por defecto: *"My App"*. - pub name: String, - /// Una descripción breve de la aplicación. - /// Por defecto: *"Developed with the amazing PageTop framework."*. - pub description: String, - /// Tema predeterminado. - /// Por defecto: *"Default"*. - pub theme: String, - /// Idioma (localización) predeterminado. - /// Por defecto: *"en-US"*. - pub language: String, - /// Dirección predeterminada para el texto: *"ltr"* (de izquierda a derecha), *"rtl"* (de - /// derecha a izquierda) o *"auto"*. - /// Por defecto: *"ltr"*. - pub direction: String, - /// Rótulo de texto ASCII al arrancar: *"Off"*, *"Slant"*, *"Small"*, *"Speed"* o *"Starwars"*. - /// Por defecto: *"Slant"*. - pub startup_banner: String, - /// Por defecto: según variable de entorno `PAGETOP_RUN_MODE`, o *"default"* si no lo está. - pub run_mode: String, -} - -#[derive(Debug, Deserialize)] -/// Section `[dev]` of the configuration settings. -/// -/// See [`Settings`]. -pub struct Dev { - /// Los archivos estáticos requeridos por la aplicación se integran de manera predeterminada en - /// el binario ejecutable. Sin embargo, durante el desarrollo puede resultar útil servir estos - /// archivos desde su propio directorio para evitar recompilar cada vez que se modifican. En - /// este caso bastaría con indicar la ruta completa al directorio raíz del proyecto. - /// Por defecto: *""*. - pub pagetop_project_dir: String, -} - -#[derive(Debug, Deserialize)] -/// Section `[log]` of the configuration settings. -/// -/// See [`Settings`]. -pub struct Log { - /// Filtro, o combinación de filtros separados por coma, para la traza de ejecución: *"Error"*, - /// *"Warn"*, *"Info"*, *"Debug"* o *"Trace"*. - /// Por ejemplo: "Error,actix_server::builder=Info,tracing_actix_web=Debug". - /// Por defecto: *"Info"*. - pub tracing: String, - /// Muestra la traza en el terminal (*"Stdout"*) o queda registrada en archivos con rotación - /// *"Daily"*, *"Hourly"*, *"Minutely"* o *"Endless"*. - /// Por defecto: *"Stdout"*. - pub rolling: String, - /// Directorio para los archivos de traza (si `rolling` != *"Stdout"*). - /// Por defecto: *"log"*. - pub path: String, - /// Prefijo para los archivos de traza (si `rolling` != *"Stdout"*). - /// Por defecto: *"tracing.log"*. - pub prefix: String, - /// Presentación de las trazas. Puede ser *"Full"*, *"Compact"*, *"Pretty"* o *"Json"*. - /// Por defecto: *"Full"*. - pub format: String, -} - -#[derive(Debug, Deserialize)] -/// Section `[server]` of the configuration settings. -/// -/// See [`Settings`]. -pub struct Server { - /// Dirección del servidor web. - /// Por defecto: *"localhost"*. - pub bind_address: String, - /// Puerto del servidor web. - /// Por defecto: *8088*. - pub bind_port: u16, - /// Duración en segundos para la sesión (0 indica "hasta que se cierre el navegador"). - /// Por defecto: *604800* (7 días). - pub session_lifetime: i64, -} - -default_settings!( - // [app] - "app.name" => "My App", - "app.description" => "Developed with the amazing PageTop framework.", - "app.theme" => "Default", - "app.language" => "en-US", - "app.direction" => "ltr", - "app.startup_banner" => "Slant", - - // [dev] - "dev.pagetop_project_dir" => "", - - // [log] - "log.tracing" => "Info", - "log.rolling" => "Stdout", - "log.path" => "log", - "log.prefix" => "tracing.log", - "log.format" => "Full", - - // [server] - "server.bind_address" => "localhost", - "server.bind_port" => 8088, - "server.session_lifetime" => 604_800, -); diff --git a/src/core.rs b/src/core.rs index cd076eb0..1fe95a5d 100644 --- a/src/core.rs +++ b/src/core.rs @@ -1,6 +1,6 @@ //! Key types and functions for creating actions, components, packages, and themes. -use crate::util::TypeInfo; +use crate::global::TypeInfo; use std::any::Any; diff --git a/src/core/component/context.rs b/src/core/component/context.rs index 32183ec8..3fd80d5c 100644 --- a/src/core/component/context.rs +++ b/src/core/component/context.rs @@ -3,11 +3,11 @@ use crate::concat_string; use crate::core::component::AnyOp; use crate::core::theme::all::{theme_by_short_name, THEME_DEFAULT}; use crate::core::theme::{ComponentsInRegions, ThemeRef}; +use crate::global::TypeInfo; use crate::html::{html, Markup}; use crate::html::{Assets, Favicon, JavaScript, StyleSheet}; use crate::locale::{LanguageIdentifier, LANGID_DEFAULT}; use crate::service::HttpRequest; -use crate::util::TypeInfo; use std::collections::HashMap; use std::error::Error; diff --git a/src/core/component/definition.rs b/src/core/component/definition.rs index af33c943..ee8f1e2f 100644 --- a/src/core/component/definition.rs +++ b/src/core/component/definition.rs @@ -1,8 +1,8 @@ use crate::base::action; use crate::core::component::Context; use crate::core::AnyBase; +use crate::global::TypeInfo; use crate::html::{html, Markup, PrepareMarkup}; -use crate::util::TypeInfo; pub trait ComponentBase { fn render(&mut self, cx: &mut Context) -> Markup; diff --git a/src/core/package/all.rs b/src/core/package/all.rs index 50c650b1..33a823f0 100644 --- a/src/core/package/all.rs +++ b/src/core/package/all.rs @@ -1,7 +1,7 @@ use crate::core::action::add_action; use crate::core::package::PackageRef; use crate::core::theme::all::THEMES; -use crate::{config, service, service_for_static_files, static_files, trace}; +use crate::{global, service, static_files, static_files_service, trace}; use std::sync::{LazyLock, RwLock}; @@ -130,10 +130,10 @@ pub fn init_packages() { // CONFIGURE SERVICES ****************************************************************************** pub fn configure_services(scfg: &mut service::web::ServiceConfig) { - service_for_static_files!( + static_files_service!( scfg, base => "/base", - [&config::SETTINGS.dev.pagetop_project_dir, "static/base"] + [&global::SETTINGS.dev.pagetop_project_dir, "static/base"] ); for m in ENABLED_PACKAGES.read().unwrap().iter() { m.configure_service(scfg); diff --git a/src/core/theme/all.rs b/src/core/theme/all.rs index c7224ae4..1470038e 100644 --- a/src/core/theme/all.rs +++ b/src/core/theme/all.rs @@ -1,5 +1,5 @@ -use crate::config; use crate::core::theme::ThemeRef; +use crate::global; use std::sync::{LazyLock, RwLock}; @@ -10,7 +10,7 @@ pub static THEMES: LazyLock>> = LazyLock::new(|| RwLock::ne // DEFAULT THEME *********************************************************************************** pub static THEME_DEFAULT: LazyLock = - LazyLock::new(|| match theme_by_short_name(&config::SETTINGS.app.theme) { + LazyLock::new(|| match theme_by_short_name(&global::SETTINGS.app.theme) { Some(theme) => theme, None => &crate::base::theme::Inception, }); diff --git a/src/core/theme/definition.rs b/src/core/theme/definition.rs index 8d7a3911..c3541dc8 100644 --- a/src/core/theme/definition.rs +++ b/src/core/theme/definition.rs @@ -4,7 +4,7 @@ use crate::core::package::PackageTrait; use crate::html::{html, Favicon, PrepareMarkup}; use crate::locale::L10n; use crate::response::page::Page; -use crate::{concat_string, config}; +use crate::{concat_string, global}; pub type ThemeRef = &'static dyn ThemeTrait; @@ -82,9 +82,9 @@ pub trait ThemeTrait: PackageTrait + Send + Sync { meta charset="utf-8"; @if let Some(title) = page.title() { - title { (config::SETTINGS.app.name) (" - ") (title) } + title { (global::SETTINGS.app.name) (" - ") (title) } } @else { - title { (config::SETTINGS.app.name) } + title { (global::SETTINGS.app.name) } } @if let Some(description) = page.description() { diff --git a/src/util.rs b/src/global.rs similarity index 53% rename from src/util.rs rename to src/global.rs index 03a93d0f..9a6fd2bf 100644 --- a/src/util.rs +++ b/src/global.rs @@ -1,10 +1,137 @@ -//! Functions and macro helpers. +//! Global settings, functions and macro helpers. -use crate::trace; +use crate::{config_defaults, trace}; + +use serde::Deserialize; use std::io; use std::path::PathBuf; +// ************************************************************************************************* +// SETTINGS. +// ************************************************************************************************* + +#[derive(Debug, Deserialize)] +/// Configuration settings for global [`[app]`](App), [`[dev]`](Dev), [`[log]`](Log), and +/// [`[server]`](Server) sections (see [`SETTINGS`]). +pub struct Settings { + pub app: App, + pub dev: Dev, + pub log: Log, + pub server: Server, +} + +#[derive(Debug, Deserialize)] +/// Section `[app]` of the configuration settings. +/// +/// See [`Settings`]. +pub struct App { + /// El nombre de la aplicación. + /// Por defecto: *"My App"*. + pub name: String, + /// Una descripción breve de la aplicación. + /// Por defecto: *"Developed with the amazing PageTop framework."*. + pub description: String, + /// Tema predeterminado. + /// Por defecto: *"Default"*. + pub theme: String, + /// Idioma (localización) predeterminado. + /// Por defecto: *"en-US"*. + pub language: String, + /// Dirección predeterminada para el texto: *"ltr"* (de izquierda a derecha), *"rtl"* (de + /// derecha a izquierda) o *"auto"*. + /// Por defecto: *"ltr"*. + pub direction: String, + /// Rótulo de texto ASCII al arrancar: *"Off"*, *"Slant"*, *"Small"*, *"Speed"* o *"Starwars"*. + /// Por defecto: *"Slant"*. + pub startup_banner: String, + /// Por defecto: según variable de entorno `PAGETOP_RUN_MODE`, o *"default"* si no lo está. + pub run_mode: String, +} + +#[derive(Debug, Deserialize)] +/// Section `[dev]` of the configuration settings. +/// +/// See [`Settings`]. +pub struct Dev { + /// Los archivos estáticos requeridos por la aplicación se integran de manera predeterminada en + /// el binario ejecutable. Sin embargo, durante el desarrollo puede resultar útil servir estos + /// archivos desde su propio directorio para evitar recompilar cada vez que se modifican. En + /// este caso bastaría con indicar la ruta completa al directorio raíz del proyecto. + /// Por defecto: *""*. + pub pagetop_project_dir: String, +} + +#[derive(Debug, Deserialize)] +/// Section `[log]` of the configuration settings. +/// +/// See [`Settings`]. +pub struct Log { + /// Filtro, o combinación de filtros separados por coma, para la traza de ejecución: *"Error"*, + /// *"Warn"*, *"Info"*, *"Debug"* o *"Trace"*. + /// Por ejemplo: "Error,actix_server::builder=Info,tracing_actix_web=Debug". + /// Por defecto: *"Info"*. + pub tracing: String, + /// Muestra la traza en el terminal (*"Stdout"*) o queda registrada en archivos con rotación + /// *"Daily"*, *"Hourly"*, *"Minutely"* o *"Endless"*. + /// Por defecto: *"Stdout"*. + pub rolling: String, + /// Directorio para los archivos de traza (si `rolling` != *"Stdout"*). + /// Por defecto: *"log"*. + pub path: String, + /// Prefijo para los archivos de traza (si `rolling` != *"Stdout"*). + /// Por defecto: *"tracing.log"*. + pub prefix: String, + /// Presentación de las trazas. Puede ser *"Full"*, *"Compact"*, *"Pretty"* o *"Json"*. + /// Por defecto: *"Full"*. + pub format: String, +} + +#[derive(Debug, Deserialize)] +/// Section `[server]` of the configuration settings. +/// +/// See [`Settings`]. +pub struct Server { + /// Dirección del servidor web. + /// Por defecto: *"localhost"*. + pub bind_address: String, + /// Puerto del servidor web. + /// Por defecto: *8088*. + pub bind_port: u16, + /// Duración en segundos para la sesión (0 indica "hasta que se cierre el navegador"). + /// Por defecto: *604800* (7 días). + pub session_lifetime: i64, +} + +config_defaults!(SETTINGS: Settings => [ + // [app] + "app.name" => "My App", + "app.description" => "Developed with the amazing PageTop framework.", + "app.theme" => "Default", + "app.language" => "en-US", + "app.direction" => "ltr", + "app.startup_banner" => "Slant", + + // [dev] + "dev.pagetop_project_dir" => "", + + // [log] + "log.tracing" => "Info", + "log.rolling" => "Stdout", + "log.path" => "log", + "log.prefix" => "tracing.log", + "log.format" => "Full", + + // [server] + "server.bind_address" => "localhost", + "server.bind_port" => 8088, + "server.session_lifetime" => 604_800, +]); + +// ************************************************************************************************* +// FUNCTIONS HELPERS. +// ************************************************************************************************* + pub enum TypeInfo { FullName, ShortName, @@ -81,10 +208,6 @@ impl TypeInfo { } } -// ************************************************************************************************* -// FUNCTIONS HELPERS. -// ************************************************************************************************* - /// Calculates the absolute directory given a root path and a relative path. /// /// # Arguments diff --git a/src/lib.rs b/src/lib.rs index 4b0d9635..b83f82dc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -95,15 +95,15 @@ pub use std::any::TypeId; pub type Weight = i8; +// Global settings, functions and macro helpers. +pub mod global; + static_locales!(LOCALES_PAGETOP); // ************************************************************************************************* // PUBLIC API. // ************************************************************************************************* -// Functions and macro helpers. -pub mod util; - // Retrieve and apply settings values from configuration files. pub mod config; // Application tracing and event logging. diff --git a/src/locale.rs b/src/locale.rs index 4bed2aa9..56979f05 100644 --- a/src/locale.rs +++ b/src/locale.rs @@ -87,7 +87,7 @@ //! ``` use crate::html::{Markup, PreEscaped}; -use crate::{config, kv, AutoDefault, LOCALES_PAGETOP}; +use crate::{global, kv, AutoDefault, LOCALES_PAGETOP}; pub use fluent_templates; pub use unic_langid::LanguageIdentifier; @@ -120,7 +120,7 @@ pub static LANGID_FALLBACK: LazyLock = LazyLock::new(|| lang /// [Unicode Language Identifier](https://unicode.org/reports/tr35/tr35.html#Unicode_language_identifier) /// through `SETTINGS.app.language`. pub static LANGID_DEFAULT: LazyLock<&LanguageIdentifier> = LazyLock::new(|| { - langid_for(config::SETTINGS.app.language.as_str()).unwrap_or(&LANGID_FALLBACK) + langid_for(global::SETTINGS.app.language.as_str()).unwrap_or(&LANGID_FALLBACK) }); pub fn langid_for(language: impl Into) -> Result<&'static LanguageIdentifier, String> { diff --git a/src/prelude.rs b/src/prelude.rs index f98a6675..450974df 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -5,29 +5,25 @@ pub use crate::{concat_string, fn_builder, main, paste, test}; pub use crate::{AutoDefault, ComponentClasses}; // GLOBAL. -pub use crate::{HashMapResources, TypeId, Weight}; +pub use crate::{global, HashMapResources, TypeId, Weight}; // MACROS. +// crate::global +pub use crate::kv; // crate::config -pub use crate::default_settings; +pub use crate::config_defaults; // crate::html pub use crate::html; // crate::locale pub use crate::static_locales; // crate::service -pub use crate::{service_for_static_files, static_files}; +pub use crate::{static_files, static_files_service}; // crate::core::action pub use crate::actions; -// crate::util -pub use crate::kv; // API. -pub use crate::util; - -pub use crate::config; - pub use crate::trace; pub use crate::html::*; diff --git a/src/service.rs b/src/service.rs index 26a88ca5..379472e3 100644 --- a/src/service.rs +++ b/src/service.rs @@ -34,7 +34,7 @@ macro_rules! static_files { } #[macro_export] -macro_rules! service_for_static_files { +macro_rules! static_files_service { ( $scfg:ident, $bundle:ident => $path:expr $(, [$root:expr, $relative:expr])? ) => {{ $crate::paste! { let span = $crate::trace::debug_span!("Configuring static files ", path = $path); @@ -42,7 +42,7 @@ macro_rules! service_for_static_files { let mut serve_embedded:bool = true; $( if !$root.is_empty() && !$relative.is_empty() { - if let Ok(absolute) = $crate::util::absolute_dir($root, $relative) { + if let Ok(absolute) = $crate::global::absolute_dir($root, $relative) { $scfg.service($crate::service::ActixFiles::new( $path, absolute, diff --git a/src/trace.rs b/src/trace.rs index 7c717eaf..6e42d790 100644 --- a/src/trace.rs +++ b/src/trace.rs @@ -12,7 +12,7 @@ //! within a nested tree of similar spans. Additionally, these spans are *structured*, with the //! ability to record data types and text messages. -use crate::config; +use crate::global; pub use tracing::{debug, error, info, trace, warn}; pub use tracing::{debug_span, error_span, info_span, trace_span, warn_span}; @@ -35,16 +35,16 @@ use std::sync::LazyLock; #[rustfmt::skip] pub(crate) static TRACING: LazyLock = LazyLock::new(|| { - let env_filter = EnvFilter::try_new(&config::SETTINGS.log.tracing) + let env_filter = EnvFilter::try_new(&global::SETTINGS.log.tracing) .unwrap_or_else(|_| EnvFilter::new("Info")); - let rolling = config::SETTINGS.log.rolling.to_lowercase(); + let rolling = global::SETTINGS.log.rolling.to_lowercase(); let (non_blocking, guard) = match rolling.as_str() { "stdout" => tracing_appender::non_blocking(std::io::stdout()), _ => tracing_appender::non_blocking({ - let path = &config::SETTINGS.log.path; - let prefix = &config::SETTINGS.log.prefix; + let path = &global::SETTINGS.log.path; + let prefix = &global::SETTINGS.log.prefix; match rolling.as_str() { "daily" => tracing_appender::rolling::daily(path, prefix), "hourly" => tracing_appender::rolling::hourly(path, prefix), @@ -53,7 +53,7 @@ pub(crate) static TRACING: LazyLock = LazyLock::new(|| { _ => { println!( "Rolling value \"{}\" not valid. Using \"daily\". Check the settings file.", - config::SETTINGS.log.rolling, + global::SETTINGS.log.rolling, ); tracing_appender::rolling::daily(path, prefix) } @@ -66,7 +66,7 @@ pub(crate) static TRACING: LazyLock = LazyLock::new(|| { .with_writer(non_blocking) .with_ansi(rolling.as_str() == "stdout"); - match config::SETTINGS.log.format.to_lowercase().as_str() { + match global::SETTINGS.log.format.to_lowercase().as_str() { "json" => subscriber.json().init(), "full" => subscriber.init(), "compact" => subscriber.compact().init(), @@ -74,7 +74,7 @@ pub(crate) static TRACING: LazyLock = LazyLock::new(|| { _ => { println!( "Tracing format \"{}\" not valid. Using \"Full\". Check the settings file.", - config::SETTINGS.log.format, + global::SETTINGS.log.format, ); subscriber.init(); }