Actualiza la presentación del rótulo de arranque
This commit is contained in:
parent
e3f592b3b0
commit
d72e1ccad5
18 changed files with 164 additions and 142 deletions
|
|
@ -8,20 +8,20 @@ edition = "2021"
|
||||||
|
|
||||||
[dependencies.pagetop]
|
[dependencies.pagetop]
|
||||||
path = "../pagetop"
|
path = "../pagetop"
|
||||||
# PageTop por defecto no requiere base de datos. Hay que habilitarla:
|
# Si se usa base de datos:
|
||||||
features = ["mysql"]
|
features = ["mysql"]
|
||||||
# features = ["postgres"]
|
# features = ["postgres"]
|
||||||
# features = ["sqlite"]
|
# features = ["sqlite"]
|
||||||
# PageTop puede dar soporte a todas las bases de datos:
|
# Soporte alternativo a todas las bases de datos:
|
||||||
# features = ["mysql", "postgres", "sqlite"]
|
# features = ["mysql", "postgres", "sqlite"]
|
||||||
# En estos casos hay que deshabilitar las características predeterminadas:
|
# En estos casos hay que deshabilitar las características predeterminadas:
|
||||||
default-features = false
|
default-features = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-web = "3.3.3"
|
actix-web = "3.3.3"
|
||||||
# Opcional. Sólo si se usa la macro html!:
|
# Si se usa la macro html!:
|
||||||
maud = { version = "0.23.0" }
|
maud = { version = "0.23.0" }
|
||||||
# Opcional. Sólo si se usa base de datos:
|
# Si se usa base de datos:
|
||||||
sea-orm = { version = "0.6.0" }
|
sea-orm = { version = "0.6.0" }
|
||||||
# Opcional. Para la serialización de estructuras de datos:
|
# Si se requiere serialización de estructuras de datos:
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,9 @@ edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
pagetop = { path = "../pagetop" }
|
pagetop = { path = "../pagetop" }
|
||||||
# Opcional. Sólo si se usa la macro html!:
|
# Si se usa la macro html!:
|
||||||
maud = { version = "0.23.0" }
|
maud = { version = "0.23.0" }
|
||||||
# Opcional. Sólo si se usa base de datos:
|
# Si se usa base de datos:
|
||||||
sea-orm = { version = "0.6.0" }
|
sea-orm = { version = "0.6.0" }
|
||||||
# Opcional. Para la serialización de estructuras de datos:
|
# Si se requiere serialización de estructuras de datos:
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ language = "en-US"
|
||||||
# Dirección predeterminada para el texto: "ltr", "rtl" o "auto".
|
# Dirección predeterminada para el texto: "ltr", "rtl" o "auto".
|
||||||
direction = "ltr"
|
direction = "ltr"
|
||||||
# Rótulo al inicio: "Off", "Slant", "Small", "Speed" o "Starwars".
|
# Rótulo al inicio: "Off", "Slant", "Small", "Speed" o "Starwars".
|
||||||
startup_banner = "Small"
|
startup_banner = "Slant"
|
||||||
|
|
||||||
[log]
|
[log]
|
||||||
# Traza de ejecución: "Error", "Warn", "Info", "Debug" o "Trace".
|
# Traza de ejecución: "Error", "Warn", "Info", "Debug" o "Trace".
|
||||||
|
|
@ -25,7 +25,7 @@ format = "Full"
|
||||||
|
|
||||||
[database]
|
[database]
|
||||||
# Conecta con una base de datos (opcional).
|
# Conecta con una base de datos (opcional).
|
||||||
# Tipo de la base de datos (mysql, postgres ó sqlite).
|
# Tipo de base de datos (mysql, postgres ó sqlite).
|
||||||
db_type = ""
|
db_type = ""
|
||||||
# Nombre (para mysql/postgres) o referencia (para sqlite) de la base de datos.
|
# Nombre (para mysql/postgres) o referencia (para sqlite) de la base de datos.
|
||||||
db_name = ""
|
db_name = ""
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
use crate::{Lazy, app, base, global, trace};
|
use crate::{Lazy, app, base, module, theme, trace};
|
||||||
use crate::config::SETTINGS;
|
use crate::config::SETTINGS;
|
||||||
use crate::module::register_module;
|
|
||||||
|
|
||||||
use std::io::Error;
|
use std::io::Error;
|
||||||
use actix_web::middleware::normalize::{NormalizePath, TrailingSlash};
|
use actix_web::middleware::normalize::{NormalizePath, TrailingSlash};
|
||||||
|
|
@ -15,31 +14,8 @@ pub fn essence() {
|
||||||
|
|
||||||
impl Application {
|
impl Application {
|
||||||
pub async fn prepare(bootstrap: fn()) -> Result<Self, Error> {
|
pub async fn prepare(bootstrap: fn()) -> Result<Self, Error> {
|
||||||
// Imprime un rótulo de presentación (opcional).
|
// Rótulo de presentación.
|
||||||
if SETTINGS.app.startup_banner.to_lowercase() != "off" {
|
app::banner::print_on_startup();
|
||||||
let figfont = figlet_rs::FIGfont::from_content(
|
|
||||||
match SETTINGS.app.startup_banner.to_lowercase().as_str() {
|
|
||||||
"slant" => include_str!("figfonts/slant.flf"),
|
|
||||||
"small" => include_str!("figfonts/small.flf"),
|
|
||||||
"speed" => include_str!("figfonts/speed.flf"),
|
|
||||||
"starwars" => include_str!("figfonts/starwars.flf"),
|
|
||||||
_ => {
|
|
||||||
println!(
|
|
||||||
"FIGfont \"{}\" not found for banner. {}. {}.",
|
|
||||||
SETTINGS.app.startup_banner,
|
|
||||||
"Using \"Small\"",
|
|
||||||
"Check the settings file",
|
|
||||||
);
|
|
||||||
include_str!("figfonts/small.flf")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
).unwrap();
|
|
||||||
println!("\n{} {}\n\n Powered by PageTop {}\n",
|
|
||||||
figfont.convert(&SETTINGS.app.name).unwrap(),
|
|
||||||
&SETTINGS.app.description,
|
|
||||||
env!("CARGO_PKG_VERSION")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Inicia registro de trazas y eventos.
|
// Inicia registro de trazas y eventos.
|
||||||
Lazy::force(&app::tracing::TRACING);
|
Lazy::force(&app::tracing::TRACING);
|
||||||
|
|
@ -57,19 +33,19 @@ impl Application {
|
||||||
|
|
||||||
// Registra el módulo para una página de presentación de PageTop.
|
// Registra el módulo para una página de presentación de PageTop.
|
||||||
// Normalmente se sobrecargará en la función de inicio.
|
// Normalmente se sobrecargará en la función de inicio.
|
||||||
register_module(&base::module::homepage::HomepageModule);
|
module::register_module(&base::module::homepage::HomepageModule);
|
||||||
|
|
||||||
// Comprueba actualizaciones pendientes de la base de datos (opcional).
|
// Actualizaciones pendientes de la base de datos (opcional).
|
||||||
#[cfg(any(feature = "mysql", feature = "postgres", feature = "sqlite"))]
|
#[cfg(any(feature = "mysql", feature = "postgres", feature = "sqlite"))]
|
||||||
global::run_migrations();
|
module::all::migrations();
|
||||||
|
|
||||||
// Prepara el servidor web.
|
// Prepara el servidor web.
|
||||||
let server = app::HttpServer::new(move || {
|
let server = app::HttpServer::new(move || {
|
||||||
app::App::new()
|
app::App::new()
|
||||||
.wrap(tracing_actix_web::TracingLogger)
|
.wrap(tracing_actix_web::TracingLogger)
|
||||||
.wrap(NormalizePath::new(TrailingSlash::Trim))
|
.wrap(NormalizePath::new(TrailingSlash::Trim))
|
||||||
.configure(&global::themes)
|
.configure(&module::all::modules)
|
||||||
.configure(&global::modules)
|
.configure(&theme::all::themes)
|
||||||
})
|
})
|
||||||
.bind(format!("{}:{}",
|
.bind(format!("{}:{}",
|
||||||
&SETTINGS.webserver.bind_address,
|
&SETTINGS.webserver.bind_address,
|
||||||
|
|
|
||||||
40
pagetop/src/app/banner/mod.rs
Normal file
40
pagetop/src/app/banner/mod.rs
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
use crate::Lazy;
|
||||||
|
use crate::config::SETTINGS;
|
||||||
|
|
||||||
|
use figlet_rs::FIGfont;
|
||||||
|
|
||||||
|
static FIGFONT: Lazy<FIGfont> = Lazy::new(|| {
|
||||||
|
let slant = include_str!("slant.flf");
|
||||||
|
let small = include_str!("small.flf");
|
||||||
|
let speed = include_str!("speed.flf");
|
||||||
|
let starwars = include_str!("starwars.flf");
|
||||||
|
|
||||||
|
FIGfont::from_content(
|
||||||
|
match SETTINGS.app.startup_banner.to_lowercase().as_str() {
|
||||||
|
"off" => slant,
|
||||||
|
"slant" => slant,
|
||||||
|
"small" => small,
|
||||||
|
"speed" => speed,
|
||||||
|
"starwars" => starwars,
|
||||||
|
_ => {
|
||||||
|
println!(
|
||||||
|
"\n FIGfont \"{}\" not found for banner. {}. {}.",
|
||||||
|
SETTINGS.app.startup_banner,
|
||||||
|
"Using \"Slant\"",
|
||||||
|
"Check the settings file",
|
||||||
|
);
|
||||||
|
slant
|
||||||
|
}
|
||||||
|
}
|
||||||
|
).unwrap()
|
||||||
|
});
|
||||||
|
|
||||||
|
pub fn print_on_startup() {
|
||||||
|
if SETTINGS.app.startup_banner.to_lowercase() != "off" {
|
||||||
|
println!("\n{} {}\n\n Powered by PageTop {}\n",
|
||||||
|
FIGFONT.convert(&SETTINGS.app.name).unwrap(),
|
||||||
|
&SETTINGS.app.description,
|
||||||
|
env!("CARGO_PKG_VERSION")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -3,6 +3,8 @@ pub use actix_web::{
|
||||||
};
|
};
|
||||||
use actix_web::dev::Server;
|
use actix_web::dev::Server;
|
||||||
|
|
||||||
|
mod banner;
|
||||||
|
|
||||||
mod tracing;
|
mod tracing;
|
||||||
|
|
||||||
pub mod locale;
|
pub mod locale;
|
||||||
|
|
|
||||||
|
|
@ -130,7 +130,7 @@ Ajustes globales y valores predeterminados para las secciones *\[app\]*,
|
||||||
"app.theme" => "Bootsier",
|
"app.theme" => "Bootsier",
|
||||||
"app.language" => "en-US",
|
"app.language" => "en-US",
|
||||||
"app.direction" => "ltr",
|
"app.direction" => "ltr",
|
||||||
"app.startup_banner" => "Small",
|
"app.startup_banner" => "Slant",
|
||||||
|
|
||||||
// [log]
|
// [log]
|
||||||
"log.tracing" => "Info",
|
"log.tracing" => "Info",
|
||||||
|
|
|
||||||
|
|
@ -1,93 +0,0 @@
|
||||||
use crate::{Lazy, app, base, run_now, theme_static_files, trace};
|
|
||||||
use crate::config::SETTINGS;
|
|
||||||
use crate::db::migration::*;
|
|
||||||
use crate::module::*;
|
|
||||||
use crate::theme::*;
|
|
||||||
|
|
||||||
use std::sync::RwLock;
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
// Módulos registrados.
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
pub static MODULES: Lazy<RwLock<Vec<&dyn ModuleTrait>>> = Lazy::new(
|
|
||||||
|| { RwLock::new(Vec::new()) }
|
|
||||||
);
|
|
||||||
|
|
||||||
pub fn register_module(m: &'static dyn ModuleTrait) {
|
|
||||||
let mut modules = MODULES.write().unwrap();
|
|
||||||
match modules.iter().find(|t| t.name() == m.name()) {
|
|
||||||
None => {
|
|
||||||
trace::info!("{}", m.name());
|
|
||||||
modules.push(m);
|
|
||||||
},
|
|
||||||
Some(_) => {},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn modules(cfg: &mut app::web::ServiceConfig) {
|
|
||||||
for m in MODULES.read().unwrap().iter() {
|
|
||||||
m.configure_module(cfg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(any(feature = "mysql", feature = "postgres", feature = "sqlite"))]
|
|
||||||
pub fn run_migrations() {
|
|
||||||
run_now({
|
|
||||||
struct Migrator;
|
|
||||||
impl MigratorTrait for Migrator {
|
|
||||||
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
|
|
||||||
let mut migrations = vec![];
|
|
||||||
for m in MODULES.read().unwrap().iter() {
|
|
||||||
migrations.append(&mut m.migrations());
|
|
||||||
}
|
|
||||||
migrations
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Migrator::up(&app::db::DBCONN, None)
|
|
||||||
}).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
// Temas registrados y tema predeterminado.
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
include!(concat!(env!("OUT_DIR"), "/theme.rs"));
|
|
||||||
|
|
||||||
pub static THEMES: Lazy<RwLock<Vec<&dyn ThemeTrait>>> = Lazy::new(|| {
|
|
||||||
RwLock::new(vec![
|
|
||||||
&base::theme::aliner::AlinerTheme,
|
|
||||||
&base::theme::minimal::MinimalTheme,
|
|
||||||
&base::theme::bootsier::BootsierTheme,
|
|
||||||
])
|
|
||||||
});
|
|
||||||
|
|
||||||
pub static DEFAULT_THEME: Lazy<&dyn ThemeTrait> = Lazy::new(|| {
|
|
||||||
for t in THEMES.read().unwrap().iter() {
|
|
||||||
if t.name().to_lowercase() == SETTINGS.app.theme.to_lowercase() {
|
|
||||||
return *t;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
&base::theme::bootsier::BootsierTheme
|
|
||||||
});
|
|
||||||
|
|
||||||
pub fn register_theme(t: &'static dyn ThemeTrait) {
|
|
||||||
THEMES.write().unwrap().push(t);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn theme_by_name(name: &str) -> Option<&'static dyn ThemeTrait> {
|
|
||||||
let themes = crate::global::THEMES.write().unwrap();
|
|
||||||
match themes.iter().find(|t| t.name() == name) {
|
|
||||||
Some(theme) => Some(*theme),
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn themes(cfg: &mut app::web::ServiceConfig) {
|
|
||||||
theme_static_files!(cfg, "/theme");
|
|
||||||
|
|
||||||
for t in THEMES.read().unwrap().iter() {
|
|
||||||
t.configure_theme(cfg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -8,8 +8,6 @@ pub use futures::executor::block_on as run_now;
|
||||||
// APIs públicas.
|
// APIs públicas.
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
mod global; // Ref. privadas globales a todos los temas y módulos.
|
|
||||||
|
|
||||||
pub mod config; // Gestión de la configuración.
|
pub mod config; // Gestión de la configuración.
|
||||||
pub mod trace; // Registro de trazas y eventos de la aplicación.
|
pub mod trace; // Registro de trazas y eventos de la aplicación.
|
||||||
pub mod locale; // Localización.
|
pub mod locale; // Localización.
|
||||||
|
|
|
||||||
44
pagetop/src/module/all.rs
Normal file
44
pagetop/src/module/all.rs
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
use crate::{Lazy, app, run_now, trace};
|
||||||
|
use crate::db::migration::*;
|
||||||
|
use super::ModuleTrait;
|
||||||
|
|
||||||
|
use std::sync::RwLock;
|
||||||
|
|
||||||
|
// Módulos registrados.
|
||||||
|
static MODULES: Lazy<RwLock<Vec<&dyn ModuleTrait>>> = Lazy::new(|| {
|
||||||
|
RwLock::new(Vec::new())
|
||||||
|
});
|
||||||
|
|
||||||
|
pub fn register_module(module: &'static dyn ModuleTrait) {
|
||||||
|
let mut modules = MODULES.write().unwrap();
|
||||||
|
match modules.iter().find(|m| m.name() == module.name()) {
|
||||||
|
None => {
|
||||||
|
trace::info!("{}", module.name());
|
||||||
|
modules.push(module);
|
||||||
|
},
|
||||||
|
Some(_) => {},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn modules(cfg: &mut app::web::ServiceConfig) {
|
||||||
|
for m in MODULES.read().unwrap().iter() {
|
||||||
|
m.configure_module(cfg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(any(feature = "mysql", feature = "postgres", feature = "sqlite"))]
|
||||||
|
pub fn migrations() {
|
||||||
|
run_now({
|
||||||
|
struct Migrator;
|
||||||
|
impl MigratorTrait for Migrator {
|
||||||
|
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
|
||||||
|
let mut migrations = vec![];
|
||||||
|
for m in MODULES.read().unwrap().iter() {
|
||||||
|
migrations.append(&mut m.migrations());
|
||||||
|
}
|
||||||
|
migrations
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Migrator::up(&app::db::DBCONN, None)
|
||||||
|
}).unwrap();
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
mod definition;
|
mod definition;
|
||||||
pub use definition::ModuleTrait;
|
pub use definition::ModuleTrait;
|
||||||
|
|
||||||
pub use crate::global::register_module;
|
pub(crate) mod all;
|
||||||
|
pub use all::register_module;
|
||||||
|
|
@ -1,7 +1,15 @@
|
||||||
use crate::global::DEFAULT_THEME;
|
use crate::{Lazy, base};
|
||||||
|
use crate::config::SETTINGS;
|
||||||
use crate::html::{Markup, PreEscaped, html};
|
use crate::html::{Markup, PreEscaped, html};
|
||||||
use crate::theme::*;
|
use crate::theme::*;
|
||||||
|
|
||||||
|
static DEFAULT_THEME: Lazy<&dyn ThemeTrait> = Lazy::new(|| {
|
||||||
|
match theme_by_name(&SETTINGS.app.theme) {
|
||||||
|
Some(theme) => theme,
|
||||||
|
None => &base::theme::bootsier::BootsierTheme,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Favicon.
|
// Favicon.
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
|
||||||
43
pagetop/src/theme/all.rs
Normal file
43
pagetop/src/theme/all.rs
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
use crate::{Lazy, app, base, theme_static_files, trace};
|
||||||
|
use super::ThemeTrait;
|
||||||
|
|
||||||
|
use std::sync::RwLock;
|
||||||
|
|
||||||
|
include!(concat!(env!("OUT_DIR"), "/theme.rs"));
|
||||||
|
|
||||||
|
// Temas registrados.
|
||||||
|
static THEMES: Lazy<RwLock<Vec<&dyn ThemeTrait>>> = Lazy::new(|| {
|
||||||
|
RwLock::new(vec![
|
||||||
|
&base::theme::aliner::AlinerTheme,
|
||||||
|
&base::theme::minimal::MinimalTheme,
|
||||||
|
&base::theme::bootsier::BootsierTheme,
|
||||||
|
])
|
||||||
|
});
|
||||||
|
|
||||||
|
pub fn register_theme(theme: &'static dyn ThemeTrait) {
|
||||||
|
let mut themes = THEMES.write().unwrap();
|
||||||
|
match themes.iter().find(|t| t.name() == theme.name()) {
|
||||||
|
None => {
|
||||||
|
trace::info!("{}", theme.name());
|
||||||
|
themes.push(theme);
|
||||||
|
},
|
||||||
|
Some(_) => {},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn theme_by_name(name: &str) -> Option<&'static dyn ThemeTrait> {
|
||||||
|
match THEMES.write().unwrap().iter().find(
|
||||||
|
|t| t.name().to_lowercase() == name.to_lowercase()
|
||||||
|
) {
|
||||||
|
Some(theme) => Some(*theme),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn themes(cfg: &mut app::web::ServiceConfig) {
|
||||||
|
theme_static_files!(cfg, "/theme");
|
||||||
|
|
||||||
|
for t in THEMES.read().unwrap().iter() {
|
||||||
|
t.configure_theme(cfg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
mod definition;
|
mod definition;
|
||||||
pub use definition::ThemeTrait;
|
pub use definition::ThemeTrait;
|
||||||
|
|
||||||
pub use crate::global::register_theme;
|
pub(crate) mod all;
|
||||||
pub use crate::global::theme_by_name;
|
pub use all::{
|
||||||
|
register_theme,
|
||||||
|
theme_by_name,
|
||||||
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue