♻️ Revierte parcialmente últimos cambios
This commit is contained in:
parent
19b4c251b0
commit
da8604980d
21 changed files with 356 additions and 353 deletions
|
|
@ -58,7 +58,7 @@ fn form_login() -> Form {
|
||||||
t(
|
t(
|
||||||
"username_help",
|
"username_help",
|
||||||
&args![
|
&args![
|
||||||
"app" => global::SETTINGS.app.name.to_owned()
|
"app" => config::SETTINGS.app.name.to_owned()
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
.as_str(),
|
.as_str(),
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ impl MigrationTrait for Migration {
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
// Built-in roles.
|
// Built-in roles.
|
||||||
db::exec::<InsertStatement>(
|
app::db::exec::<InsertStatement>(
|
||||||
Query::insert()
|
Query::insert()
|
||||||
.into_table(Role::Table)
|
.into_table(Role::Table)
|
||||||
.columns(vec![Role::Name, Role::Weight])
|
.columns(vec![Role::Name, Role::Weight])
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,13 @@ pub use actix_web_static_files::ResourceFiles;
|
||||||
|
|
||||||
mod banner;
|
mod banner;
|
||||||
|
|
||||||
|
mod tracing;
|
||||||
|
|
||||||
|
pub mod locale;
|
||||||
|
|
||||||
|
#[cfg(feature = "database")]
|
||||||
|
pub mod db;
|
||||||
|
|
||||||
pub mod application;
|
pub mod application;
|
||||||
|
|
||||||
pub mod fatal_error;
|
pub mod fatal_error;
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ use crate::core::module::ModuleStaticRef;
|
||||||
use crate::core::{module, theme};
|
use crate::core::{module, theme};
|
||||||
use crate::html::Markup;
|
use crate::html::Markup;
|
||||||
use crate::response::page::ResultPage;
|
use crate::response::page::ResultPage;
|
||||||
use crate::{global, LazyStatic};
|
use crate::{config, LazyStatic};
|
||||||
|
|
||||||
use actix_web::dev::Server;
|
use actix_web::dev::Server;
|
||||||
|
|
||||||
|
|
@ -20,14 +20,14 @@ impl Application {
|
||||||
super::banner::print_on_startup();
|
super::banner::print_on_startup();
|
||||||
|
|
||||||
// Inicia registro de trazas y eventos.
|
// Inicia registro de trazas y eventos.
|
||||||
LazyStatic::force(&global::TRACING);
|
LazyStatic::force(&super::tracing::TRACING);
|
||||||
|
|
||||||
// Valida el identificador de idioma.
|
// Valida el identificador de idioma.
|
||||||
LazyStatic::force(&global::LANGID);
|
LazyStatic::force(&super::locale::LANGID);
|
||||||
|
|
||||||
#[cfg(feature = "database")]
|
#[cfg(feature = "database")]
|
||||||
// Conecta con la base de datos.
|
// Conecta con la base de datos.
|
||||||
LazyStatic::force(&crate::db::DBCONN);
|
LazyStatic::force(&super::db::DBCONN);
|
||||||
|
|
||||||
// Registra los módulos de la aplicación.
|
// Registra los módulos de la aplicación.
|
||||||
module::all::register_modules(app);
|
module::all::register_modules(app);
|
||||||
|
|
@ -55,7 +55,7 @@ impl Application {
|
||||||
})
|
})
|
||||||
.bind(format!(
|
.bind(format!(
|
||||||
"{}:{}",
|
"{}:{}",
|
||||||
&global::SETTINGS.server.bind_address, &global::SETTINGS.server.bind_port
|
&config::SETTINGS.server.bind_address, &config::SETTINGS.server.bind_port
|
||||||
))?
|
))?
|
||||||
.run();
|
.run();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,24 @@
|
||||||
mod figfont;
|
mod figfont;
|
||||||
use figfont::FIGFONT;
|
use figfont::FIGFONT;
|
||||||
|
|
||||||
use crate::global;
|
use crate::config;
|
||||||
|
|
||||||
use substring::Substring;
|
use substring::Substring;
|
||||||
|
|
||||||
|
|
||||||
pub fn print_on_startup() {
|
pub fn print_on_startup() {
|
||||||
if global::SETTINGS.app.startup_banner.to_lowercase() != "off" {
|
if config::SETTINGS.app.startup_banner.to_lowercase() != "off" {
|
||||||
if let Some((term_width, _)) = term_size::dimensions() {
|
if let Some((term_width, _)) = term_size::dimensions() {
|
||||||
if term_width >= 80 {
|
if term_width >= 80 {
|
||||||
let maxlen = (term_width / 10) - 2;
|
let maxlen = (term_width / 10) - 2;
|
||||||
let mut app = global::SETTINGS.app.name.substring(0, maxlen).to_owned();
|
let mut app = config::SETTINGS.app.name.substring(0, maxlen).to_owned();
|
||||||
if global::SETTINGS.app.name.len() > maxlen {
|
if config::SETTINGS.app.name.len() > maxlen {
|
||||||
app = format!("{}...", app);
|
app = format!("{}...", app);
|
||||||
}
|
}
|
||||||
println!(
|
println!(
|
||||||
"\n{} {}\n\n Powered by PageTop {}\n",
|
"\n{} {}\n\n Powered by PageTop {}\n",
|
||||||
FIGFONT.convert(&app).unwrap(),
|
FIGFONT.convert(&app).unwrap(),
|
||||||
&global::SETTINGS.app.description,
|
&config::SETTINGS.app.description,
|
||||||
env!("CARGO_PKG_VERSION")
|
env!("CARGO_PKG_VERSION")
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
|
|
@ -25,8 +26,8 @@ pub fn print_on_startup() {
|
||||||
}
|
}
|
||||||
println!(
|
println!(
|
||||||
"\n{}\n{}\n\nPowered by PageTop {}\n",
|
"\n{}\n{}\n\nPowered by PageTop {}\n",
|
||||||
&global::SETTINGS.app.name,
|
&config::SETTINGS.app.name,
|
||||||
&global::SETTINGS.app.description,
|
&config::SETTINGS.app.description,
|
||||||
env!("CARGO_PKG_VERSION")
|
env!("CARGO_PKG_VERSION")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{global, LazyStatic};
|
use crate::{config, LazyStatic};
|
||||||
|
|
||||||
use figlet_rs::FIGfont;
|
use figlet_rs::FIGfont;
|
||||||
|
|
||||||
|
|
@ -8,7 +8,7 @@ pub static FIGFONT: LazyStatic<FIGfont> = LazyStatic::new(|| {
|
||||||
let speed = include_str!("speed.flf");
|
let speed = include_str!("speed.flf");
|
||||||
let starwars = include_str!("starwars.flf");
|
let starwars = include_str!("starwars.flf");
|
||||||
|
|
||||||
FIGfont::from_content(match global::SETTINGS.app.startup_banner.to_lowercase().as_str() {
|
FIGfont::from_content(match config::SETTINGS.app.startup_banner.to_lowercase().as_str() {
|
||||||
"off" => slant,
|
"off" => slant,
|
||||||
"slant" => slant,
|
"slant" => slant,
|
||||||
"small" => small,
|
"small" => small,
|
||||||
|
|
@ -17,7 +17,7 @@ pub static FIGFONT: LazyStatic<FIGfont> = LazyStatic::new(|| {
|
||||||
_ => {
|
_ => {
|
||||||
println!(
|
println!(
|
||||||
"\n FIGfont \"{}\" not found for banner. Using \"Slant\". Check settings files.",
|
"\n FIGfont \"{}\" not found for banner. Using \"Slant\". Check settings files.",
|
||||||
global::SETTINGS.app.startup_banner,
|
config::SETTINGS.app.startup_banner,
|
||||||
);
|
);
|
||||||
slant
|
slant
|
||||||
}
|
}
|
||||||
|
|
|
||||||
99
pagetop/src/app/db.rs
Normal file
99
pagetop/src/app/db.rs
Normal file
|
|
@ -0,0 +1,99 @@
|
||||||
|
use crate::{config, run_now, trace, LazyStatic};
|
||||||
|
use crate::db::*;
|
||||||
|
|
||||||
|
use sea_orm::{ConnectOptions, ConnectionTrait, Database, DatabaseBackend, Statement};
|
||||||
|
use tracing_unwrap::ResultExt;
|
||||||
|
|
||||||
|
|
||||||
|
pub static DBCONN: LazyStatic<DbConn> = LazyStatic::new(|| {
|
||||||
|
trace::info!(
|
||||||
|
"Connecting to database \"{}\" using a pool of {} connections",
|
||||||
|
&config::SETTINGS.database.db_name,
|
||||||
|
&config::SETTINGS.database.max_pool_size
|
||||||
|
);
|
||||||
|
|
||||||
|
let db_uri = match config::SETTINGS.database.db_type.as_str() {
|
||||||
|
"mysql" | "postgres" => {
|
||||||
|
let mut tmp_uri = DbUri::parse(
|
||||||
|
format!(
|
||||||
|
"{}://{}/{}",
|
||||||
|
&config::SETTINGS.database.db_type,
|
||||||
|
&config::SETTINGS.database.db_host,
|
||||||
|
&config::SETTINGS.database.db_name
|
||||||
|
)
|
||||||
|
.as_str(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
tmp_uri
|
||||||
|
.set_username(config::SETTINGS.database.db_user.as_str())
|
||||||
|
.unwrap();
|
||||||
|
// https://github.com/launchbadge/sqlx/issues/1624
|
||||||
|
tmp_uri
|
||||||
|
.set_password(Some(config::SETTINGS.database.db_pass.as_str()))
|
||||||
|
.unwrap();
|
||||||
|
if config::SETTINGS.database.db_port != 0 {
|
||||||
|
tmp_uri.set_port(Some(config::SETTINGS.database.db_port)).unwrap();
|
||||||
|
}
|
||||||
|
tmp_uri
|
||||||
|
}
|
||||||
|
"sqlite" => DbUri::parse(
|
||||||
|
format!(
|
||||||
|
"{}://{}",
|
||||||
|
&config::SETTINGS.database.db_type, &config::SETTINGS.database.db_name
|
||||||
|
)
|
||||||
|
.as_str(),
|
||||||
|
)
|
||||||
|
.unwrap(),
|
||||||
|
_ => {
|
||||||
|
trace::error!(
|
||||||
|
"Unrecognized database type \"{}\"",
|
||||||
|
&config::SETTINGS.database.db_type
|
||||||
|
);
|
||||||
|
DbUri::parse("").unwrap()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
run_now(Database::connect::<ConnectOptions>({
|
||||||
|
let mut db_opt = ConnectOptions::new(db_uri.to_string());
|
||||||
|
db_opt.max_connections(config::SETTINGS.database.max_pool_size);
|
||||||
|
db_opt
|
||||||
|
}))
|
||||||
|
.expect_or_log("Failed to connect to database")
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
static DBBACKEND: LazyStatic<DatabaseBackend> = LazyStatic::new(||
|
||||||
|
DBCONN.get_database_backend()
|
||||||
|
);
|
||||||
|
|
||||||
|
pub async fn query<Q: QueryStatementWriter>(stmt: &mut Q) -> Result<Vec<QueryResult>, DbErr> {
|
||||||
|
DBCONN
|
||||||
|
.query_all(Statement::from_string(
|
||||||
|
*DBBACKEND,
|
||||||
|
match *DBBACKEND {
|
||||||
|
DatabaseBackend::MySql => stmt.to_string(MysqlQueryBuilder),
|
||||||
|
DatabaseBackend::Postgres => stmt.to_string(PostgresQueryBuilder),
|
||||||
|
DatabaseBackend::Sqlite => stmt.to_string(SqliteQueryBuilder),
|
||||||
|
},
|
||||||
|
))
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn exec<Q: QueryStatementWriter>(stmt: &mut Q) -> Result<Option<QueryResult>, DbErr> {
|
||||||
|
DBCONN
|
||||||
|
.query_one(Statement::from_string(
|
||||||
|
*DBBACKEND,
|
||||||
|
match *DBBACKEND {
|
||||||
|
DatabaseBackend::MySql => stmt.to_string(MysqlQueryBuilder),
|
||||||
|
DatabaseBackend::Postgres => stmt.to_string(PostgresQueryBuilder),
|
||||||
|
DatabaseBackend::Sqlite => stmt.to_string(SqliteQueryBuilder),
|
||||||
|
},
|
||||||
|
))
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn exec_raw(stmt: String) -> Result<ExecResult, DbErr> {
|
||||||
|
DBCONN
|
||||||
|
.execute(Statement::from_string(*DBBACKEND, stmt))
|
||||||
|
.await
|
||||||
|
}
|
||||||
24
pagetop/src/app/locale.rs
Normal file
24
pagetop/src/app/locale.rs
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
use crate::{config, trace, LazyStatic};
|
||||||
|
|
||||||
|
use unic_langid::LanguageIdentifier;
|
||||||
|
|
||||||
|
// LOCALIZACIÓN ************************************************************************************
|
||||||
|
|
||||||
|
/// Almacena el Identificador de Idioma Unicode
|
||||||
|
/// ([Unicode Language Identifier](https://unicode.org/reports/tr35/tr35.html#Unicode_language_identifier))
|
||||||
|
/// global para la aplicación, obtenido de `SETTINGS.app.language`.
|
||||||
|
pub static LANGID: LazyStatic<LanguageIdentifier> =
|
||||||
|
LazyStatic::new(|| match config::SETTINGS.app.language.parse() {
|
||||||
|
Ok(language) => language,
|
||||||
|
Err(_) => {
|
||||||
|
trace::warn!(
|
||||||
|
"{}, {} \"{}\"! {}, {}",
|
||||||
|
"Failed to parse language",
|
||||||
|
"unrecognized Unicode Language Identifier",
|
||||||
|
config::SETTINGS.app.language,
|
||||||
|
"Using \"en-US\"",
|
||||||
|
"check the settings file",
|
||||||
|
);
|
||||||
|
"en-US".parse().unwrap()
|
||||||
|
}
|
||||||
|
});
|
||||||
63
pagetop/src/app/tracing.rs
Normal file
63
pagetop/src/app/tracing.rs
Normal file
|
|
@ -0,0 +1,63 @@
|
||||||
|
use crate::{config, LazyStatic};
|
||||||
|
|
||||||
|
use tracing_appender::non_blocking::WorkerGuard;
|
||||||
|
use tracing_subscriber::EnvFilter;
|
||||||
|
|
||||||
|
|
||||||
|
/// Registro de trazas y eventos de la aplicación.
|
||||||
|
///
|
||||||
|
/// Para aumentar el rendimiento, un subproceso dedicado utiliza un sistema de escritura sin bloqueo
|
||||||
|
/// (*non-blocking writer*) que actúa periódicamente en vez de enviar cada traza o evento al
|
||||||
|
/// instante. Si el programa termina abruptamente (por ejemplo, por un panic! o un
|
||||||
|
/// std::process::exit), es posible que algunas trazas o eventos no se envíen.
|
||||||
|
///
|
||||||
|
/// Puesto que las trazas o eventos registrados poco antes de la caída de una aplicación suelen ser
|
||||||
|
/// importantes para diagnosticar la causa del fallo, con `Lazy<WorkerGuard>` se garantiza que todos
|
||||||
|
/// los registros almacenados se enviarán antes de terminar la ejecución.
|
||||||
|
|
||||||
|
#[rustfmt::skip]
|
||||||
|
pub static TRACING: LazyStatic<WorkerGuard> = LazyStatic::new(|| {
|
||||||
|
let env_filter =
|
||||||
|
EnvFilter::try_new(&config::SETTINGS.log.tracing).unwrap_or_else(|_| EnvFilter::new("Info"));
|
||||||
|
|
||||||
|
let rolling = config::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;
|
||||||
|
match rolling.as_str() {
|
||||||
|
"daily" => tracing_appender::rolling::daily(path, prefix),
|
||||||
|
"hourly" => tracing_appender::rolling::hourly(path, prefix),
|
||||||
|
"minutely" => tracing_appender::rolling::minutely(path, prefix),
|
||||||
|
"endless" => tracing_appender::rolling::never(path, prefix),
|
||||||
|
_ => {
|
||||||
|
println!(
|
||||||
|
"Rolling value \"{}\" not valid. Using \"daily\". Check the settings file.",
|
||||||
|
config::SETTINGS.log.rolling,
|
||||||
|
);
|
||||||
|
tracing_appender::rolling::daily(path, prefix)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
let subscriber = tracing_subscriber::fmt()
|
||||||
|
.with_env_filter(env_filter)
|
||||||
|
.with_writer(non_blocking)
|
||||||
|
.with_ansi(rolling.as_str() == "stdout");
|
||||||
|
match config::SETTINGS.log.format.to_lowercase().as_str() {
|
||||||
|
"json" => subscriber.json().init(),
|
||||||
|
"full" => subscriber.init(),
|
||||||
|
"compact" => subscriber.compact().init(),
|
||||||
|
"pretty" => subscriber.pretty().init(),
|
||||||
|
_ => {
|
||||||
|
println!(
|
||||||
|
"Tracing format \"{}\" not valid. Using \"Full\". Check the settings file.",
|
||||||
|
config::SETTINGS.log.format,
|
||||||
|
);
|
||||||
|
subscriber.init();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
guard
|
||||||
|
});
|
||||||
|
|
@ -57,7 +57,7 @@ fn hello_world() -> Container {
|
||||||
(e("hello_intro", &args![
|
(e("hello_intro", &args![
|
||||||
"app" => format!(
|
"app" => format!(
|
||||||
"<span class=\"app-name\">{}</span>",
|
"<span class=\"app-name\">{}</span>",
|
||||||
&global::SETTINGS.app.name,
|
&config::SETTINGS.app.name,
|
||||||
)
|
)
|
||||||
]))
|
]))
|
||||||
})
|
})
|
||||||
|
|
@ -110,7 +110,7 @@ fn welcome() -> Container {
|
||||||
(e("welcome_subtitle", &args![
|
(e("welcome_subtitle", &args![
|
||||||
"app" => format!(
|
"app" => format!(
|
||||||
"<span class=\"app-name\">{}</span>",
|
"<span class=\"app-name\">{}</span>",
|
||||||
&global::SETTINGS.app.name
|
&config::SETTINGS.app.name
|
||||||
)
|
)
|
||||||
]))
|
]))
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -124,8 +124,11 @@ use crate::LazyStatic;
|
||||||
use crate::config::data::ConfigData;
|
use crate::config::data::ConfigData;
|
||||||
use crate::config::file::File;
|
use crate::config::file::File;
|
||||||
|
|
||||||
|
use serde::Deserialize;
|
||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
|
|
||||||
/// Directorio donde se encuentran los archivos de configuración.
|
/// Directorio donde se encuentran los archivos de configuración.
|
||||||
const CONFIG_DIR: &str = "config";
|
const CONFIG_DIR: &str = "config";
|
||||||
|
|
||||||
|
|
@ -180,3 +183,127 @@ macro_rules! pub_config {
|
||||||
});
|
});
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
/// Ajustes globales para las secciones reservadas [`[app]`](App), [`[database]`](Database),
|
||||||
|
/// [`[dev]`](Dev), [`[log]`](Log) y [`[server]`](Server) (ver [`SETTINGS`]).
|
||||||
|
pub struct Settings {
|
||||||
|
pub app: App,
|
||||||
|
pub database: Database,
|
||||||
|
pub dev: Dev,
|
||||||
|
pub log: Log,
|
||||||
|
pub server: Server,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
/// Sección `[app]` de los ajustes globales.
|
||||||
|
///
|
||||||
|
/// Ver [`Settings`].
|
||||||
|
pub struct App {
|
||||||
|
/// Valor predefinido: *"PageTop Application"*
|
||||||
|
pub name: String,
|
||||||
|
/// Valor predefinido: *"Developed with the amazing PageTop framework."*
|
||||||
|
pub description: String,
|
||||||
|
/// Valor predefinido: *"Bootsier"*
|
||||||
|
pub theme: String,
|
||||||
|
/// Valor predefinido: *"en-US"*
|
||||||
|
pub language: String,
|
||||||
|
/// Valor predefinido: *"ltr"*
|
||||||
|
pub direction: String,
|
||||||
|
/// Valor predefinido: *"Slant"*
|
||||||
|
pub startup_banner: String,
|
||||||
|
/// Valor predefinido: según variable de entorno PAGETOP_RUN_MODE, o *"default"* si no lo está
|
||||||
|
pub run_mode: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
/// Sección `[database]` de los ajustes globales.
|
||||||
|
///
|
||||||
|
/// Ver [`Settings`].
|
||||||
|
pub struct Database {
|
||||||
|
/// Valor predefinido: *""*
|
||||||
|
pub db_type: String,
|
||||||
|
/// Valor predefinido: *""*
|
||||||
|
pub db_name: String,
|
||||||
|
/// Valor predefinido: *""*
|
||||||
|
pub db_user: String,
|
||||||
|
/// Valor predefinido: *""*
|
||||||
|
pub db_pass: String,
|
||||||
|
/// Valor predefinido: *"localhost"*
|
||||||
|
pub db_host: String,
|
||||||
|
/// Valor predefinido: *0*
|
||||||
|
pub db_port: u16,
|
||||||
|
/// Valor predefinido: *5*
|
||||||
|
pub max_pool_size: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
/// Sección `[dev]` de los ajustes globales.
|
||||||
|
///
|
||||||
|
/// Ver [`Settings`].
|
||||||
|
pub struct Dev {
|
||||||
|
/// Valor predefinido: *""*
|
||||||
|
pub static_files: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
/// Sección `[log]` de los ajustes globales.
|
||||||
|
///
|
||||||
|
/// Ver [`Settings`].
|
||||||
|
pub struct Log {
|
||||||
|
/// Valor predefinido: *"Info"*
|
||||||
|
pub tracing: String,
|
||||||
|
/// Valor predefinido: *"Stdout"*
|
||||||
|
pub rolling: String,
|
||||||
|
/// Valor predefinido: *"log"*
|
||||||
|
pub path: String,
|
||||||
|
/// Valor predefinido: *"tracing.log"*
|
||||||
|
pub prefix: String,
|
||||||
|
/// Valor predefinido: *"Full"*
|
||||||
|
pub format: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
/// Sección `[server]` de los ajustes globales.
|
||||||
|
///
|
||||||
|
/// Ver [`Settings`].
|
||||||
|
pub struct Server {
|
||||||
|
/// Valor predefinido: *"localhost"*
|
||||||
|
pub bind_address: String,
|
||||||
|
/// Valor predefinido: *8088*
|
||||||
|
pub bind_port: u16,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub_config!(SETTINGS: Settings,
|
||||||
|
// [app]
|
||||||
|
"app.name" => "PageTop Application",
|
||||||
|
"app.description" => "Developed with the amazing PageTop framework.",
|
||||||
|
"app.theme" => "Bootsier",
|
||||||
|
"app.language" => "en-US",
|
||||||
|
"app.direction" => "ltr",
|
||||||
|
"app.startup_banner" => "Slant",
|
||||||
|
|
||||||
|
// [database]
|
||||||
|
"database.db_type" => "",
|
||||||
|
"database.db_name" => "",
|
||||||
|
"database.db_user" => "",
|
||||||
|
"database.db_pass" => "",
|
||||||
|
"database.db_host" => "localhost",
|
||||||
|
"database.db_port" => 0,
|
||||||
|
"database.max_pool_size" => 5,
|
||||||
|
|
||||||
|
// [dev]
|
||||||
|
"dev.static_files" => "",
|
||||||
|
|
||||||
|
// [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,
|
||||||
|
);
|
||||||
|
|
|
||||||
|
|
@ -110,7 +110,7 @@ pub fn run_migrations() {
|
||||||
migrations
|
migrations
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Migrator::up(&DBCONN, None)
|
Migrator::up(&app::db::DBCONN, None)
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
@ -125,7 +125,7 @@ pub fn run_migrations() {
|
||||||
migrations
|
migrations
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Migrator::down(&DBCONN, None)
|
Migrator::down(&app::db::DBCONN, None)
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{app, concat_string, global};
|
use crate::{app, concat_string, config};
|
||||||
use crate::base::component::{Container, Html};
|
use crate::base::component::{Container, Html};
|
||||||
use crate::core::component::ComponentTrait;
|
use crate::core::component::ComponentTrait;
|
||||||
use crate::html::{html, Favicon, Markup};
|
use crate::html::{html, Favicon, Markup};
|
||||||
|
|
@ -41,9 +41,9 @@ pub trait ThemeTrait: BaseTheme + Send + Sync {
|
||||||
|
|
||||||
@match page.title().get() {
|
@match page.title().get() {
|
||||||
Some(t) => title {
|
Some(t) => title {
|
||||||
(concat_string!(global::SETTINGS.app.name, " | ", t))
|
(concat_string!(config::SETTINGS.app.name, " | ", t))
|
||||||
},
|
},
|
||||||
None => title { (global::SETTINGS.app.name) }
|
None => title { (config::SETTINGS.app.name) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@if let Some(d) = page.description().get() {
|
@if let Some(d) = page.description().get() {
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,7 @@
|
||||||
use crate::{global, run_now, trace, LazyStatic};
|
|
||||||
|
|
||||||
pub use url::Url as DbUri;
|
pub use url::Url as DbUri;
|
||||||
|
|
||||||
pub use sea_orm::{DatabaseConnection as DbConn, ExecResult, QueryResult};
|
pub use sea_orm::{DatabaseConnection as DbConn, ExecResult, QueryResult};
|
||||||
|
|
||||||
use sea_orm::{ConnectOptions, ConnectionTrait, Database, DatabaseBackend, Statement};
|
|
||||||
use tracing_unwrap::ResultExt;
|
|
||||||
|
|
||||||
|
|
||||||
// El siguiente módulo migration es una versión simplificada del módulo sea_orm_migration (v0.9.1)
|
// El siguiente módulo migration es una versión simplificada del módulo sea_orm_migration (v0.9.1)
|
||||||
// https://github.com/SeaQL/sea-orm/tree/0.9.1/sea-orm-migration para evitar los errores generados
|
// https://github.com/SeaQL/sea-orm/tree/0.9.1/sea-orm-migration para evitar los errores generados
|
||||||
|
|
@ -42,97 +37,3 @@ macro_rules! migration_item {
|
||||||
Box::new(migration::$migration_module::Migration)
|
Box::new(migration::$migration_module::Migration)
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub static DBCONN: LazyStatic<DbConn> = LazyStatic::new(|| {
|
|
||||||
trace::info!(
|
|
||||||
"Connecting to database \"{}\" using a pool of {} connections",
|
|
||||||
&global::SETTINGS.database.db_name,
|
|
||||||
&global::SETTINGS.database.max_pool_size
|
|
||||||
);
|
|
||||||
|
|
||||||
let db_uri = match global::SETTINGS.database.db_type.as_str() {
|
|
||||||
"mysql" | "postgres" => {
|
|
||||||
let mut tmp_uri = DbUri::parse(
|
|
||||||
format!(
|
|
||||||
"{}://{}/{}",
|
|
||||||
&global::SETTINGS.database.db_type,
|
|
||||||
&global::SETTINGS.database.db_host,
|
|
||||||
&global::SETTINGS.database.db_name
|
|
||||||
)
|
|
||||||
.as_str(),
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
tmp_uri
|
|
||||||
.set_username(global::SETTINGS.database.db_user.as_str())
|
|
||||||
.unwrap();
|
|
||||||
// https://github.com/launchbadge/sqlx/issues/1624
|
|
||||||
tmp_uri
|
|
||||||
.set_password(Some(global::SETTINGS.database.db_pass.as_str()))
|
|
||||||
.unwrap();
|
|
||||||
if global::SETTINGS.database.db_port != 0 {
|
|
||||||
tmp_uri.set_port(Some(global::SETTINGS.database.db_port)).unwrap();
|
|
||||||
}
|
|
||||||
tmp_uri
|
|
||||||
}
|
|
||||||
"sqlite" => DbUri::parse(
|
|
||||||
format!(
|
|
||||||
"{}://{}",
|
|
||||||
&global::SETTINGS.database.db_type, &global::SETTINGS.database.db_name
|
|
||||||
)
|
|
||||||
.as_str(),
|
|
||||||
)
|
|
||||||
.unwrap(),
|
|
||||||
_ => {
|
|
||||||
trace::error!(
|
|
||||||
"Unrecognized database type \"{}\"",
|
|
||||||
&global::SETTINGS.database.db_type
|
|
||||||
);
|
|
||||||
DbUri::parse("").unwrap()
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
run_now(Database::connect::<ConnectOptions>({
|
|
||||||
let mut db_opt = ConnectOptions::new(db_uri.to_string());
|
|
||||||
db_opt.max_connections(global::SETTINGS.database.max_pool_size);
|
|
||||||
db_opt
|
|
||||||
}))
|
|
||||||
.expect_or_log("Failed to connect to database")
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
static DBBACKEND: LazyStatic<DatabaseBackend> = LazyStatic::new(||
|
|
||||||
DBCONN.get_database_backend()
|
|
||||||
);
|
|
||||||
|
|
||||||
pub async fn query<Q: QueryStatementWriter>(stmt: &mut Q) -> Result<Vec<QueryResult>, DbErr> {
|
|
||||||
DBCONN
|
|
||||||
.query_all(Statement::from_string(
|
|
||||||
*DBBACKEND,
|
|
||||||
match *DBBACKEND {
|
|
||||||
DatabaseBackend::MySql => stmt.to_string(MysqlQueryBuilder),
|
|
||||||
DatabaseBackend::Postgres => stmt.to_string(PostgresQueryBuilder),
|
|
||||||
DatabaseBackend::Sqlite => stmt.to_string(SqliteQueryBuilder),
|
|
||||||
},
|
|
||||||
))
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn exec<Q: QueryStatementWriter>(stmt: &mut Q) -> Result<Option<QueryResult>, DbErr> {
|
|
||||||
DBCONN
|
|
||||||
.query_one(Statement::from_string(
|
|
||||||
*DBBACKEND,
|
|
||||||
match *DBBACKEND {
|
|
||||||
DatabaseBackend::MySql => stmt.to_string(MysqlQueryBuilder),
|
|
||||||
DatabaseBackend::Postgres => stmt.to_string(PostgresQueryBuilder),
|
|
||||||
DatabaseBackend::Sqlite => stmt.to_string(SqliteQueryBuilder),
|
|
||||||
},
|
|
||||||
))
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn exec_raw(stmt: String) -> Result<ExecResult, DbErr> {
|
|
||||||
DBCONN
|
|
||||||
.execute(Statement::from_string(*DBBACKEND, stmt))
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,214 +0,0 @@
|
||||||
use crate::{pub_config, trace, LazyStatic};
|
|
||||||
|
|
||||||
use serde::Deserialize;
|
|
||||||
|
|
||||||
use tracing_appender::non_blocking::WorkerGuard;
|
|
||||||
use tracing_subscriber::EnvFilter;
|
|
||||||
|
|
||||||
use unic_langid::LanguageIdentifier;
|
|
||||||
|
|
||||||
// CONFIGURACIÓN ***********************************************************************************
|
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
|
||||||
/// Ajustes globales para las secciones reservadas [`[app]`](App), [`[database]`](Database),
|
|
||||||
/// [`[dev]`](Dev), [`[log]`](Log) y [`[server]`](Server) (ver [`SETTINGS`]).
|
|
||||||
pub struct Settings {
|
|
||||||
pub app: App,
|
|
||||||
pub database: Database,
|
|
||||||
pub dev: Dev,
|
|
||||||
pub log: Log,
|
|
||||||
pub server: Server,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
|
||||||
/// Sección `[app]` de los ajustes globales.
|
|
||||||
///
|
|
||||||
/// Ver [`Settings`].
|
|
||||||
pub struct App {
|
|
||||||
/// Valor predefinido: *"PageTop Application"*
|
|
||||||
pub name: String,
|
|
||||||
/// Valor predefinido: *"Developed with the amazing PageTop framework."*
|
|
||||||
pub description: String,
|
|
||||||
/// Valor predefinido: *"Bootsier"*
|
|
||||||
pub theme: String,
|
|
||||||
/// Valor predefinido: *"en-US"*
|
|
||||||
pub language: String,
|
|
||||||
/// Valor predefinido: *"ltr"*
|
|
||||||
pub direction: String,
|
|
||||||
/// Valor predefinido: *"Slant"*
|
|
||||||
pub startup_banner: String,
|
|
||||||
/// Valor predefinido: según variable de entorno PAGETOP_RUN_MODE, o *"default"* si no lo está
|
|
||||||
pub run_mode: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
|
||||||
/// Sección `[database]` de los ajustes globales.
|
|
||||||
///
|
|
||||||
/// Ver [`Settings`].
|
|
||||||
pub struct Database {
|
|
||||||
/// Valor predefinido: *""*
|
|
||||||
pub db_type: String,
|
|
||||||
/// Valor predefinido: *""*
|
|
||||||
pub db_name: String,
|
|
||||||
/// Valor predefinido: *""*
|
|
||||||
pub db_user: String,
|
|
||||||
/// Valor predefinido: *""*
|
|
||||||
pub db_pass: String,
|
|
||||||
/// Valor predefinido: *"localhost"*
|
|
||||||
pub db_host: String,
|
|
||||||
/// Valor predefinido: *0*
|
|
||||||
pub db_port: u16,
|
|
||||||
/// Valor predefinido: *5*
|
|
||||||
pub max_pool_size: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
|
||||||
/// Sección `[dev]` de los ajustes globales.
|
|
||||||
///
|
|
||||||
/// Ver [`Settings`].
|
|
||||||
pub struct Dev {
|
|
||||||
/// Valor predefinido: *""*
|
|
||||||
pub static_files: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
|
||||||
/// Sección `[log]` de los ajustes globales.
|
|
||||||
///
|
|
||||||
/// Ver [`Settings`].
|
|
||||||
pub struct Log {
|
|
||||||
/// Valor predefinido: *"Info"*
|
|
||||||
pub tracing: String,
|
|
||||||
/// Valor predefinido: *"Stdout"*
|
|
||||||
pub rolling: String,
|
|
||||||
/// Valor predefinido: *"log"*
|
|
||||||
pub path: String,
|
|
||||||
/// Valor predefinido: *"tracing.log"*
|
|
||||||
pub prefix: String,
|
|
||||||
/// Valor predefinido: *"Full"*
|
|
||||||
pub format: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
|
||||||
/// Sección `[server]` de los ajustes globales.
|
|
||||||
///
|
|
||||||
/// Ver [`Settings`].
|
|
||||||
pub struct Server {
|
|
||||||
/// Valor predefinido: *"localhost"*
|
|
||||||
pub bind_address: String,
|
|
||||||
/// Valor predefinido: *8088*
|
|
||||||
pub bind_port: u16,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub_config!(SETTINGS: Settings,
|
|
||||||
// [app]
|
|
||||||
"app.name" => "PageTop Application",
|
|
||||||
"app.description" => "Developed with the amazing PageTop framework.",
|
|
||||||
"app.theme" => "Bootsier",
|
|
||||||
"app.language" => "en-US",
|
|
||||||
"app.direction" => "ltr",
|
|
||||||
"app.startup_banner" => "Slant",
|
|
||||||
|
|
||||||
// [database]
|
|
||||||
"database.db_type" => "",
|
|
||||||
"database.db_name" => "",
|
|
||||||
"database.db_user" => "",
|
|
||||||
"database.db_pass" => "",
|
|
||||||
"database.db_host" => "localhost",
|
|
||||||
"database.db_port" => 0,
|
|
||||||
"database.max_pool_size" => 5,
|
|
||||||
|
|
||||||
// [dev]
|
|
||||||
"dev.static_files" => "",
|
|
||||||
|
|
||||||
// [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,
|
|
||||||
);
|
|
||||||
|
|
||||||
// REGISTRO DE TRAZAS Y EVENTOS ********************************************************************
|
|
||||||
|
|
||||||
/// Registro de trazas y eventos de la aplicación.
|
|
||||||
///
|
|
||||||
/// Para aumentar el rendimiento, un subproceso dedicado utiliza un sistema de escritura sin bloqueo
|
|
||||||
/// (*non-blocking writer*) que actúa periódicamente en vez de enviar cada traza o evento al
|
|
||||||
/// instante. Si el programa termina abruptamente (por ejemplo, por un panic! o un
|
|
||||||
/// std::process::exit), es posible que algunas trazas o eventos no se envíen.
|
|
||||||
///
|
|
||||||
/// Puesto que las trazas o eventos registrados poco antes de la caída de una aplicación suelen ser
|
|
||||||
/// importantes para diagnosticar la causa del fallo, con `Lazy<WorkerGuard>` se garantiza que todos
|
|
||||||
/// los registros almacenados se enviarán antes de terminar la ejecución.
|
|
||||||
|
|
||||||
#[rustfmt::skip]
|
|
||||||
pub(crate) static TRACING: LazyStatic<WorkerGuard> = LazyStatic::new(|| {
|
|
||||||
let env_filter =
|
|
||||||
EnvFilter::try_new(&SETTINGS.log.tracing).unwrap_or_else(|_| EnvFilter::new("Info"));
|
|
||||||
|
|
||||||
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 = &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),
|
|
||||||
"minutely" => tracing_appender::rolling::minutely(path, prefix),
|
|
||||||
"endless" => tracing_appender::rolling::never(path, prefix),
|
|
||||||
_ => {
|
|
||||||
println!(
|
|
||||||
"Rolling value \"{}\" not valid. Using \"daily\". Check the settings file.",
|
|
||||||
SETTINGS.log.rolling,
|
|
||||||
);
|
|
||||||
tracing_appender::rolling::daily(path, prefix)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
let subscriber = tracing_subscriber::fmt()
|
|
||||||
.with_env_filter(env_filter)
|
|
||||||
.with_writer(non_blocking)
|
|
||||||
.with_ansi(rolling.as_str() == "stdout");
|
|
||||||
match SETTINGS.log.format.to_lowercase().as_str() {
|
|
||||||
"json" => subscriber.json().init(),
|
|
||||||
"full" => subscriber.init(),
|
|
||||||
"compact" => subscriber.compact().init(),
|
|
||||||
"pretty" => subscriber.pretty().init(),
|
|
||||||
_ => {
|
|
||||||
println!(
|
|
||||||
"Tracing format \"{}\" not valid. Using \"Full\". Check the settings file.",
|
|
||||||
SETTINGS.log.format,
|
|
||||||
);
|
|
||||||
subscriber.init();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
guard
|
|
||||||
});
|
|
||||||
|
|
||||||
// LOCALIZACIÓN ************************************************************************************
|
|
||||||
|
|
||||||
/// Almacena el Identificador de Idioma Unicode
|
|
||||||
/// ([Unicode Language Identifier](https://unicode.org/reports/tr35/tr35.html#Unicode_language_identifier))
|
|
||||||
/// de la aplicación, obtenido de `SETTINGS.app.language`.
|
|
||||||
pub static LANGID: LazyStatic<LanguageIdentifier> =
|
|
||||||
LazyStatic::new(|| match SETTINGS.app.language.parse() {
|
|
||||||
Ok(language) => language,
|
|
||||||
Err(_) => {
|
|
||||||
trace::warn!(
|
|
||||||
"{}, {} \"{}\"! {}, {}",
|
|
||||||
"Failed to parse language",
|
|
||||||
"unrecognized Unicode Language Identifier",
|
|
||||||
SETTINGS.app.language,
|
|
||||||
"Using \"en-US\"",
|
|
||||||
"check the settings file",
|
|
||||||
);
|
|
||||||
"en-US".parse().unwrap()
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
@ -62,9 +62,6 @@ pub mod html;
|
||||||
#[cfg(feature = "database")]
|
#[cfg(feature = "database")]
|
||||||
pub mod db;
|
pub mod db;
|
||||||
|
|
||||||
// Acceso a declaraciones globales.
|
|
||||||
pub mod global;
|
|
||||||
|
|
||||||
// Prepara y ejecuta la aplicación.
|
// Prepara y ejecuta la aplicación.
|
||||||
pub mod app;
|
pub mod app;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -102,7 +102,7 @@ pub use fluent_templates::{static_loader as static_locale, Loader as Locale};
|
||||||
/// Permite integrar fácilmente localización en temas, módulos y componentes.
|
/// Permite integrar fácilmente localización en temas, módulos y componentes.
|
||||||
macro_rules! pub_locale {
|
macro_rules! pub_locale {
|
||||||
( $dir_locales:literal $(, $core_locales:literal)? ) => {
|
( $dir_locales:literal $(, $core_locales:literal)? ) => {
|
||||||
use $crate::global;
|
use $crate::app;
|
||||||
use $crate::locale::*;
|
use $crate::locale::*;
|
||||||
|
|
||||||
static_locale! {
|
static_locale! {
|
||||||
|
|
@ -118,7 +118,7 @@ macro_rules! pub_locale {
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
fn l(key: &str) -> String {
|
fn l(key: &str) -> String {
|
||||||
LOCALES.lookup(&global::LANGID, key).unwrap_or(key.to_string())
|
LOCALES.lookup(&app::locale::LANGID, key).unwrap_or(key.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
|
|
@ -126,7 +126,7 @@ macro_rules! pub_locale {
|
||||||
key: &str,
|
key: &str,
|
||||||
args: &std::collections::HashMap<String, FluentValue>
|
args: &std::collections::HashMap<String, FluentValue>
|
||||||
) -> String {
|
) -> String {
|
||||||
LOCALES.lookup_with_args(&global::LANGID, key, args).unwrap_or(key.to_string())
|
LOCALES.lookup_with_args(&app::locale::LANGID, key, args).unwrap_or(key.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
|
|
@ -135,7 +135,7 @@ macro_rules! pub_locale {
|
||||||
args: &std::collections::HashMap<String, FluentValue>
|
args: &std::collections::HashMap<String, FluentValue>
|
||||||
) -> $crate::html::PreEscaped<String> {
|
) -> $crate::html::PreEscaped<String> {
|
||||||
$crate::html::PreEscaped(
|
$crate::html::PreEscaped(
|
||||||
LOCALES.lookup_with_args(&global::LANGID, key, args).unwrap_or(key.to_string())
|
LOCALES.lookup_with_args(&app::locale::LANGID, key, args).unwrap_or(key.to_string())
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,6 @@ pub use crate::html::*;
|
||||||
#[cfg(feature = "database")]
|
#[cfg(feature = "database")]
|
||||||
pub use crate::{db, db::*, migration_item, pub_migration};
|
pub use crate::{db, db::*, migration_item, pub_migration};
|
||||||
|
|
||||||
pub use crate::global;
|
|
||||||
|
|
||||||
pub use crate::app;
|
pub use crate::app;
|
||||||
pub use crate::app::application::Application;
|
pub use crate::app::application::Application;
|
||||||
pub use crate::app::fatal_error::FatalError;
|
pub use crate::app::fatal_error::FatalError;
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,10 @@ use super::PageOp;
|
||||||
|
|
||||||
use crate::core::theme::{all::theme_by_single_name, ThemeStaticRef};
|
use crate::core::theme::{all::theme_by_single_name, ThemeStaticRef};
|
||||||
use crate::html::{html, Assets, Favicon, IdentifierValue, JavaScript, Markup, ModeJS, StyleSheet};
|
use crate::html::{html, Assets, Favicon, IdentifierValue, JavaScript, Markup, ModeJS, StyleSheet};
|
||||||
use crate::{base, concat_string, global, util, LazyStatic};
|
use crate::{base, concat_string, config, util, LazyStatic};
|
||||||
|
|
||||||
static DEFAULT_THEME: LazyStatic<ThemeStaticRef> =
|
static DEFAULT_THEME: LazyStatic<ThemeStaticRef> =
|
||||||
LazyStatic::new(|| match theme_by_single_name(&global::SETTINGS.app.theme) {
|
LazyStatic::new(|| match theme_by_single_name(&config::SETTINGS.app.theme) {
|
||||||
Some(theme) => theme,
|
Some(theme) => theme,
|
||||||
None => &base::theme::bootsier::Bootsier,
|
None => &base::theme::bootsier::Bootsier,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,12 @@ use crate::app::fatal_error::FatalError;
|
||||||
use crate::core::component::*;
|
use crate::core::component::*;
|
||||||
use crate::core::hook::{action_ref, run_actions};
|
use crate::core::hook::{action_ref, run_actions};
|
||||||
use crate::html::{html, AttributeValue, Classes, ClassesOp, Markup, DOCTYPE};
|
use crate::html::{html, AttributeValue, Classes, ClassesOp, Markup, DOCTYPE};
|
||||||
use crate::{global, trace, LazyStatic};
|
use crate::{config, trace, LazyStatic};
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
static DEFAULT_LANGUAGE: LazyStatic<Option<String>> = LazyStatic::new(|| {
|
static DEFAULT_LANGUAGE: LazyStatic<Option<String>> = LazyStatic::new(|| {
|
||||||
let language = global::SETTINGS.app.language[..2].to_lowercase();
|
let language = config::SETTINGS.app.language[..2].to_lowercase();
|
||||||
if !language.is_empty() {
|
if !language.is_empty() {
|
||||||
Some(language)
|
Some(language)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -18,7 +18,7 @@ static DEFAULT_LANGUAGE: LazyStatic<Option<String>> = LazyStatic::new(|| {
|
||||||
});
|
});
|
||||||
|
|
||||||
static DEFAULT_DIRECTION: LazyStatic<Option<String>> = LazyStatic::new(|| {
|
static DEFAULT_DIRECTION: LazyStatic<Option<String>> = LazyStatic::new(|| {
|
||||||
let direction = global::SETTINGS.app.direction.to_lowercase();
|
let direction = config::SETTINGS.app.direction.to_lowercase();
|
||||||
match direction.as_str() {
|
match direction.as_str() {
|
||||||
"auto" => Some("auto".to_owned()),
|
"auto" => Some("auto".to_owned()),
|
||||||
"ltr" => Some("ltr".to_owned()),
|
"ltr" => Some("ltr".to_owned()),
|
||||||
|
|
@ -27,7 +27,7 @@ static DEFAULT_DIRECTION: LazyStatic<Option<String>> = LazyStatic::new(|| {
|
||||||
_ => {
|
_ => {
|
||||||
trace::warn!(
|
trace::warn!(
|
||||||
"Text direction \"{}\" not valid, {}",
|
"Text direction \"{}\" not valid, {}",
|
||||||
global::SETTINGS.app.direction,
|
config::SETTINGS.app.direction,
|
||||||
"check the settings file"
|
"check the settings file"
|
||||||
);
|
);
|
||||||
None
|
None
|
||||||
|
|
|
||||||
|
|
@ -169,7 +169,7 @@ macro_rules! args {
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! configure_service_for_static_files {
|
macro_rules! configure_service_for_static_files {
|
||||||
( $cfg:ident, $dir:expr, $embed:ident ) => {{
|
( $cfg:ident, $dir:expr, $embed:ident ) => {{
|
||||||
let static_files = &$crate::global::SETTINGS.dev.static_files;
|
let static_files = &$crate::config::SETTINGS.dev.static_files;
|
||||||
if static_files.is_empty() {
|
if static_files.is_empty() {
|
||||||
$cfg.service($crate::app::ResourceFiles::new($dir, $embed()));
|
$cfg.service($crate::app::ResourceFiles::new($dir, $embed()));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue