🐛 Fix package registration
This commit is contained in:
parent
7fd262eaa0
commit
4ea28030c7
5 changed files with 26 additions and 57 deletions
6
examples/app-basic.rs
Normal file
6
examples/app-basic.rs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
use pagetop::prelude::*;
|
||||
|
||||
#[pagetop::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
Application::new().run()?.await
|
||||
}
|
||||
10
src/app.rs
10
src/app.rs
|
|
@ -34,12 +34,12 @@ impl Application {
|
|||
}
|
||||
|
||||
/// Prepares an application instance with a specific package.
|
||||
pub fn prepare(app: PackageRef) -> Self {
|
||||
Self::internal_prepare(Some(app))
|
||||
pub fn prepare(root_package: PackageRef) -> Self {
|
||||
Self::internal_prepare(Some(root_package))
|
||||
}
|
||||
|
||||
// Internal method to prepare the application, optionally with a package.
|
||||
fn internal_prepare(app: Option<PackageRef>) -> Self {
|
||||
fn internal_prepare(root_package: Option<PackageRef>) -> Self {
|
||||
// On startup, show the application banner.
|
||||
Self::show_banner();
|
||||
|
||||
|
|
@ -54,9 +54,7 @@ impl Application {
|
|||
LazyStatic::force(&db::DBCONN);
|
||||
|
||||
// Registers the application's packages.
|
||||
if let Some(app) = app {
|
||||
package::all::register_packages(app);
|
||||
}
|
||||
package::all::register_packages(root_package);
|
||||
|
||||
// Registers package actions.
|
||||
package::all::register_actions();
|
||||
|
|
|
|||
|
|
@ -7,8 +7,5 @@ pub use fluent::Fluent;
|
|||
mod body;
|
||||
pub use body::Body;
|
||||
|
||||
mod components;
|
||||
pub use components::Components;
|
||||
|
||||
mod region;
|
||||
pub use region::Region;
|
||||
|
|
|
|||
|
|
@ -1,36 +0,0 @@
|
|||
use crate::prelude::*;
|
||||
|
||||
#[derive(AutoDefault)]
|
||||
pub struct Components(MixedComponents);
|
||||
|
||||
impl ComponentTrait for Components {
|
||||
fn new() -> Self {
|
||||
Components::default()
|
||||
}
|
||||
|
||||
fn prepare_component(&self, cx: &mut Context) -> PrepareMarkup {
|
||||
PrepareMarkup::With(self.components().render(cx))
|
||||
}
|
||||
}
|
||||
|
||||
impl Components {
|
||||
// Components BUILDER.
|
||||
|
||||
#[fn_builder]
|
||||
pub fn alter_components(&mut self, op: AnyOp) -> &mut Self {
|
||||
self.0.alter_value(op);
|
||||
self
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
pub fn add_component(mut self, component: impl ComponentTrait) -> Self {
|
||||
self.0.alter_value(AnyOp::Add(AnyComponent::with(component)));
|
||||
self
|
||||
}
|
||||
|
||||
// Components GETTERS.
|
||||
|
||||
pub fn components(&self) -> &MixedComponents {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
|
@ -20,28 +20,32 @@ static DROPPED_PACKAGES: LazyStatic<RwLock<Vec<PackageRef>>> =
|
|||
|
||||
// REGISTER PACKAGES *******************************************************************************
|
||||
|
||||
pub fn register_packages(app: PackageRef) {
|
||||
pub fn register_packages(root_package: Option<PackageRef>) {
|
||||
// List of packages to drop.
|
||||
let mut list: Vec<PackageRef> = Vec::new();
|
||||
add_to_dropped(&mut list, app);
|
||||
DROPPED_PACKAGES.write().unwrap().append(&mut list);
|
||||
let mut packages_to_drop: Vec<PackageRef> = Vec::new();
|
||||
if let Some(package) = root_package {
|
||||
add_to_dropped(&mut packages_to_drop, package);
|
||||
}
|
||||
DROPPED_PACKAGES.write().unwrap().append(&mut packages_to_drop);
|
||||
|
||||
// List of packages to enable.
|
||||
let mut list: Vec<PackageRef> = Vec::new();
|
||||
let mut packages_to_enable: Vec<PackageRef> = Vec::new();
|
||||
|
||||
// Enable default welcome page.
|
||||
add_to_enabled(&mut list, &crate::base::package::Welcome);
|
||||
add_to_enabled(&mut packages_to_enable, &crate::base::package::Welcome);
|
||||
|
||||
// Enable default themes.
|
||||
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::Inception);
|
||||
add_to_enabled(&mut packages_to_enable, &crate::base::theme::Basic);
|
||||
add_to_enabled(&mut packages_to_enable, &crate::base::theme::Chassis);
|
||||
add_to_enabled(&mut packages_to_enable, &crate::base::theme::Inception);
|
||||
|
||||
// Enable application packages.
|
||||
add_to_enabled(&mut list, app);
|
||||
if let Some(package) = root_package {
|
||||
add_to_enabled(&mut packages_to_enable, package);
|
||||
}
|
||||
|
||||
list.reverse();
|
||||
ENABLED_PACKAGES.write().unwrap().append(&mut list);
|
||||
packages_to_enable.reverse();
|
||||
ENABLED_PACKAGES.write().unwrap().append(&mut packages_to_enable);
|
||||
}
|
||||
|
||||
fn add_to_dropped(list: &mut Vec<PackageRef>, package: PackageRef) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue