diff --git a/pagetop-user/src/lib.rs b/pagetop-user/src/lib.rs index d45a2259..22c14c41 100644 --- a/pagetop-user/src/lib.rs +++ b/pagetop-user/src/lib.rs @@ -58,7 +58,7 @@ fn form_login() -> Form { t( "username_help", &args![ - "app" => config::get("app.name").to_owned() + "app" => SETTINGS.app.name.to_owned() ], ) .as_str(), diff --git a/pagetop/src/app/application.rs b/pagetop/src/app/application.rs index 2ad4d1f3..4875a0ee 100644 --- a/pagetop/src/app/application.rs +++ b/pagetop/src/app/application.rs @@ -1,5 +1,5 @@ use super::fatal_error::FatalError; -use crate::config; +use crate::config::SETTINGS; use crate::core::module::ModuleStaticRef; use crate::core::{module, theme}; use crate::html::Markup; @@ -39,7 +39,7 @@ impl Application { module::all::register_actions(); // Inicializa valores predefinidos de configuración. - module::all::init_settings(); + // module::all::init_settings(); // Inicializa los módulos. module::all::init_modules(); @@ -58,8 +58,8 @@ impl Application { }) .bind(format!( "{}:{}", - config::get("webserver.bind_address"), - config::get("webserver.bind_port") + &SETTINGS.webserver.bind_address, + &SETTINGS.webserver.bind_port ))? .run(); diff --git a/pagetop/src/app/banner.rs b/pagetop/src/app/banner.rs index eb52f4a5..1e50e54a 100644 --- a/pagetop/src/app/banner.rs +++ b/pagetop/src/app/banner.rs @@ -1,23 +1,23 @@ mod figfont; use figfont::FIGFONT; -use crate::config; +use crate::config::SETTINGS; use substring::Substring; pub fn print_on_startup() { - if config::get("app.startup_banner").to_lowercase() != "off" { + if SETTINGS.app.startup_banner.to_lowercase() != "off" { if let Some((term_width, _)) = term_size::dimensions() { if term_width >= 80 { let maxlen = (term_width / 10) - 2; - let mut app = config::get("app.name").substring(0, maxlen).to_owned(); - if config::get("app.name").len() > maxlen { + let mut app = SETTINGS.app.name.substring(0, maxlen).to_owned(); + if SETTINGS.app.name.len() > maxlen { app = format!("{}...", app); } println!( "\n{} {}\n\n Powered by PageTop {}\n", FIGFONT.convert(&app).unwrap(), - config::get("app.description"), + &SETTINGS.app.description, env!("CARGO_PKG_VERSION") ); return; @@ -25,8 +25,8 @@ pub fn print_on_startup() { } println!( "\n{}\n{}\n\nPowered by PageTop {}\n", - config::get("app.name"), - config::get("app.description"), + &SETTINGS.app.name, + &SETTINGS.app.description, env!("CARGO_PKG_VERSION") ); } diff --git a/pagetop/src/app/banner/figfont.rs b/pagetop/src/app/banner/figfont.rs index 48321dc8..d92fe35a 100644 --- a/pagetop/src/app/banner/figfont.rs +++ b/pagetop/src/app/banner/figfont.rs @@ -1,4 +1,5 @@ -use crate::{config, LazyStatic}; +use crate::config::SETTINGS; +use crate::LazyStatic; use figlet_rs::FIGfont; @@ -8,7 +9,7 @@ pub static FIGFONT: LazyStatic = LazyStatic::new(|| { let speed = include_str!("speed.flf"); let starwars = include_str!("starwars.flf"); - FIGfont::from_content(match config::get("app.startup_banner").to_lowercase().as_str() { + FIGfont::from_content(match SETTINGS.app.startup_banner.to_lowercase().as_str() { "off" => slant, "slant" => slant, "small" => small, @@ -17,7 +18,7 @@ pub static FIGFONT: LazyStatic = LazyStatic::new(|| { _ => { println!( "\n FIGfont \"{}\" not found for banner. Using \"Slant\". Check the settings file.", - config::get("app.startup_banner"), + SETTINGS.app.startup_banner, ); slant } diff --git a/pagetop/src/app/db.rs b/pagetop/src/app/db.rs index 61aec6fe..37b3b505 100644 --- a/pagetop/src/app/db.rs +++ b/pagetop/src/app/db.rs @@ -1,4 +1,4 @@ -use crate::config; +use crate::config::SETTINGS; use crate::db::*; use crate::{run_now, trace, LazyStatic}; @@ -8,38 +8,39 @@ use tracing_unwrap::ResultExt; pub static DBCONN: LazyStatic = LazyStatic::new(|| { trace::info!( "Connecting to database \"{}\" using a pool of {} connections", - config::get("database.db_name"), - config::get("database.max_pool_size") + &SETTINGS.database.db_name, + &SETTINGS.database.max_pool_size ); - let db_uri = match config::get("database.db_type").as_str() { + let db_uri = match SETTINGS.database.db_type.as_str() { "mysql" | "postgres" => { let mut tmp_uri = DbUri::parse( format!( "{}://{}/{}", - config::get("database.db_type"), - config::get("database.db_host"), - config::get("database.db_name") + &SETTINGS.database.db_type, + &SETTINGS.database.db_host, + &SETTINGS.database.db_name ) .as_str(), ) .unwrap(); tmp_uri - .set_username(config::get("database.db_user").as_str()) + .set_username(SETTINGS.database.db_user.as_str()) .unwrap(); // https://github.com/launchbadge/sqlx/issues/1624 tmp_uri - .set_password(Some(config::get("database.db_pass").as_str())) + .set_password(Some(SETTINGS.database.db_pass.as_str())) .unwrap(); - if config::get_value::("database.db_port") != 0 { - tmp_uri.set_port(Some(config::get_value::("database.db_port"))).unwrap(); + if SETTINGS.database.db_port != 0 { + tmp_uri.set_port(Some(SETTINGS.database.db_port)).unwrap(); } tmp_uri } "sqlite" => DbUri::parse( format!( "{}://{}", - config::get("database.db_type"), &config::get("database.db_name") + &SETTINGS.database.db_type, + &SETTINGS.database.db_name ) .as_str(), ) @@ -47,7 +48,7 @@ pub static DBCONN: LazyStatic = LazyStatic::new(|| { _ => { trace::error!( "Unrecognized database type \"{}\"", - config::get("database.db_type") + &SETTINGS.database.db_type ); DbUri::parse("").unwrap() } @@ -55,7 +56,7 @@ pub static DBCONN: LazyStatic = LazyStatic::new(|| { run_now(Database::connect::({ let mut db_opt = ConnectOptions::new(db_uri.to_string()); - db_opt.max_connections(config::get_value::("database.max_pool_size")); + db_opt.max_connections(SETTINGS.database.max_pool_size); db_opt })) .expect_or_log("Failed to connect to database") diff --git a/pagetop/src/app/locale.rs b/pagetop/src/app/locale.rs index 55d3abf7..9775867f 100644 --- a/pagetop/src/app/locale.rs +++ b/pagetop/src/app/locale.rs @@ -1,4 +1,5 @@ -use crate::{config, trace, LazyStatic}; +use crate::config::SETTINGS; +use crate::{trace, LazyStatic}; use unic_langid::LanguageIdentifier; @@ -6,14 +7,14 @@ use unic_langid::LanguageIdentifier; /// (https://unicode.org/reports/tr35/tr35.html#Unicode_language_identifier)) de /// la aplicación, obtenido de `SETTINGS.app.language`. pub static LANGID: LazyStatic = - LazyStatic::new(|| match config::get("app.language").parse() { + LazyStatic::new(|| match SETTINGS.app.language.parse() { Ok(language) => language, Err(_) => { trace::warn!( "{}, {} \"{}\"! {}, {}", "Failed to parse language", "unrecognized Unicode Language Identifier", - config::get("app.language"), + SETTINGS.app.language, "Using \"en-US\"", "check the settings file", ); diff --git a/pagetop/src/app/tracing.rs b/pagetop/src/app/tracing.rs index d2450ac3..bc6bf515 100644 --- a/pagetop/src/app/tracing.rs +++ b/pagetop/src/app/tracing.rs @@ -1,4 +1,5 @@ -use crate::{config, LazyStatic}; +use crate::config::SETTINGS; +use crate::LazyStatic; use tracing_appender::non_blocking::WorkerGuard; use tracing_subscriber::EnvFilter; @@ -19,14 +20,14 @@ use tracing_subscriber::EnvFilter; #[rustfmt::skip] pub static TRACING: LazyStatic = LazyStatic::new(|| { let env_filter = - EnvFilter::try_new(config::get("log.tracing")).unwrap_or_else(|_| EnvFilter::new("Info")); + EnvFilter::try_new(&SETTINGS.log.tracing).unwrap_or_else(|_| EnvFilter::new("Info")); - let rolling = config::get("log.rolling").to_lowercase(); + let rolling = 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::get("log.path"); - let prefix = config::get("log.prefix"); + let path = &SETTINGS.log.path; + let prefix = &SETTINGS.log.prefix; match rolling.as_str() { "daily" => tracing_appender::rolling::daily(path, prefix), "hourly" => tracing_appender::rolling::hourly(path, prefix), @@ -35,7 +36,7 @@ pub static TRACING: LazyStatic = LazyStatic::new(|| { _ => { println!( "Rolling value \"{}\" not valid. Using \"daily\". Check the settings file.", - config::get("log.rolling"), + SETTINGS.log.rolling, ); tracing_appender::rolling::daily(path, prefix) } @@ -46,7 +47,7 @@ pub static TRACING: LazyStatic = LazyStatic::new(|| { .with_env_filter(env_filter) .with_writer(non_blocking) .with_ansi(rolling.as_str() == "stdout"); - match config::get("log.format").to_lowercase().as_str() { + match SETTINGS.log.format.to_lowercase().as_str() { "json" => subscriber.json().init(), "full" => subscriber.init(), "compact" => subscriber.compact().init(), @@ -54,7 +55,7 @@ pub static TRACING: LazyStatic = LazyStatic::new(|| { _ => { println!( "Tracing format \"{}\" not valid. Using \"Full\". Check the settings file.", - config::get("log.format"), + SETTINGS.log.format, ); subscriber.init(); } diff --git a/pagetop/src/base/module/homepage.rs b/pagetop/src/base/module/homepage.rs index e51fbbf4..92a3628b 100644 --- a/pagetop/src/base/module/homepage.rs +++ b/pagetop/src/base/module/homepage.rs @@ -55,7 +55,7 @@ fn hello_world() -> Container { .with_component( Paragraph::with(html! { (e("hello_intro", &args![ - "app" => format!("{}", config::get("app.name")) + "app" => format!("{}", &SETTINGS.app.name) ])) }) .with_display(ParagraphDisplay::Small), @@ -101,7 +101,7 @@ fn welcome() -> Container { .with_component( Heading::h3(html! { (e("welcome_subtitle", &args![ - "app" => format!("{}", config::get("app.name")) + "app" => format!("{}", &SETTINGS.app.name) ])) }) .with_display(HeadingDisplay::Subtitle), diff --git a/pagetop/src/core/module/all.rs b/pagetop/src/core/module/all.rs index 3ac7ff8b..12e461d1 100644 --- a/pagetop/src/core/module/all.rs +++ b/pagetop/src/core/module/all.rs @@ -1,5 +1,4 @@ use super::ModuleStaticRef; -use crate::config; use crate::core::hook::add_action; use crate::core::theme; use crate::{app, trace, LazyStatic}; @@ -87,14 +86,14 @@ pub fn register_actions() { } // INIT SETTINGS *********************************************************************************** - +/* pub fn init_settings() { trace::info!("initializing custom predefined settings"); for m in ENABLED_MODULES.read().unwrap().iter() { - config::add_predefined_settings(m.settings()); + settings::add_predefined_settings(m.settings()); } } - +*/ // INIT MODULES ************************************************************************************ pub fn init_modules() { diff --git a/pagetop/src/core/module/definition.rs b/pagetop/src/core/module/definition.rs index 8ad2bf71..110fe9bb 100644 --- a/pagetop/src/core/module/definition.rs +++ b/pagetop/src/core/module/definition.rs @@ -1,6 +1,6 @@ use crate::app; -use crate::predefined_settings; -use crate::config::PredefinedSettings; +//use crate::predefined_settings; +//use crate::settings::PredefinedSettings; use crate::core::hook::HookAction; use crate::core::theme::ThemeStaticRef; use crate::util::{single_type_name, Handler}; @@ -41,11 +41,11 @@ pub trait ModuleTrait: BaseModule + Send + Sync { fn actions(&self) -> Vec { vec![] } - +/* fn settings(&self) -> PredefinedSettings { predefined_settings![] } - +*/ fn init(&self) {} #[cfg(feature = "database")] diff --git a/pagetop/src/core/theme/definition.rs b/pagetop/src/core/theme/definition.rs index 68bf1368..ee3abcbf 100644 --- a/pagetop/src/core/theme/definition.rs +++ b/pagetop/src/core/theme/definition.rs @@ -1,7 +1,7 @@ use crate::app; use crate::base::component::{Container, Html}; use crate::concat_string; -use crate::config; +use crate::config::SETTINGS; use crate::core::component::ComponentTrait; use crate::html::{html, Favicon, Markup}; use crate::response::page::{Page, PageContext, PageOp}; @@ -43,9 +43,9 @@ pub trait ThemeTrait: BaseTheme + Send + Sync { @match page.title().get() { Some(t) => title { - (concat_string!(config::get("app.name"), " | ", t)) + (concat_string!(SETTINGS.app.name, " | ", t)) }, - None => title { (config::get("app.name")) } + None => title { (SETTINGS.app.name) } } @match page.description().get() { diff --git a/pagetop/src/lib.rs b/pagetop/src/lib.rs index a61ee3ad..e9b2c650 100644 --- a/pagetop/src/lib.rs +++ b/pagetop/src/lib.rs @@ -40,6 +40,7 @@ // GLOBAL. pub use concat_string::concat_string; +pub use doc_comment::doc_comment; pub use once_cell::sync::Lazy as LazyStatic; // LOCAL. diff --git a/pagetop/src/prelude.rs b/pagetop/src/prelude.rs index a461ffbb..a8e21580 100644 --- a/pagetop/src/prelude.rs +++ b/pagetop/src/prelude.rs @@ -5,8 +5,7 @@ pub use crate::{ args, concat_string, configure_service_for_static_files, pub_const_handler, LazyStatic, }; -pub use crate::config; -pub use crate::config::PredefinedSettings; +pub use crate::config::SETTINGS; pub use crate::trace; diff --git a/pagetop/src/response/page/context.rs b/pagetop/src/response/page/context.rs index 4a9c3036..055fa781 100644 --- a/pagetop/src/response/page/context.rs +++ b/pagetop/src/response/page/context.rs @@ -1,11 +1,11 @@ use super::PageOp; -use crate::config; +use crate::config::SETTINGS; use crate::core::theme::{all::theme_by_single_name, ThemeStaticRef}; use crate::html::{html, Assets, Favicon, IdentifierValue, JavaScript, Markup, ModeJS, StyleSheet}; use crate::{base, concat_string, util, LazyStatic}; static DEFAULT_THEME: LazyStatic = - LazyStatic::new(|| match theme_by_single_name(&config::get("app.theme")) { + LazyStatic::new(|| match theme_by_single_name(&SETTINGS.app.theme) { Some(theme) => theme, None => &base::theme::bootsier::Bootsier, }); diff --git a/pagetop/src/response/page/definition.rs b/pagetop/src/response/page/definition.rs index 82e1c499..3617b40d 100644 --- a/pagetop/src/response/page/definition.rs +++ b/pagetop/src/response/page/definition.rs @@ -1,6 +1,6 @@ use super::{BeforeRenderPageHook, PageContext, PageOp, ResultPage, HOOK_BEFORE_RENDER_PAGE}; use crate::app::fatal_error::FatalError; -use crate::config; +use crate::config::SETTINGS; use crate::core::component::*; use crate::core::hook::{action_ref, run_actions}; use crate::html::{html, AttributeValue, Classes, ClassesOp, Markup, DOCTYPE}; @@ -9,7 +9,7 @@ use crate::{trace, LazyStatic}; use std::collections::HashMap; static DEFAULT_LANGUAGE: LazyStatic> = LazyStatic::new(|| { - let language = config::get("app.language")[..2].to_lowercase(); + let language = SETTINGS.app.language[..2].to_lowercase(); if !language.is_empty() { Some(language) } else { @@ -18,7 +18,7 @@ static DEFAULT_LANGUAGE: LazyStatic> = LazyStatic::new(|| { }); static DEFAULT_DIRECTION: LazyStatic> = LazyStatic::new(|| { - let direction = config::get("app.direction").to_lowercase(); + let direction = SETTINGS.app.direction.to_lowercase(); match direction.as_str() { "auto" => Some("auto".to_owned()), "ltr" => Some("ltr".to_owned()), @@ -27,7 +27,7 @@ static DEFAULT_DIRECTION: LazyStatic> = LazyStatic::new(|| { _ => { trace::warn!( "Text direction \"{}\" not valid, {}", - config::get("app.direction"), + SETTINGS.app.direction, "check the settings file" ); None diff --git a/pagetop/src/util.rs b/pagetop/src/util.rs index a4358c02..68d20d3e 100644 --- a/pagetop/src/util.rs +++ b/pagetop/src/util.rs @@ -169,7 +169,7 @@ macro_rules! args { #[macro_export] macro_rules! configure_service_for_static_files { ( $cfg:ident, $dir:expr, $embed:ident ) => {{ - let static_files = $crate::config::get("dev.static_files"); + let static_files = &$crate::config::SETTINGS.dev.static_files; if static_files.is_empty() { $cfg.service($crate::app::ResourceFiles::new($dir, $embed())); } else {