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]
|
||||
name = "pagetop"
|
||||
version = "0.0.2"
|
||||
version = "0.0.3"
|
||||
edition = "2021"
|
||||
|
||||
authors = [
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
use crate::{Lazy, all, app, trace};
|
||||
use crate::{Lazy, app, base, global, trace};
|
||||
use crate::config::SETTINGS;
|
||||
use crate::theme::*;
|
||||
use crate::module::*;
|
||||
use crate::module::register_module;
|
||||
|
||||
use std::io::Error;
|
||||
use actix_web::middleware::normalize::{NormalizePath, TrailingSlash};
|
||||
|
|
@ -52,30 +51,25 @@ impl Application {
|
|||
#[cfg(any(feature = "mysql", feature = "postgres", feature = "sqlite"))]
|
||||
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.
|
||||
trace::info!("Calling application bootstrap");
|
||||
let _ = &bootstrap();
|
||||
|
||||
// Registra el módulo para la página de inicio de PageTop.
|
||||
// Al ser el último, puede sobrecargarse con la función de inicio.
|
||||
register_module(&homepage::HomepageModule);
|
||||
// Registra el módulo para una página de presentación de PageTop.
|
||||
// Normalmente se sobrecargará en la función de inicio.
|
||||
register_module(&base::module::homepage::HomepageModule);
|
||||
|
||||
// Comprueba actualizaciones pendientes de la base de datos (opcional).
|
||||
#[cfg(any(feature = "mysql", feature = "postgres", feature = "sqlite"))]
|
||||
all::run_migrations();
|
||||
global::run_migrations();
|
||||
|
||||
// Prepara el servidor web.
|
||||
let server = app::HttpServer::new(move || {
|
||||
app::App::new()
|
||||
.wrap(tracing_actix_web::TracingLogger)
|
||||
.wrap(NormalizePath::new(TrailingSlash::Trim))
|
||||
.configure(&all::themes)
|
||||
.configure(&all::modules)
|
||||
.configure(&global::themes)
|
||||
.configure(&global::modules)
|
||||
})
|
||||
.bind(format!("{}:{}",
|
||||
&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::*;
|
||||
|
||||
localize!("src/module/homepage/locales");
|
||||
localize!("src/base/module/homepage/locales");
|
||||
|
||||
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"));
|
||||
|
||||
localize!("src/theme/bootsier/locales");
|
||||
localize!("src/base/theme/bootsier/locales");
|
||||
|
||||
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::theme::ThemeTrait;
|
||||
use crate::module::ModuleTrait;
|
||||
use crate::module::*;
|
||||
use crate::theme::*;
|
||||
|
||||
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.
|
||||
// -----------------------------------------------------------------------------
|
||||
|
|
@ -34,6 +14,17 @@ 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);
|
||||
|
|
@ -56,3 +47,50 @@ pub fn run_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) {
|
||||
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.
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
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 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"))]
|
||||
pub mod db; // Acceso a la base de datos.
|
||||
|
||||
pub mod html; // Publicación de código HTML desde el código.
|
||||
pub mod theme; // API para crear temas y temas predeterminados.
|
||||
pub mod html; // Publicación de HTML desde el código.
|
||||
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 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 prelude; // Re-exporta recursos comunes.
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
use crate::app;
|
||||
|
||||
#[cfg(any(feature = "mysql", feature = "postgres", feature = "sqlite"))]
|
||||
use crate::db;
|
||||
use crate::app;
|
||||
|
||||
use std::any::type_name;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,17 +1,4 @@
|
|||
use crate::{all, trace};
|
||||
|
||||
mod definition;
|
||||
pub use definition::ModuleTrait;
|
||||
|
||||
pub mod homepage;
|
||||
|
||||
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(_) => {},
|
||||
}
|
||||
}
|
||||
pub use crate::global::register_module;
|
||||
|
|
|
|||
|
|
@ -16,6 +16,6 @@ pub use crate::response::page::*;
|
|||
pub use crate::app;
|
||||
pub use crate::app::application::{Application, essence};
|
||||
|
||||
pub use crate::component::*;
|
||||
pub use crate::base::component::*;
|
||||
|
||||
pub use crate::util;
|
||||
|
|
|
|||
|
|
@ -1,17 +1,7 @@
|
|||
use crate::{Lazy, all};
|
||||
use crate::config::SETTINGS;
|
||||
use crate::global::DEFAULT_THEME;
|
||||
use crate::html::{Markup, PreEscaped, html};
|
||||
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.
|
||||
// -----------------------------------------------------------------------------
|
||||
|
|
@ -207,7 +197,7 @@ impl PageAssets {
|
|||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use crate::app;
|
||||
use crate::config::SETTINGS;
|
||||
use crate::html::{Markup, html};
|
||||
use crate::response::page::{Page, PageAssets, PageComponent};
|
||||
use crate::app;
|
||||
use crate::component::Chunck;
|
||||
use crate::base::component::Chunck;
|
||||
|
||||
/// Los temas deben implementar este "trait".
|
||||
pub trait ThemeTrait: Send + Sync {
|
||||
|
|
|
|||
|
|
@ -1,20 +1,5 @@
|
|||
use crate::all;
|
||||
|
||||
mod definition;
|
||||
pub use definition::ThemeTrait;
|
||||
|
||||
pub mod aliner;
|
||||
pub mod minimal;
|
||||
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,
|
||||
}
|
||||
}
|
||||
pub use crate::global::register_theme;
|
||||
pub use crate::global::theme_by_name;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue