💥 Replace action! macro with actions!
This commit is contained in:
parent
507015d5c9
commit
c50cfa985f
8 changed files with 22 additions and 15 deletions
|
|
@ -30,7 +30,7 @@ impl ModuleTrait for Admin {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn actions(&self) -> Vec<Action> {
|
fn actions(&self) -> Vec<Action> {
|
||||||
vec![action!(ActionBeforePrepareBody => before_prepare_body)]
|
actions![ActionBeforePrepareBody::with(before_prepare_body)]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn configure_service(&self, scfg: &mut service::web::ServiceConfig) {
|
fn configure_service(&self, scfg: &mut service::web::ServiceConfig) {
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ impl ModuleTrait for JQuery {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn actions(&self) -> Vec<Action> {
|
fn actions(&self) -> Vec<Action> {
|
||||||
vec![action!(ActionAfterPrepareBody => after_prepare_body)]
|
actions![ActionAfterPrepareBody::with(after_prepare_body)]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn configure_service(&self, scfg: &mut service::web::ServiceConfig) {
|
fn configure_service(&self, scfg: &mut service::web::ServiceConfig) {
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ impl ModuleTrait for Minimal {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn actions(&self) -> Vec<Action> {
|
fn actions(&self) -> Vec<Action> {
|
||||||
vec![action!(ActionAfterPrepareBody => after_prepare_body, 99)]
|
actions![ActionAfterPrepareBody::with(after_prepare_body).with_weight(99)]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn configure_service(&self, scfg: &mut service::web::ServiceConfig) {
|
fn configure_service(&self, scfg: &mut service::web::ServiceConfig) {
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ impl ModuleTrait for Node {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn actions(&self) -> Vec<Action> {
|
fn actions(&self) -> Vec<Action> {
|
||||||
vec![action!(ActionBeforePrepareBody => before_prepare_body, -1)]
|
actions![ActionBeforePrepareBody::with(before_prepare_body).with_weight(-1)]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn migrations(&self) -> Vec<MigrationItem> {
|
fn migrations(&self) -> Vec<MigrationItem> {
|
||||||
|
|
|
||||||
|
|
@ -8,10 +8,3 @@ use list::ActionsList;
|
||||||
mod all;
|
mod all;
|
||||||
pub(crate) use all::add_action;
|
pub(crate) use all::add_action;
|
||||||
pub use all::run_actions;
|
pub use all::run_actions;
|
||||||
|
|
||||||
#[macro_export]
|
|
||||||
macro_rules! action {
|
|
||||||
( $action:ty => $f:ident $(, $weight:expr)? ) => {{
|
|
||||||
Box::new(<$action>::new().with_action($f)$(.with_weight($weight))?)
|
|
||||||
}};
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -31,3 +31,17 @@ impl ActionsList {
|
||||||
let _: Vec<_> = self.0.read().unwrap().iter().map(f).collect();
|
let _: Vec<_> = self.0.read().unwrap().iter().map(f).collect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! actions {
|
||||||
|
() => {
|
||||||
|
Vec::<Action>::new()
|
||||||
|
};
|
||||||
|
( $($action:expr),+ $(,)? ) => {{
|
||||||
|
let mut v = Vec::<Action>::new();
|
||||||
|
$(
|
||||||
|
v.push(Box::new($action));
|
||||||
|
)*
|
||||||
|
v
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::core::action::Action;
|
use crate::core::action::Action;
|
||||||
use crate::core::component::L10n;
|
use crate::core::component::L10n;
|
||||||
use crate::core::theme::ThemeRef;
|
use crate::core::theme::ThemeRef;
|
||||||
use crate::{service, util, Handle};
|
use crate::{actions, service, util, Handle};
|
||||||
|
|
||||||
#[cfg(feature = "database")]
|
#[cfg(feature = "database")]
|
||||||
use crate::{db::MigrationItem, migrations};
|
use crate::{db::MigrationItem, migrations};
|
||||||
|
|
@ -37,7 +37,7 @@ pub trait ModuleTrait: ModuleBase + Send + Sync {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn actions(&self) -> Vec<Action> {
|
fn actions(&self) -> Vec<Action> {
|
||||||
vec![]
|
actions![]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn init(&self) {}
|
fn init(&self) {}
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,8 @@ pub use crate::default_settings;
|
||||||
pub use crate::static_locales;
|
pub use crate::static_locales;
|
||||||
// crate::service
|
// crate::service
|
||||||
pub use crate::{static_files, static_files_service};
|
pub use crate::{static_files, static_files_service};
|
||||||
// crate::core::action
|
// crate::core::actions
|
||||||
pub use crate::action;
|
pub use crate::actions;
|
||||||
// crate::core::component
|
// crate::core::component
|
||||||
pub use crate::actions_for_component;
|
pub use crate::actions_for_component;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue