Libera la versión de desarrollo 0.0.3
This commit is contained in:
parent
fbc6ab2adf
commit
3ee5859eae
32 changed files with 94 additions and 93 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "pagetop"
|
name = "pagetop"
|
||||||
version = "0.0.2"
|
version = "0.0.3"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
authors = [
|
authors = [
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
use crate::{Lazy, all, app, trace};
|
use crate::{Lazy, app, base, global, trace};
|
||||||
use crate::config::SETTINGS;
|
use crate::config::SETTINGS;
|
||||||
use crate::theme::*;
|
use crate::module::register_module;
|
||||||
use crate::module::*;
|
|
||||||
|
|
||||||
use std::io::Error;
|
use std::io::Error;
|
||||||
use actix_web::middleware::normalize::{NormalizePath, TrailingSlash};
|
use actix_web::middleware::normalize::{NormalizePath, TrailingSlash};
|
||||||
|
|
@ -52,30 +51,25 @@ impl Application {
|
||||||
#[cfg(any(feature = "mysql", feature = "postgres", feature = "sqlite"))]
|
#[cfg(any(feature = "mysql", feature = "postgres", feature = "sqlite"))]
|
||||||
Lazy::force(&app::db::DBCONN);
|
Lazy::force(&app::db::DBCONN);
|
||||||
|
|
||||||
// Registra los temas predefinidos.
|
|
||||||
register_theme(&aliner::AlinerTheme);
|
|
||||||
register_theme(&minimal::MinimalTheme);
|
|
||||||
register_theme(&bootsier::BootsierTheme);
|
|
||||||
|
|
||||||
// Ejecuta la función de inicio de la aplicación.
|
// Ejecuta la función de inicio de la aplicación.
|
||||||
trace::info!("Calling application bootstrap");
|
trace::info!("Calling application bootstrap");
|
||||||
let _ = &bootstrap();
|
let _ = &bootstrap();
|
||||||
|
|
||||||
// Registra el módulo para la página de inicio de PageTop.
|
// Registra el módulo para una página de presentación de PageTop.
|
||||||
// Al ser el último, puede sobrecargarse con la función de inicio.
|
// Normalmente se sobrecargará en la función de inicio.
|
||||||
register_module(&homepage::HomepageModule);
|
register_module(&base::module::homepage::HomepageModule);
|
||||||
|
|
||||||
// Comprueba actualizaciones pendientes de la base de datos (opcional).
|
// Comprueba actualizaciones pendientes de la base de datos (opcional).
|
||||||
#[cfg(any(feature = "mysql", feature = "postgres", feature = "sqlite"))]
|
#[cfg(any(feature = "mysql", feature = "postgres", feature = "sqlite"))]
|
||||||
all::run_migrations();
|
global::run_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(&all::themes)
|
.configure(&global::themes)
|
||||||
.configure(&all::modules)
|
.configure(&global::modules)
|
||||||
})
|
})
|
||||||
.bind(format!("{}:{}",
|
.bind(format!("{}:{}",
|
||||||
&SETTINGS.webserver.bind_address,
|
&SETTINGS.webserver.bind_address,
|
||||||
|
|
|
||||||
3
pagetop/src/base/mod.rs
Normal file
3
pagetop/src/base/mod.rs
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
pub mod component;
|
||||||
|
pub mod module;
|
||||||
|
pub mod theme;
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
localize!("src/module/homepage/locales");
|
localize!("src/base/module/homepage/locales");
|
||||||
|
|
||||||
pub struct HomepageModule;
|
pub struct HomepageModule;
|
||||||
|
|
||||||
1
pagetop/src/base/module/mod.rs
Normal file
1
pagetop/src/base/module/mod.rs
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
pub mod homepage;
|
||||||
|
|
@ -2,7 +2,7 @@ use crate::prelude::*;
|
||||||
|
|
||||||
include!(concat!(env!("OUT_DIR"), "/bootsier.rs"));
|
include!(concat!(env!("OUT_DIR"), "/bootsier.rs"));
|
||||||
|
|
||||||
localize!("src/theme/bootsier/locales");
|
localize!("src/base/theme/bootsier/locales");
|
||||||
|
|
||||||
pub struct BootsierTheme;
|
pub struct BootsierTheme;
|
||||||
|
|
||||||
3
pagetop/src/base/theme/mod.rs
Normal file
3
pagetop/src/base/theme/mod.rs
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
pub mod aliner;
|
||||||
|
pub mod bootsier;
|
||||||
|
pub mod minimal;
|
||||||
|
|
@ -1,31 +1,11 @@
|
||||||
use crate::{Lazy, run_now, app};
|
use crate::{Lazy, app, base, run_now, trace};
|
||||||
|
use crate::config::SETTINGS;
|
||||||
use crate::db::migration::*;
|
use crate::db::migration::*;
|
||||||
use crate::theme::ThemeTrait;
|
use crate::module::*;
|
||||||
use crate::module::ModuleTrait;
|
use crate::theme::*;
|
||||||
|
|
||||||
use std::sync::RwLock;
|
use std::sync::RwLock;
|
||||||
|
|
||||||
include!(concat!(env!("OUT_DIR"), "/theme.rs"));
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
// Temas registrados y tema predeterminado.
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
pub static THEMES: Lazy<RwLock<Vec<&dyn ThemeTrait>>> = Lazy::new(
|
|
||||||
|| { RwLock::new(Vec::new()) }
|
|
||||||
);
|
|
||||||
|
|
||||||
pub fn themes(cfg: &mut app::web::ServiceConfig) {
|
|
||||||
cfg.service(actix_web_static_files::ResourceFiles::new(
|
|
||||||
"/theme",
|
|
||||||
assets()
|
|
||||||
));
|
|
||||||
|
|
||||||
for t in THEMES.read().unwrap().iter() {
|
|
||||||
t.configure_theme(cfg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Módulos registrados.
|
// Módulos registrados.
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
@ -34,6 +14,17 @@ pub static MODULES: Lazy<RwLock<Vec<&dyn ModuleTrait>>> = Lazy::new(
|
||||||
|| { RwLock::new(Vec::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) {
|
pub fn modules(cfg: &mut app::web::ServiceConfig) {
|
||||||
for m in MODULES.read().unwrap().iter() {
|
for m in MODULES.read().unwrap().iter() {
|
||||||
m.configure_module(cfg);
|
m.configure_module(cfg);
|
||||||
|
|
@ -56,3 +47,50 @@ pub fn run_migrations() {
|
||||||
Migrator::up(&app::db::DBCONN, None)
|
Migrator::up(&app::db::DBCONN, None)
|
||||||
}).unwrap();
|
}).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) {
|
||||||
|
cfg.service(actix_web_static_files::ResourceFiles::new(
|
||||||
|
"/theme",
|
||||||
|
assets()
|
||||||
|
));
|
||||||
|
|
||||||
|
for t in THEMES.read().unwrap().iter() {
|
||||||
|
t.configure_theme(cfg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -8,7 +8,7 @@ pub use futures::executor::block_on as run_now;
|
||||||
// APIs públicas.
|
// APIs públicas.
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
mod all; // Variables globales privadas.
|
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.
|
||||||
|
|
@ -17,14 +17,13 @@ pub mod locale; // Localización.
|
||||||
#[cfg(any(feature = "mysql", feature = "postgres", feature = "sqlite"))]
|
#[cfg(any(feature = "mysql", feature = "postgres", feature = "sqlite"))]
|
||||||
pub mod db; // Acceso a la base de datos.
|
pub mod db; // Acceso a la base de datos.
|
||||||
|
|
||||||
pub mod html; // Publicación de código HTML desde el código.
|
pub mod html; // Publicación de HTML desde el código.
|
||||||
pub mod theme; // API para crear temas y temas predeterminados.
|
|
||||||
pub mod module; // API para crear módulos con nuevas funcionalidades.
|
pub mod module; // API para crear módulos con nuevas funcionalidades.
|
||||||
|
pub mod theme; // API para crear temas y temas predeterminados.
|
||||||
pub mod response; // Tipos de respuestas web.
|
pub mod response; // Tipos de respuestas web.
|
||||||
pub mod app; // Aplicación y servidor web.
|
pub mod app; // Aplicación y servidor web.
|
||||||
|
|
||||||
pub mod component; // Componentes base.
|
pub mod base; // Componentes, Módulos y Temas base.
|
||||||
|
|
||||||
pub mod util; // Macros y funciones útiles.
|
pub mod util; // Macros y funciones útiles.
|
||||||
|
|
||||||
pub mod prelude; // Re-exporta recursos comunes.
|
pub mod prelude; // Re-exporta recursos comunes.
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
|
use crate::app;
|
||||||
|
|
||||||
#[cfg(any(feature = "mysql", feature = "postgres", feature = "sqlite"))]
|
#[cfg(any(feature = "mysql", feature = "postgres", feature = "sqlite"))]
|
||||||
use crate::db;
|
use crate::db;
|
||||||
use crate::app;
|
|
||||||
|
|
||||||
use std::any::type_name;
|
use std::any::type_name;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,4 @@
|
||||||
use crate::{all, trace};
|
|
||||||
|
|
||||||
mod definition;
|
mod definition;
|
||||||
pub use definition::ModuleTrait;
|
pub use definition::ModuleTrait;
|
||||||
|
|
||||||
pub mod homepage;
|
pub use crate::global::register_module;
|
||||||
|
|
||||||
pub fn register_module(m: &'static dyn ModuleTrait) {
|
|
||||||
let mut modules = all::MODULES.write().unwrap();
|
|
||||||
match modules.iter().find(|t| t.name() == m.name()) {
|
|
||||||
None => {
|
|
||||||
trace::info!("{}", m.name());
|
|
||||||
modules.push(m);
|
|
||||||
},
|
|
||||||
Some(_) => {},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,6 @@ pub use crate::response::page::*;
|
||||||
pub use crate::app;
|
pub use crate::app;
|
||||||
pub use crate::app::application::{Application, essence};
|
pub use crate::app::application::{Application, essence};
|
||||||
|
|
||||||
pub use crate::component::*;
|
pub use crate::base::component::*;
|
||||||
|
|
||||||
pub use crate::util;
|
pub use crate::util;
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,7 @@
|
||||||
use crate::{Lazy, all};
|
use crate::global::DEFAULT_THEME;
|
||||||
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(|| {
|
|
||||||
for t in all::THEMES.read().unwrap().iter() {
|
|
||||||
if t.name().to_lowercase() == SETTINGS.app.theme.to_lowercase() {
|
|
||||||
return *t;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
&bootsier::BootsierTheme
|
|
||||||
});
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Favicon.
|
// Favicon.
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
@ -207,7 +197,7 @@ impl PageAssets {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn using_theme(&mut self, theme_name: &str) -> &mut Self {
|
pub fn using_theme(&mut self, theme_name: &str) -> &mut Self {
|
||||||
self.theme = find_theme(theme_name).unwrap_or(*DEFAULT_THEME);
|
self.theme = theme_by_name(theme_name).unwrap_or(*DEFAULT_THEME);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
|
use crate::app;
|
||||||
use crate::config::SETTINGS;
|
use crate::config::SETTINGS;
|
||||||
use crate::html::{Markup, html};
|
use crate::html::{Markup, html};
|
||||||
use crate::response::page::{Page, PageAssets, PageComponent};
|
use crate::response::page::{Page, PageAssets, PageComponent};
|
||||||
use crate::app;
|
use crate::base::component::Chunck;
|
||||||
use crate::component::Chunck;
|
|
||||||
|
|
||||||
/// Los temas deben implementar este "trait".
|
/// Los temas deben implementar este "trait".
|
||||||
pub trait ThemeTrait: Send + Sync {
|
pub trait ThemeTrait: Send + Sync {
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,5 @@
|
||||||
use crate::all;
|
|
||||||
|
|
||||||
mod definition;
|
mod definition;
|
||||||
pub use definition::ThemeTrait;
|
pub use definition::ThemeTrait;
|
||||||
|
|
||||||
pub mod aliner;
|
pub use crate::global::register_theme;
|
||||||
pub mod minimal;
|
pub use crate::global::theme_by_name;
|
||||||
pub mod bootsier;
|
|
||||||
|
|
||||||
pub fn register_theme(t: &'static dyn ThemeTrait) {
|
|
||||||
all::THEMES.write().unwrap().push(t);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn find_theme(name: &str) -> Option<&'static dyn ThemeTrait> {
|
|
||||||
let themes = all::THEMES.write().unwrap();
|
|
||||||
match themes.iter().find(|t| t.name() == name) {
|
|
||||||
Some(theme) => Some(*theme),
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue