🚚 Refactor modules to packages to avoid Rust clash
This commit is contained in:
parent
98fa367ebc
commit
89f78a1aff
35 changed files with 125 additions and 123 deletions
12
Cargo.toml
12
Cargo.toml
|
|
@ -5,14 +5,14 @@ members = [
|
||||||
# Utilities.
|
# Utilities.
|
||||||
"pagetop-macros",
|
"pagetop-macros",
|
||||||
"pagetop-build",
|
"pagetop-build",
|
||||||
"pagetop-homedemo",
|
|
||||||
# Modules.
|
|
||||||
"pagetop-admin",
|
|
||||||
"pagetop-user",
|
|
||||||
"pagetop-node",
|
|
||||||
# Themes.
|
# Themes.
|
||||||
"pagetop-bootsier",
|
"pagetop-bootsier",
|
||||||
"pagetop-bulmix",
|
"pagetop-bulmix",
|
||||||
|
# Packages.
|
||||||
|
"pagetop-homedemo",
|
||||||
|
"pagetop-admin",
|
||||||
|
"pagetop-user",
|
||||||
|
"pagetop-node",
|
||||||
]
|
]
|
||||||
|
|
||||||
exclude = [
|
exclude = [
|
||||||
|
|
@ -20,3 +20,5 @@ exclude = [
|
||||||
"examples",
|
"examples",
|
||||||
"tests",
|
"tests",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
resolver = "2"
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,13 @@ use pagetop::prelude::*;
|
||||||
#[derive(AssignHandle)]
|
#[derive(AssignHandle)]
|
||||||
struct Drust;
|
struct Drust;
|
||||||
|
|
||||||
impl ModuleTrait for Drust {
|
impl PackageTrait for Drust {
|
||||||
fn dependencies(&self) -> Vec<ModuleRef> {
|
fn dependencies(&self) -> Vec<PackageRef> {
|
||||||
vec![
|
vec![
|
||||||
// Themes.
|
// Themes.
|
||||||
&pagetop_bootsier::Bootsier,
|
&pagetop_bootsier::Bootsier,
|
||||||
&pagetop_bulmix::Bulmix,
|
&pagetop_bulmix::Bulmix,
|
||||||
// Modules.
|
// Packages.
|
||||||
&pagetop_homedemo::HomeDemo,
|
&pagetop_homedemo::HomeDemo,
|
||||||
&pagetop_admin::Admin,
|
&pagetop_admin::Admin,
|
||||||
&pagetop_user::User,
|
&pagetop_user::User,
|
||||||
|
|
@ -17,7 +17,7 @@ impl ModuleTrait for Drust {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn drop_modules(&self) -> Vec<ModuleRef> {
|
fn drop_packages(&self) -> Vec<PackageRef> {
|
||||||
vec![
|
vec![
|
||||||
// &pagetop_node::Node
|
// &pagetop_node::Node
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ use pagetop::prelude::*;
|
||||||
#[derive(AssignHandle)]
|
#[derive(AssignHandle)]
|
||||||
struct HelloName;
|
struct HelloName;
|
||||||
|
|
||||||
impl ModuleTrait for HelloName {
|
impl PackageTrait for HelloName {
|
||||||
fn configure_service(&self, scfg: &mut service::web::ServiceConfig) {
|
fn configure_service(&self, scfg: &mut service::web::ServiceConfig) {
|
||||||
scfg.service(hello_name);
|
scfg.service(hello_name);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ use pagetop::prelude::*;
|
||||||
#[derive(AssignHandle)]
|
#[derive(AssignHandle)]
|
||||||
struct HelloWorld;
|
struct HelloWorld;
|
||||||
|
|
||||||
impl ModuleTrait for HelloWorld {
|
impl PackageTrait for HelloWorld {
|
||||||
fn configure_service(&self, scfg: &mut service::web::ServiceConfig) {
|
fn configure_service(&self, scfg: &mut service::web::ServiceConfig) {
|
||||||
scfg.route("/", service::web::get().to(hello_world));
|
scfg.route("/", service::web::get().to(hello_world));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,13 +7,13 @@ mod summary;
|
||||||
#[derive(AssignHandle)]
|
#[derive(AssignHandle)]
|
||||||
pub struct Admin;
|
pub struct Admin;
|
||||||
|
|
||||||
impl ModuleTrait for Admin {
|
impl PackageTrait for Admin {
|
||||||
fn name(&self) -> L10n {
|
fn name(&self) -> L10n {
|
||||||
L10n::t("module_name", &LOCALES_ADMIN)
|
L10n::t("package_name", &LOCALES_ADMIN)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn description(&self) -> L10n {
|
fn description(&self) -> L10n {
|
||||||
L10n::t("module_description", &LOCALES_ADMIN)
|
L10n::t("package_description", &LOCALES_ADMIN)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn actions(&self) -> Vec<Action> {
|
fn actions(&self) -> Vec<Action> {
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,2 @@
|
||||||
module_name = Admin module
|
package_name = Admin module
|
||||||
module_description = Administration module.
|
package_description = Administration module.
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,2 @@
|
||||||
module_name = Admin module
|
package_name = Admin module
|
||||||
module_description = Módulo de administración.
|
package_description = Módulo de administración.
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ use pagetop::prelude::*;
|
||||||
pub async fn summary(request: service::HttpRequest) -> ResultPage<Markup, ErrorPage> {
|
pub async fn summary(request: service::HttpRequest) -> ResultPage<Markup, ErrorPage> {
|
||||||
let top_menu = Menu::new()
|
let top_menu = Menu::new()
|
||||||
.with_id("admin-menu-test")
|
.with_id("admin-menu-test")
|
||||||
.add_item(menu::Item::label(L10n::t("module_name", &LOCALES_ADMIN)))
|
.add_item(menu::Item::label(L10n::t("package_name", &LOCALES_ADMIN)))
|
||||||
.add_item(menu::Item::label(L10n::n("Ejemplo \"Label\"")))
|
.add_item(menu::Item::label(L10n::n("Ejemplo \"Label\"")))
|
||||||
.add_item(menu::Item::link(L10n::n("Ejemplo \"Link\""), |_| {
|
.add_item(menu::Item::link(L10n::n("Ejemplo \"Link\""), |_| {
|
||||||
"https://www.google.es"
|
"https://www.google.es"
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ static_files!(bootsier);
|
||||||
#[derive(AssignHandle)]
|
#[derive(AssignHandle)]
|
||||||
pub struct Bootsier;
|
pub struct Bootsier;
|
||||||
|
|
||||||
impl ModuleTrait for Bootsier {
|
impl PackageTrait for Bootsier {
|
||||||
fn theme(&self) -> Option<ThemeRef> {
|
fn theme(&self) -> Option<ThemeRef> {
|
||||||
Some(&Bootsier)
|
Some(&Bootsier)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ static_files!(bulmix);
|
||||||
#[derive(AssignHandle)]
|
#[derive(AssignHandle)]
|
||||||
pub struct Bulmix;
|
pub struct Bulmix;
|
||||||
|
|
||||||
impl ModuleTrait for Bulmix {
|
impl PackageTrait for Bulmix {
|
||||||
fn theme(&self) -> Option<ThemeRef> {
|
fn theme(&self) -> Option<ThemeRef> {
|
||||||
Some(&Bulmix)
|
Some(&Bulmix)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,13 +7,13 @@ static_files!(homedemo);
|
||||||
#[derive(AssignHandle)]
|
#[derive(AssignHandle)]
|
||||||
pub struct HomeDemo;
|
pub struct HomeDemo;
|
||||||
|
|
||||||
impl ModuleTrait for HomeDemo {
|
impl PackageTrait for HomeDemo {
|
||||||
fn name(&self) -> L10n {
|
fn name(&self) -> L10n {
|
||||||
L10n::t("module_name", &LOCALES_HOMEDEMO)
|
L10n::t("package_name", &LOCALES_HOMEDEMO)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn description(&self) -> L10n {
|
fn description(&self) -> L10n {
|
||||||
L10n::t("module_description", &LOCALES_HOMEDEMO)
|
L10n::t("package_description", &LOCALES_HOMEDEMO)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn configure_service(&self, scfg: &mut service::web::ServiceConfig) {
|
fn configure_service(&self, scfg: &mut service::web::ServiceConfig) {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
module_name = Default homepage
|
package_name = Default homepage
|
||||||
module_description = Displays a demo homepage when none is configured.
|
package_description = Displays a demo homepage when none is configured.
|
||||||
|
|
||||||
page_title = Hello world!
|
page_title = Hello world!
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
module_name = Página de inicio predeterminada
|
package_name = Página de inicio predeterminada
|
||||||
module_description = Muestra una página de demostración predeterminada cuando no hay ninguna configurada.
|
package_description = Muestra una página de demostración predeterminada cuando no hay ninguna configurada.
|
||||||
|
|
||||||
page_title = ¡Hola mundo!
|
page_title = ¡Hola mundo!
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,13 +8,13 @@ mod migration;
|
||||||
#[derive(AssignHandle)]
|
#[derive(AssignHandle)]
|
||||||
pub struct Node;
|
pub struct Node;
|
||||||
|
|
||||||
impl ModuleTrait for Node {
|
impl PackageTrait for Node {
|
||||||
fn name(&self) -> L10n {
|
fn name(&self) -> L10n {
|
||||||
L10n::t("module_name", &LOCALES_NODE)
|
L10n::t("package_name", &LOCALES_NODE)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn description(&self) -> L10n {
|
fn description(&self) -> L10n {
|
||||||
L10n::t("module_description", &LOCALES_NODE)
|
L10n::t("package_description", &LOCALES_NODE)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn configure_service(&self, scfg: &mut service::web::ServiceConfig) {
|
fn configure_service(&self, scfg: &mut service::web::ServiceConfig) {
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,2 @@
|
||||||
module_name = Node
|
package_name = Node
|
||||||
module_description = Allows content to be submitted to the site and displayed on pages.
|
package_description = Allows content to be submitted to the site and displayed on pages.
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,2 @@
|
||||||
module_name = Nodo
|
package_name = Nodo
|
||||||
module_description = Permite enviar contenidos al sitio y mostrarlos en páginas.
|
package_description = Permite enviar contenidos al sitio y mostrarlos en páginas.
|
||||||
|
|
|
||||||
|
|
@ -7,13 +7,13 @@ mod migration;
|
||||||
#[derive(AssignHandle)]
|
#[derive(AssignHandle)]
|
||||||
pub struct User;
|
pub struct User;
|
||||||
|
|
||||||
impl ModuleTrait for User {
|
impl PackageTrait for User {
|
||||||
fn name(&self) -> L10n {
|
fn name(&self) -> L10n {
|
||||||
L10n::t("module_name", &LOCALES_USER)
|
L10n::t("package_name", &LOCALES_USER)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn description(&self) -> L10n {
|
fn description(&self) -> L10n {
|
||||||
L10n::t("module_description", &LOCALES_USER)
|
L10n::t("package_description", &LOCALES_USER)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn configure_service(&self, scfg: &mut service::web::ServiceConfig) {
|
fn configure_service(&self, scfg: &mut service::web::ServiceConfig) {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
module_name = User
|
package_name = User
|
||||||
module_description = Manages the user registration and login system.
|
package_description = Manages the user registration and login system.
|
||||||
|
|
||||||
username = User name
|
username = User name
|
||||||
password = Password
|
password = Password
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
module_name = Usuario
|
package_name = Usuario
|
||||||
module_description = Gestiona el registro de usuarios y el sistema de accesos.
|
package_description = Gestiona el registro de usuarios y el sistema de accesos.
|
||||||
|
|
||||||
username = Nombre de usuario
|
username = Nombre de usuario
|
||||||
password = Contraseña
|
password = Contraseña
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
mod figfont;
|
mod figfont;
|
||||||
|
|
||||||
use crate::core::{module, module::ModuleRef};
|
use crate::core::{package, package::PackageRef};
|
||||||
use crate::html::Markup;
|
use crate::html::Markup;
|
||||||
use crate::response::page::{ErrorPage, ResultPage};
|
use crate::response::page::{ErrorPage, ResultPage};
|
||||||
use crate::{concat_string, config, locale, service, trace, LazyStatic};
|
use crate::{concat_string, config, locale, service, trace, LazyStatic};
|
||||||
|
|
@ -21,7 +21,7 @@ use std::io::Error;
|
||||||
pub struct Application;
|
pub struct Application;
|
||||||
|
|
||||||
impl Application {
|
impl Application {
|
||||||
pub fn prepare(app: ModuleRef) -> Result<Self, Error> {
|
pub fn prepare(app: PackageRef) -> Result<Self, Error> {
|
||||||
// On startup.
|
// On startup.
|
||||||
show_banner();
|
show_banner();
|
||||||
|
|
||||||
|
|
@ -35,18 +35,18 @@ impl Application {
|
||||||
// Conecta con la base de datos.
|
// Conecta con la base de datos.
|
||||||
LazyStatic::force(&db::DBCONN);
|
LazyStatic::force(&db::DBCONN);
|
||||||
|
|
||||||
// Registra los módulos de la aplicación.
|
// Registra los paquetes de la aplicación.
|
||||||
module::all::register_modules(app);
|
package::all::register_packages(app);
|
||||||
|
|
||||||
// Registra acciones de los módulos.
|
// Registra acciones de los paquetes.
|
||||||
module::all::register_actions();
|
package::all::register_actions();
|
||||||
|
|
||||||
// Inicializa los módulos.
|
// Inicializa los paquetes.
|
||||||
module::all::init_modules();
|
package::all::init_packages();
|
||||||
|
|
||||||
#[cfg(feature = "database")]
|
#[cfg(feature = "database")]
|
||||||
// Ejecuta actualizaciones pendientes de la base de datos.
|
// Ejecuta actualizaciones pendientes de la base de datos.
|
||||||
module::all::run_migrations();
|
package::all::run_migrations();
|
||||||
|
|
||||||
Ok(Self)
|
Ok(Self)
|
||||||
}
|
}
|
||||||
|
|
@ -107,7 +107,7 @@ fn service_app() -> service::App<
|
||||||
>,
|
>,
|
||||||
> {
|
> {
|
||||||
service::App::new()
|
service::App::new()
|
||||||
.configure(module::all::configure_services)
|
.configure(package::all::configure_services)
|
||||||
.default_service(service::web::route().to(service_not_found))
|
.default_service(service::web::route().to(service_not_found))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
//! Base actions, components, modules, and themes.
|
//! Base actions, components, packages, and themes.
|
||||||
|
|
||||||
pub mod action;
|
pub mod action;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ use crate::BaseHandle;
|
||||||
#[derive(BaseHandle)]
|
#[derive(BaseHandle)]
|
||||||
pub struct Basic;
|
pub struct Basic;
|
||||||
|
|
||||||
impl ModuleTrait for Basic {
|
impl PackageTrait for Basic {
|
||||||
fn name(&self) -> L10n {
|
fn name(&self) -> L10n {
|
||||||
L10n::n("Basic")
|
L10n::n("Basic")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ use crate::BaseHandle;
|
||||||
#[derive(BaseHandle)]
|
#[derive(BaseHandle)]
|
||||||
pub struct Chassis;
|
pub struct Chassis;
|
||||||
|
|
||||||
impl ModuleTrait for Chassis {
|
impl PackageTrait for Chassis {
|
||||||
fn name(&self) -> L10n {
|
fn name(&self) -> L10n {
|
||||||
L10n::n("Chassis")
|
L10n::n("Chassis")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ use crate::BaseHandle;
|
||||||
#[derive(BaseHandle)]
|
#[derive(BaseHandle)]
|
||||||
pub struct Inception;
|
pub struct Inception;
|
||||||
|
|
||||||
impl ModuleTrait for Inception {
|
impl PackageTrait for Inception {
|
||||||
fn name(&self) -> L10n {
|
fn name(&self) -> L10n {
|
||||||
L10n::n("Inception")
|
L10n::n("Inception")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,7 @@
|
||||||
//! println!("Value of PAGETOP_RUN_MODE: {}", &config::SETTINGS.app.run_mode);
|
//! println!("Value of PAGETOP_RUN_MODE: {}", &config::SETTINGS.app.run_mode);
|
||||||
//! }
|
//! }
|
||||||
//!
|
//!
|
||||||
//! fn module_settings() {
|
//! fn package_settings() {
|
||||||
//! println!("{} - {:?}", &SETTINGS.myapp.name, &SETTINGS.myapp.description);
|
//! println!("{} - {:?}", &SETTINGS.myapp.name, &SETTINGS.myapp.description);
|
||||||
//! println!("{}", &SETTINGS.myapp.width);
|
//! println!("{}", &SETTINGS.myapp.width);
|
||||||
//! }
|
//! }
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
//! Key types and functions for creating actions, components, modules, and themes.
|
//! Key types and functions for creating actions, components, packages, and themes.
|
||||||
|
|
||||||
// API to define functions that alter the behavior of PageTop core.
|
// API to define functions that alter the behavior of PageTop core.
|
||||||
pub mod action;
|
pub mod action;
|
||||||
|
|
@ -6,8 +6,8 @@ pub mod action;
|
||||||
// API to build new components.
|
// API to build new components.
|
||||||
pub mod component;
|
pub mod component;
|
||||||
|
|
||||||
// API to add new features with modules.
|
// API to add new features with packages.
|
||||||
pub mod module;
|
pub mod package;
|
||||||
|
|
||||||
// API to add new layouts with themes.
|
// API to add new layouts with themes.
|
||||||
pub mod theme;
|
pub mod theme;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +0,0 @@
|
||||||
mod definition;
|
|
||||||
pub use definition::{ModuleBase, ModuleRef, ModuleTrait};
|
|
||||||
|
|
||||||
pub(crate) mod all;
|
|
||||||
4
pagetop/src/core/package.rs
Normal file
4
pagetop/src/core/package.rs
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
mod definition;
|
||||||
|
pub use definition::{PackageBase, PackageRef, PackageTrait};
|
||||||
|
|
||||||
|
pub(crate) mod all;
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::core::action::add_action;
|
use crate::core::action::add_action;
|
||||||
use crate::core::module::ModuleRef;
|
use crate::core::package::PackageRef;
|
||||||
use crate::core::theme::all::THEMES;
|
use crate::core::theme::all::THEMES;
|
||||||
use crate::{config, service, service_for_static_files, static_files, trace, LazyStatic};
|
use crate::{config, service, service_for_static_files, static_files, trace, LazyStatic};
|
||||||
|
|
||||||
|
|
@ -10,71 +10,71 @@ use std::sync::RwLock;
|
||||||
|
|
||||||
static_files!(base);
|
static_files!(base);
|
||||||
|
|
||||||
// MODULES *****************************************************************************************
|
// PACKAGES ****************************************************************************************
|
||||||
|
|
||||||
static ENABLED_MODULES: LazyStatic<RwLock<Vec<ModuleRef>>> =
|
static ENABLED_PACKAGES: LazyStatic<RwLock<Vec<PackageRef>>> =
|
||||||
LazyStatic::new(|| RwLock::new(Vec::new()));
|
LazyStatic::new(|| RwLock::new(Vec::new()));
|
||||||
|
|
||||||
static DROPPED_MODULES: LazyStatic<RwLock<Vec<ModuleRef>>> =
|
static DROPPED_PACKAGES: LazyStatic<RwLock<Vec<PackageRef>>> =
|
||||||
LazyStatic::new(|| RwLock::new(Vec::new()));
|
LazyStatic::new(|| RwLock::new(Vec::new()));
|
||||||
|
|
||||||
// REGISTER MODULES ********************************************************************************
|
// REGISTER PACKAGES *******************************************************************************
|
||||||
|
|
||||||
pub fn register_modules(app: ModuleRef) {
|
pub fn register_packages(app: PackageRef) {
|
||||||
// List of modules to drop.
|
// List of packages to drop.
|
||||||
let mut list: Vec<ModuleRef> = Vec::new();
|
let mut list: Vec<PackageRef> = Vec::new();
|
||||||
add_to_dropped(&mut list, app);
|
add_to_dropped(&mut list, app);
|
||||||
DROPPED_MODULES.write().unwrap().append(&mut list);
|
DROPPED_PACKAGES.write().unwrap().append(&mut list);
|
||||||
|
|
||||||
// List of modules to enable.
|
// List of packages to enable.
|
||||||
let mut list: Vec<ModuleRef> = Vec::new();
|
let mut list: Vec<PackageRef> = Vec::new();
|
||||||
|
|
||||||
// Enable default themes.
|
// Enable default themes.
|
||||||
add_to_enabled(&mut list, &crate::base::theme::Basic);
|
add_to_enabled(&mut list, &crate::base::theme::Basic);
|
||||||
add_to_enabled(&mut list, &crate::base::theme::Chassis);
|
add_to_enabled(&mut list, &crate::base::theme::Chassis);
|
||||||
add_to_enabled(&mut list, &crate::base::theme::Inception);
|
add_to_enabled(&mut list, &crate::base::theme::Inception);
|
||||||
|
|
||||||
// Enable application modules.
|
// Enable application packages.
|
||||||
add_to_enabled(&mut list, app);
|
add_to_enabled(&mut list, app);
|
||||||
|
|
||||||
list.reverse();
|
list.reverse();
|
||||||
ENABLED_MODULES.write().unwrap().append(&mut list);
|
ENABLED_PACKAGES.write().unwrap().append(&mut list);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_to_dropped(list: &mut Vec<ModuleRef>, module: ModuleRef) {
|
fn add_to_dropped(list: &mut Vec<PackageRef>, package: PackageRef) {
|
||||||
for d in module.drop_modules().iter() {
|
for d in package.drop_packages().iter() {
|
||||||
if !list.iter().any(|m| m.handle() == d.handle()) {
|
if !list.iter().any(|p| p.handle() == d.handle()) {
|
||||||
list.push(*d);
|
list.push(*d);
|
||||||
trace::debug!("Module \"{}\" dropped", d.single_name());
|
trace::debug!("Package \"{}\" dropped", d.single_name());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for d in module.dependencies().iter() {
|
for d in package.dependencies().iter() {
|
||||||
add_to_dropped(list, *d);
|
add_to_dropped(list, *d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_to_enabled(list: &mut Vec<ModuleRef>, module: ModuleRef) {
|
fn add_to_enabled(list: &mut Vec<PackageRef>, package: PackageRef) {
|
||||||
if !list.iter().any(|m| m.handle() == module.handle()) {
|
if !list.iter().any(|p| p.handle() == package.handle()) {
|
||||||
if DROPPED_MODULES
|
if DROPPED_PACKAGES
|
||||||
.read()
|
.read()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.iter()
|
.iter()
|
||||||
.any(|m| m.handle() == module.handle())
|
.any(|p| p.handle() == package.handle())
|
||||||
{
|
{
|
||||||
panic!(
|
panic!(
|
||||||
"Trying to enable \"{}\" module which is dropped",
|
"Trying to enable \"{}\" package which is dropped",
|
||||||
module.single_name()
|
package.single_name()
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
list.push(module);
|
list.push(package);
|
||||||
|
|
||||||
let mut dependencies = module.dependencies();
|
let mut dependencies = package.dependencies();
|
||||||
dependencies.reverse();
|
dependencies.reverse();
|
||||||
for d in dependencies.iter() {
|
for d in dependencies.iter() {
|
||||||
add_to_enabled(list, *d);
|
add_to_enabled(list, *d);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(theme) = module.theme() {
|
if let Some(theme) = package.theme() {
|
||||||
let mut registered_themes = THEMES.write().unwrap();
|
let mut registered_themes = THEMES.write().unwrap();
|
||||||
if !registered_themes
|
if !registered_themes
|
||||||
.iter()
|
.iter()
|
||||||
|
|
@ -84,7 +84,7 @@ fn add_to_enabled(list: &mut Vec<ModuleRef>, module: ModuleRef) {
|
||||||
trace::debug!("Enabling \"{}\" theme", theme.single_name());
|
trace::debug!("Enabling \"{}\" theme", theme.single_name());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
trace::debug!("Enabling \"{}\" module", module.single_name());
|
trace::debug!("Enabling \"{}\" package", package.single_name());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -93,18 +93,18 @@ fn add_to_enabled(list: &mut Vec<ModuleRef>, module: ModuleRef) {
|
||||||
// REGISTER ACTIONS ********************************************************************************
|
// REGISTER ACTIONS ********************************************************************************
|
||||||
|
|
||||||
pub fn register_actions() {
|
pub fn register_actions() {
|
||||||
for m in ENABLED_MODULES.read().unwrap().iter() {
|
for m in ENABLED_PACKAGES.read().unwrap().iter() {
|
||||||
for a in m.actions().into_iter() {
|
for a in m.actions().into_iter() {
|
||||||
add_action(a);
|
add_action(a);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// INIT MODULES ************************************************************************************
|
// INIT PACKAGES ***********************************************************************************
|
||||||
|
|
||||||
pub fn init_modules() {
|
pub fn init_packages() {
|
||||||
trace::info!("Calling application bootstrap");
|
trace::info!("Calling application bootstrap");
|
||||||
for m in ENABLED_MODULES.read().unwrap().iter() {
|
for m in ENABLED_PACKAGES.read().unwrap().iter() {
|
||||||
m.init();
|
m.init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -119,7 +119,7 @@ pub fn run_migrations() {
|
||||||
impl MigratorTrait for Migrator {
|
impl MigratorTrait for Migrator {
|
||||||
fn migrations() -> Vec<MigrationItem> {
|
fn migrations() -> Vec<MigrationItem> {
|
||||||
let mut migrations = vec![];
|
let mut migrations = vec![];
|
||||||
for m in ENABLED_MODULES.read().unwrap().iter() {
|
for m in ENABLED_PACKAGES.read().unwrap().iter() {
|
||||||
migrations.append(&mut m.migrations());
|
migrations.append(&mut m.migrations());
|
||||||
}
|
}
|
||||||
migrations
|
migrations
|
||||||
|
|
@ -135,7 +135,7 @@ pub fn run_migrations() {
|
||||||
impl MigratorTrait for Migrator {
|
impl MigratorTrait for Migrator {
|
||||||
fn migrations() -> Vec<MigrationItem> {
|
fn migrations() -> Vec<MigrationItem> {
|
||||||
let mut migrations = vec![];
|
let mut migrations = vec![];
|
||||||
for m in DROPPED_MODULES.read().unwrap().iter() {
|
for m in DROPPED_PACKAGES.read().unwrap().iter() {
|
||||||
migrations.append(&mut m.migrations());
|
migrations.append(&mut m.migrations());
|
||||||
}
|
}
|
||||||
migrations
|
migrations
|
||||||
|
|
@ -156,7 +156,7 @@ pub fn configure_services(scfg: &mut service::web::ServiceConfig) {
|
||||||
base => "/base",
|
base => "/base",
|
||||||
[&config::SETTINGS.dev.pagetop_project_dir, "pagetop/static/base"]
|
[&config::SETTINGS.dev.pagetop_project_dir, "pagetop/static/base"]
|
||||||
);
|
);
|
||||||
for m in ENABLED_MODULES.read().unwrap().iter() {
|
for m in ENABLED_PACKAGES.read().unwrap().iter() {
|
||||||
m.configure_service(scfg);
|
m.configure_service(scfg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -6,14 +6,14 @@ use crate::{actions, service, util, ImplementHandle};
|
||||||
#[cfg(feature = "database")]
|
#[cfg(feature = "database")]
|
||||||
use crate::{db::MigrationItem, migrations};
|
use crate::{db::MigrationItem, migrations};
|
||||||
|
|
||||||
pub type ModuleRef = &'static dyn ModuleTrait;
|
pub type PackageRef = &'static dyn PackageTrait;
|
||||||
|
|
||||||
pub trait ModuleBase {
|
pub trait PackageBase {
|
||||||
fn single_name(&self) -> &'static str;
|
fn single_name(&self) -> &'static str;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Los módulos deben implementar este *trait*.
|
/// Los paquetes deben implementar este *trait*.
|
||||||
pub trait ModuleTrait: ImplementHandle + ModuleBase + Send + Sync {
|
pub trait PackageTrait: ImplementHandle + PackageBase + Send + Sync {
|
||||||
fn name(&self) -> L10n {
|
fn name(&self) -> L10n {
|
||||||
L10n::n(self.single_name())
|
L10n::n(self.single_name())
|
||||||
}
|
}
|
||||||
|
|
@ -26,11 +26,11 @@ pub trait ModuleTrait: ImplementHandle + ModuleBase + Send + Sync {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dependencies(&self) -> Vec<ModuleRef> {
|
fn dependencies(&self) -> Vec<PackageRef> {
|
||||||
vec![]
|
vec![]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn drop_modules(&self) -> Vec<ModuleRef> {
|
fn drop_packages(&self) -> Vec<PackageRef> {
|
||||||
vec![]
|
vec![]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -50,7 +50,7 @@ pub trait ModuleTrait: ImplementHandle + ModuleBase + Send + Sync {
|
||||||
fn configure_service(&self, scfg: &mut service::web::ServiceConfig) {}
|
fn configure_service(&self, scfg: &mut service::web::ServiceConfig) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<M: ?Sized + ModuleTrait> ModuleBase for M {
|
impl<M: ?Sized + PackageTrait> PackageBase for M {
|
||||||
fn single_name(&self) -> &'static str {
|
fn single_name(&self) -> &'static str {
|
||||||
util::single_type_name::<Self>()
|
util::single_type_name::<Self>()
|
||||||
}
|
}
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::core::component::{ComponentTrait, Context};
|
use crate::core::component::{ComponentTrait, Context};
|
||||||
use crate::core::module::ModuleTrait;
|
use crate::core::package::PackageTrait;
|
||||||
use crate::html::{html, Favicon, Markup, OptionId};
|
use crate::html::{html, Favicon, Markup, OptionId};
|
||||||
use crate::locale::L10n;
|
use crate::locale::L10n;
|
||||||
use crate::response::page::Page;
|
use crate::response::page::Page;
|
||||||
|
|
@ -8,7 +8,7 @@ use crate::{concat_string, config};
|
||||||
pub type ThemeRef = &'static dyn ThemeTrait;
|
pub type ThemeRef = &'static dyn ThemeTrait;
|
||||||
|
|
||||||
/// Los temas deben implementar este "trait".
|
/// Los temas deben implementar este "trait".
|
||||||
pub trait ThemeTrait: ModuleTrait + Send + Sync {
|
pub trait ThemeTrait: PackageTrait + Send + Sync {
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
fn regions(&self) -> Vec<(&'static str, L10n)> {
|
fn regions(&self) -> Vec<(&'static str, L10n)> {
|
||||||
vec![
|
vec![
|
||||||
|
|
|
||||||
|
|
@ -28,11 +28,11 @@
|
||||||
//!
|
//!
|
||||||
//! * Essential web framework ([`service`]).
|
//! * Essential web framework ([`service`]).
|
||||||
//!
|
//!
|
||||||
//! * Key types and functions for creating actions, components, modules, and themes ([`core`]).
|
//! * Key types and functions for creating actions, components, packages, and themes ([`core`]).
|
||||||
//!
|
//!
|
||||||
//! * Web request response variants ([`response`]).
|
//! * Web request response variants ([`response`]).
|
||||||
//!
|
//!
|
||||||
//! * Base actions, components, modules, and themes ([`base`]).
|
//! * Base actions, components, packages, and themes ([`base`]).
|
||||||
//!
|
//!
|
||||||
//! * Utility functions ([`util`]).
|
//! * Utility functions ([`util`]).
|
||||||
//!
|
//!
|
||||||
|
|
@ -49,7 +49,7 @@
|
||||||
//! #[derive(AssignHandle)]
|
//! #[derive(AssignHandle)]
|
||||||
//! struct HelloWorld;
|
//! struct HelloWorld;
|
||||||
//!
|
//!
|
||||||
//! impl ModuleTrait for HelloWorld {
|
//! impl PackageTrait for HelloWorld {
|
||||||
//! fn configure_service(&self, scfg: &mut service::web::ServiceConfig) {
|
//! fn configure_service(&self, scfg: &mut service::web::ServiceConfig) {
|
||||||
//! scfg.route("/", service::web::get().to(hello_world));
|
//! scfg.route("/", service::web::get().to(hello_world));
|
||||||
//! }
|
//! }
|
||||||
|
|
@ -66,7 +66,7 @@
|
||||||
//! Application::prepare(&HelloWorld).unwrap().run()?.await
|
//! Application::prepare(&HelloWorld).unwrap().run()?.await
|
||||||
//! }
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
//! This program implements a module named `HelloWorld` with one service that returns a web page
|
//! This program implements a package named `HelloWorld` with one service that returns a web page
|
||||||
//! that greets the world whenever it is accessed from the browser at `http://localhost:8088` (using
|
//! that greets the world whenever it is accessed from the browser at `http://localhost:8088` (using
|
||||||
//! the [default configuration settings](`config::Server`)). You can find this code in the PageTop
|
//! the [default configuration settings](`config::Server`)). You can find this code in the PageTop
|
||||||
//! [basic examples repository](https://github.com/manuelcillero/pagetop/tree/main/examples/basics).
|
//! [basic examples repository](https://github.com/manuelcillero/pagetop/tree/main/examples/basics).
|
||||||
|
|
@ -74,15 +74,15 @@
|
||||||
//! # 🧱 Extending PageTop
|
//! # 🧱 Extending PageTop
|
||||||
//!
|
//!
|
||||||
//! The PageTop core API provides a comprehensive toolkit for extending its functionalities to
|
//! The PageTop core API provides a comprehensive toolkit for extending its functionalities to
|
||||||
//! specific requirements and application scenarios through actions, components, modules, and
|
//! specific requirements and application scenarios through actions, components, packages, and
|
||||||
//! themes:
|
//! themes:
|
||||||
//!
|
//!
|
||||||
//! * **Actions** serve as a mechanism to customize PageTop's internal behavior by intercepting its
|
//! * **Actions** serve as a mechanism to customize PageTop's internal behavior by intercepting its
|
||||||
//! execution flow.
|
//! execution flow.
|
||||||
//! * **Components** encapsulate HTML, CSS, and JavaScript into functional, configurable, and
|
//! * **Components** encapsulate HTML, CSS, and JavaScript into functional, configurable, and
|
||||||
//! well-defined units.
|
//! well-defined units.
|
||||||
//! * **Modules** extend or customize existing functionality by interacting with PageTop APIs or
|
//! * **Packages** extend or customize existing functionality by interacting with PageTop APIs or
|
||||||
//! third-party module APIs.
|
//! third-party package APIs.
|
||||||
//! * **Themes** enable developers to alter the appearance of pages and components without affecting
|
//! * **Themes** enable developers to alter the appearance of pages and components without affecting
|
||||||
//! their functionality.
|
//! their functionality.
|
||||||
//!
|
//!
|
||||||
|
|
@ -91,8 +91,8 @@
|
||||||
//! Projects leveraging PageTop will use `cargo` to resolve dependencies, similar to any other Rust
|
//! Projects leveraging PageTop will use `cargo` to resolve dependencies, similar to any other Rust
|
||||||
//! project.
|
//! project.
|
||||||
//!
|
//!
|
||||||
//! Nevertheless, it’s crucial that each module explicitly declares its
|
//! Nevertheless, it’s crucial that each package explicitly declares its
|
||||||
//! [dependencies](core::module::ModuleTrait#method.dependencies), if any, to assist PageTop in
|
//! [dependencies](core::package::PackageTrait#method.dependencies), if any, to assist PageTop in
|
||||||
//! structuring and initializing the application in a modular fashion.
|
//! structuring and initializing the application in a modular fashion.
|
||||||
|
|
||||||
#![cfg_attr(docsrs, feature(doc_cfg))]
|
#![cfg_attr(docsrs, feature(doc_cfg))]
|
||||||
|
|
@ -167,13 +167,13 @@ pub mod db;
|
||||||
// Essential web framework.
|
// Essential web framework.
|
||||||
pub mod service;
|
pub mod service;
|
||||||
|
|
||||||
// Key types and functions for creating actions, components, modules, and themes.
|
// Key types and functions for creating actions, components, packages, and themes.
|
||||||
pub mod core;
|
pub mod core;
|
||||||
|
|
||||||
// Web request response variants.
|
// Web request response variants.
|
||||||
pub mod response;
|
pub mod response;
|
||||||
|
|
||||||
// Base actions, components, modules, and themes.
|
// Base actions, components, packages, and themes.
|
||||||
pub mod base;
|
pub mod base;
|
||||||
|
|
||||||
// Prepare and run the application.
|
// Prepare and run the application.
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ pub use crate::service::HttpMessage;
|
||||||
|
|
||||||
pub use crate::core::action::*;
|
pub use crate::core::action::*;
|
||||||
pub use crate::core::component::*;
|
pub use crate::core::component::*;
|
||||||
pub use crate::core::module::*;
|
pub use crate::core::package::*;
|
||||||
pub use crate::core::theme::*;
|
pub use crate::core::theme::*;
|
||||||
|
|
||||||
pub use crate::response::{page::*, redirect::*, ResponseError};
|
pub use crate::response::{page::*, redirect::*, ResponseError};
|
||||||
|
|
|
||||||
|
|
@ -160,7 +160,7 @@ impl Page {
|
||||||
// Theme actions before preparing the page body.
|
// Theme actions before preparing the page body.
|
||||||
self.context.theme().before_prepare_body(self);
|
self.context.theme().before_prepare_body(self);
|
||||||
|
|
||||||
// Module actions before preparing the page body.
|
// Packages actions before preparing the page body.
|
||||||
action::page::BeforePrepareBody::dispatch(self);
|
action::page::BeforePrepareBody::dispatch(self);
|
||||||
|
|
||||||
// Prepare page body.
|
// Prepare page body.
|
||||||
|
|
@ -169,7 +169,7 @@ impl Page {
|
||||||
// Theme actions after preparing the page body.
|
// Theme actions after preparing the page body.
|
||||||
self.context.theme().after_prepare_body(self);
|
self.context.theme().after_prepare_body(self);
|
||||||
|
|
||||||
// Module actions after preparing the page body.
|
// Packages actions after preparing the page body.
|
||||||
action::page::AfterPrepareBody::dispatch(self);
|
action::page::AfterPrepareBody::dispatch(self);
|
||||||
|
|
||||||
// Prepare page head.
|
// Prepare page head.
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ use pagetop::prelude::*;
|
||||||
#[derive(AssignHandle)]
|
#[derive(AssignHandle)]
|
||||||
struct HealthCheck;
|
struct HealthCheck;
|
||||||
|
|
||||||
impl ModuleTrait for HealthCheck {}
|
impl PackageTrait for HealthCheck {}
|
||||||
|
|
||||||
#[pagetop::test]
|
#[pagetop::test]
|
||||||
async fn health_check_works() {
|
async fn health_check_works() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue