🚧 Working on actions
This commit is contained in:
parent
e732244a2e
commit
d99a5aa586
23 changed files with 480 additions and 323 deletions
|
|
@ -1,3 +1,9 @@
|
|||
pub mod component;
|
||||
use crate::prelude::*;
|
||||
|
||||
pub type FnActionWithComponent<C> = fn(component: &mut C, cx: &mut Context);
|
||||
|
||||
pub mod page;
|
||||
|
||||
pub mod theme;
|
||||
|
||||
pub mod component;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,3 @@
|
|||
use crate::prelude::*;
|
||||
|
||||
pub type FnActionComponent<C> = fn(component: &mut C, cx: &mut Context);
|
||||
|
||||
mod before_prepare_component;
|
||||
pub use before_prepare_component::*;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
use crate::prelude::*;
|
||||
|
||||
use super::FnActionComponent;
|
||||
use crate::base::action::FnActionWithComponent;
|
||||
|
||||
pub struct AfterPrepareComponent<C: ComponentTrait> {
|
||||
f: FnActionComponent<C>,
|
||||
pub struct AfterPrepare<C: ComponentTrait> {
|
||||
f: FnActionWithComponent<C>,
|
||||
referer_type_id: Option<TypeId>,
|
||||
referer_id: OptionId,
|
||||
weight: Weight,
|
||||
}
|
||||
|
||||
impl<C: ComponentTrait> ActionTrait for AfterPrepareComponent<C> {
|
||||
impl<C: ComponentTrait> ActionTrait for AfterPrepare<C> {
|
||||
fn referer_type_id(&self) -> Option<TypeId> {
|
||||
self.referer_type_id
|
||||
}
|
||||
|
|
@ -23,9 +23,9 @@ impl<C: ComponentTrait> ActionTrait for AfterPrepareComponent<C> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<C: ComponentTrait> AfterPrepareComponent<C> {
|
||||
pub fn new(f: FnActionComponent<C>) -> Self {
|
||||
AfterPrepareComponent {
|
||||
impl<C: ComponentTrait> AfterPrepare<C> {
|
||||
pub fn new(f: FnActionWithComponent<C>) -> Self {
|
||||
AfterPrepare {
|
||||
f,
|
||||
referer_type_id: Some(TypeId::of::<C>()),
|
||||
referer_id: OptionId::default(),
|
||||
|
|
@ -44,10 +44,25 @@ impl<C: ComponentTrait> AfterPrepareComponent<C> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub(crate) fn dispatch(component: &mut C, cx: &mut Context, referer_id: Option<String>) {
|
||||
pub(crate) fn dispatch(component: &mut C, cx: &mut Context) {
|
||||
dispatch_actions(
|
||||
(TypeId::of::<Self>(), Some(TypeId::of::<C>()), referer_id),
|
||||
ActionKey::new(TypeId::of::<Self>(), None, Some(TypeId::of::<C>()), None),
|
||||
|action: &Self| (action.f)(component, cx),
|
||||
);
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub(crate) fn dispatch_by_id(component: &mut C, cx: &mut Context) {
|
||||
if component.id().is_some() {
|
||||
dispatch_actions(
|
||||
ActionKey::new(
|
||||
TypeId::of::<Self>(),
|
||||
None,
|
||||
Some(TypeId::of::<C>()),
|
||||
component.id(),
|
||||
),
|
||||
|action: &Self| (action.f)(component, cx),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
use crate::prelude::*;
|
||||
|
||||
use super::FnActionComponent;
|
||||
use crate::base::action::FnActionWithComponent;
|
||||
|
||||
pub struct BeforePrepareComponent<C: ComponentTrait> {
|
||||
f: FnActionComponent<C>,
|
||||
pub struct BeforePrepare<C: ComponentTrait> {
|
||||
f: FnActionWithComponent<C>,
|
||||
referer_type_id: Option<TypeId>,
|
||||
referer_id: OptionId,
|
||||
weight: Weight,
|
||||
}
|
||||
|
||||
impl<C: ComponentTrait> ActionTrait for BeforePrepareComponent<C> {
|
||||
impl<C: ComponentTrait> ActionTrait for BeforePrepare<C> {
|
||||
fn referer_type_id(&self) -> Option<TypeId> {
|
||||
self.referer_type_id
|
||||
}
|
||||
|
|
@ -23,9 +23,9 @@ impl<C: ComponentTrait> ActionTrait for BeforePrepareComponent<C> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<C: ComponentTrait> BeforePrepareComponent<C> {
|
||||
pub fn new(f: FnActionComponent<C>) -> Self {
|
||||
BeforePrepareComponent {
|
||||
impl<C: ComponentTrait> BeforePrepare<C> {
|
||||
pub fn new(f: FnActionWithComponent<C>) -> Self {
|
||||
BeforePrepare {
|
||||
f,
|
||||
referer_type_id: Some(TypeId::of::<C>()),
|
||||
referer_id: OptionId::default(),
|
||||
|
|
@ -44,10 +44,25 @@ impl<C: ComponentTrait> BeforePrepareComponent<C> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub(crate) fn dispatch(component: &mut C, cx: &mut Context, referer_id: Option<String>) {
|
||||
pub(crate) fn dispatch(component: &mut C, cx: &mut Context) {
|
||||
dispatch_actions(
|
||||
(TypeId::of::<Self>(), Some(TypeId::of::<C>()), referer_id),
|
||||
ActionKey::new(TypeId::of::<Self>(), None, Some(TypeId::of::<C>()), None),
|
||||
|action: &Self| (action.f)(component, cx),
|
||||
);
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub(crate) fn dispatch_by_id(component: &mut C, cx: &mut Context) {
|
||||
if component.id().is_some() {
|
||||
dispatch_actions(
|
||||
ActionKey::new(
|
||||
TypeId::of::<Self>(),
|
||||
None,
|
||||
Some(TypeId::of::<C>()),
|
||||
component.id(),
|
||||
),
|
||||
|action: &Self| (action.f)(component, cx),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,3 @@
|
|||
use crate::prelude::*;
|
||||
|
||||
pub type FnActionPage = fn(page: &mut Page);
|
||||
|
||||
mod before_prepare_body;
|
||||
pub use before_prepare_body::*;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
use crate::prelude::*;
|
||||
|
||||
use super::FnActionPage;
|
||||
pub type FnAfterPrepareBody = fn(page: &mut Page);
|
||||
|
||||
pub struct AfterPrepareBody {
|
||||
f: FnActionPage,
|
||||
f: FnAfterPrepareBody,
|
||||
weight: Weight,
|
||||
}
|
||||
|
||||
|
|
@ -14,7 +14,7 @@ impl ActionTrait for AfterPrepareBody {
|
|||
}
|
||||
|
||||
impl AfterPrepareBody {
|
||||
pub fn new(f: FnActionPage) -> Self {
|
||||
pub fn new(f: FnAfterPrepareBody) -> Self {
|
||||
AfterPrepareBody { f, weight: 0 }
|
||||
}
|
||||
|
||||
|
|
@ -25,8 +25,9 @@ impl AfterPrepareBody {
|
|||
|
||||
#[inline(always)]
|
||||
pub(crate) fn dispatch(page: &mut Page) {
|
||||
dispatch_actions((TypeId::of::<Self>(), None, None), |action: &Self| {
|
||||
(action.f)(page)
|
||||
});
|
||||
dispatch_actions(
|
||||
ActionKey::new(TypeId::of::<Self>(), None, None, None),
|
||||
|action: &Self| (action.f)(page),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
use crate::prelude::*;
|
||||
|
||||
use super::FnActionPage;
|
||||
pub type FnBeforePrepareBody = fn(page: &mut Page);
|
||||
|
||||
pub struct BeforePrepareBody {
|
||||
f: FnActionPage,
|
||||
f: FnBeforePrepareBody,
|
||||
weight: Weight,
|
||||
}
|
||||
|
||||
|
|
@ -14,7 +14,7 @@ impl ActionTrait for BeforePrepareBody {
|
|||
}
|
||||
|
||||
impl BeforePrepareBody {
|
||||
pub fn new(f: FnActionPage) -> Self {
|
||||
pub fn new(f: FnBeforePrepareBody) -> Self {
|
||||
BeforePrepareBody { f, weight: 0 }
|
||||
}
|
||||
|
||||
|
|
@ -25,8 +25,9 @@ impl BeforePrepareBody {
|
|||
|
||||
#[inline(always)]
|
||||
pub(crate) fn dispatch(page: &mut Page) {
|
||||
dispatch_actions((TypeId::of::<Self>(), None, None), |action: &Self| {
|
||||
(action.f)(page)
|
||||
});
|
||||
dispatch_actions(
|
||||
ActionKey::new(TypeId::of::<Self>(), None, None, None),
|
||||
|action: &Self| (action.f)(page),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
8
src/base/action/theme.rs
Normal file
8
src/base/action/theme.rs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
mod before_prepare_component;
|
||||
pub use before_prepare_component::*;
|
||||
|
||||
mod after_prepare_component;
|
||||
pub use after_prepare_component::*;
|
||||
|
||||
mod render_component;
|
||||
pub use render_component::*;
|
||||
42
src/base/action/theme/after_prepare_component.rs
Normal file
42
src/base/action/theme/after_prepare_component.rs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
use crate::prelude::*;
|
||||
|
||||
use crate::base::action::FnActionWithComponent;
|
||||
|
||||
pub struct AfterPrepare<C: ComponentTrait> {
|
||||
f: FnActionWithComponent<C>,
|
||||
theme_type_id: Option<TypeId>,
|
||||
referer_type_id: Option<TypeId>,
|
||||
}
|
||||
|
||||
impl<C: ComponentTrait> ActionTrait for AfterPrepare<C> {
|
||||
fn theme_type_id(&self) -> Option<TypeId> {
|
||||
self.theme_type_id
|
||||
}
|
||||
|
||||
fn referer_type_id(&self) -> Option<TypeId> {
|
||||
self.referer_type_id
|
||||
}
|
||||
}
|
||||
|
||||
impl<C: ComponentTrait> AfterPrepare<C> {
|
||||
pub fn new(theme: ThemeRef, f: FnActionWithComponent<C>) -> Self {
|
||||
AfterPrepare {
|
||||
f,
|
||||
theme_type_id: Some(theme.type_id()),
|
||||
referer_type_id: Some(TypeId::of::<C>()),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub(crate) fn dispatch(component: &mut C, cx: &mut Context) {
|
||||
dispatch_actions(
|
||||
ActionKey::new(
|
||||
TypeId::of::<Self>(),
|
||||
Some(cx.theme().type_id()),
|
||||
Some(TypeId::of::<C>()),
|
||||
None,
|
||||
),
|
||||
|action: &Self| (action.f)(component, cx),
|
||||
);
|
||||
}
|
||||
}
|
||||
42
src/base/action/theme/before_prepare_component.rs
Normal file
42
src/base/action/theme/before_prepare_component.rs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
use crate::prelude::*;
|
||||
|
||||
use crate::base::action::FnActionWithComponent;
|
||||
|
||||
pub struct BeforePrepare<C: ComponentTrait> {
|
||||
f: FnActionWithComponent<C>,
|
||||
theme_type_id: Option<TypeId>,
|
||||
referer_type_id: Option<TypeId>,
|
||||
}
|
||||
|
||||
impl<C: ComponentTrait> ActionTrait for BeforePrepare<C> {
|
||||
fn theme_type_id(&self) -> Option<TypeId> {
|
||||
self.theme_type_id
|
||||
}
|
||||
|
||||
fn referer_type_id(&self) -> Option<TypeId> {
|
||||
self.referer_type_id
|
||||
}
|
||||
}
|
||||
|
||||
impl<C: ComponentTrait> BeforePrepare<C> {
|
||||
pub fn new(theme: ThemeRef, f: FnActionWithComponent<C>) -> Self {
|
||||
BeforePrepare {
|
||||
f,
|
||||
theme_type_id: Some(theme.type_id()),
|
||||
referer_type_id: Some(TypeId::of::<C>()),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub(crate) fn dispatch(component: &mut C, cx: &mut Context) {
|
||||
dispatch_actions(
|
||||
ActionKey::new(
|
||||
TypeId::of::<Self>(),
|
||||
Some(cx.theme().type_id()),
|
||||
Some(TypeId::of::<C>()),
|
||||
None,
|
||||
),
|
||||
|action: &Self| (action.f)(component, cx),
|
||||
);
|
||||
}
|
||||
}
|
||||
48
src/base/action/theme/render_component.rs
Normal file
48
src/base/action/theme/render_component.rs
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
use crate::prelude::*;
|
||||
|
||||
pub type FnRenderComponent<C> = fn(component: &C, cx: &mut Context) -> Option<Markup>;
|
||||
|
||||
pub struct RenderComponent<C: ComponentTrait> {
|
||||
f: FnRenderComponent<C>,
|
||||
theme_type_id: Option<TypeId>,
|
||||
referer_type_id: Option<TypeId>,
|
||||
}
|
||||
|
||||
impl<C: ComponentTrait> ActionTrait for RenderComponent<C> {
|
||||
fn theme_type_id(&self) -> Option<TypeId> {
|
||||
self.theme_type_id
|
||||
}
|
||||
|
||||
fn referer_type_id(&self) -> Option<TypeId> {
|
||||
self.referer_type_id
|
||||
}
|
||||
}
|
||||
|
||||
impl<C: ComponentTrait> RenderComponent<C> {
|
||||
pub fn new(theme: ThemeRef, f: FnRenderComponent<C>) -> Self {
|
||||
RenderComponent {
|
||||
f,
|
||||
theme_type_id: Some(theme.type_id()),
|
||||
referer_type_id: Some(TypeId::of::<C>()),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub(crate) fn dispatch(component: &C, cx: &mut Context) -> Option<Markup> {
|
||||
let mut render_component: Option<Markup> = None;
|
||||
dispatch_actions(
|
||||
ActionKey::new(
|
||||
TypeId::of::<Self>(),
|
||||
Some(cx.theme().type_id()),
|
||||
Some(TypeId::of::<C>()),
|
||||
None,
|
||||
),
|
||||
|action: &Self| {
|
||||
if render_component.is_none() {
|
||||
render_component = (action.f)(component, cx);
|
||||
}
|
||||
},
|
||||
);
|
||||
render_component
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +1,19 @@
|
|||
mod definition;
|
||||
pub use definition::ActionTrait;
|
||||
pub use definition::{ActionBase, ActionBox, ActionKey, ActionTrait};
|
||||
|
||||
mod list;
|
||||
pub use list::Action;
|
||||
use list::ActionsList;
|
||||
|
||||
mod all;
|
||||
pub(crate) use all::add_action;
|
||||
pub use all::{dispatch_actions, KeyAction};
|
||||
pub use all::dispatch_actions;
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! actions {
|
||||
() => {
|
||||
Vec::<ActionBox>::new()
|
||||
};
|
||||
( $($action:expr),+ $(,)? ) => {{
|
||||
vec![$(Box::new($action),)+]
|
||||
}};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,35 +1,31 @@
|
|||
use crate::core::action::{Action, ActionTrait, ActionsList};
|
||||
use crate::{LazyStatic, TypeId};
|
||||
use crate::core::action::{ActionBox, ActionKey, ActionTrait, ActionsList};
|
||||
use crate::LazyStatic;
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::sync::RwLock;
|
||||
|
||||
pub type KeyAction = (TypeId, Option<TypeId>, Option<String>);
|
||||
|
||||
// Registered actions.
|
||||
static ACTIONS: LazyStatic<RwLock<HashMap<KeyAction, ActionsList>>> =
|
||||
static ACTIONS: LazyStatic<RwLock<HashMap<ActionKey, ActionsList>>> =
|
||||
LazyStatic::new(|| RwLock::new(HashMap::new()));
|
||||
|
||||
pub fn add_action(action: Action) {
|
||||
pub fn add_action(action: ActionBox) {
|
||||
let key = action.key();
|
||||
let mut actions = ACTIONS.write().unwrap();
|
||||
let key_action = (
|
||||
action.type_id(),
|
||||
action.referer_type_id(),
|
||||
action.referer_id(),
|
||||
);
|
||||
if let Some(list) = actions.get_mut(&key_action) {
|
||||
if let Some(list) = actions.get_mut(&key) {
|
||||
list.add(action);
|
||||
} else {
|
||||
actions.insert(key_action, ActionsList::new(action));
|
||||
let mut list = ActionsList::new();
|
||||
list.add(action);
|
||||
actions.insert(key, list);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn dispatch_actions<A, B, F>(key_action: KeyAction, f: F)
|
||||
pub fn dispatch_actions<A, B, F>(key: ActionKey, f: F)
|
||||
where
|
||||
A: ActionTrait,
|
||||
F: FnMut(&A) -> B,
|
||||
{
|
||||
if let Some(list) = ACTIONS.read().unwrap().get(&key_action) {
|
||||
if let Some(list) = ACTIONS.read().unwrap().get(&key) {
|
||||
list.iter_map(f)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,41 @@
|
|||
use crate::core::AnyBase;
|
||||
use crate::{TypeId, Weight};
|
||||
|
||||
pub trait ActionTrait: AnyBase + Send + Sync {
|
||||
pub type ActionBox = Box<dyn ActionTrait>;
|
||||
|
||||
#[derive(Eq, PartialEq, Hash)]
|
||||
pub struct ActionKey {
|
||||
action_type_id: TypeId,
|
||||
theme_type_id: Option<TypeId>,
|
||||
referer_type_id: Option<TypeId>,
|
||||
referer_id: Option<String>,
|
||||
}
|
||||
|
||||
impl ActionKey {
|
||||
pub fn new(
|
||||
action_type_id: TypeId,
|
||||
theme_type_id: Option<TypeId>,
|
||||
referer_type_id: Option<TypeId>,
|
||||
referer_id: Option<String>,
|
||||
) -> Self {
|
||||
ActionKey {
|
||||
action_type_id,
|
||||
theme_type_id,
|
||||
referer_type_id,
|
||||
referer_id,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait ActionBase {
|
||||
fn key(&self) -> ActionKey;
|
||||
}
|
||||
|
||||
pub trait ActionTrait: ActionBase + AnyBase + Send + Sync {
|
||||
fn theme_type_id(&self) -> Option<TypeId> {
|
||||
None
|
||||
}
|
||||
|
||||
fn referer_type_id(&self) -> Option<TypeId> {
|
||||
None
|
||||
}
|
||||
|
|
@ -14,3 +48,14 @@ pub trait ActionTrait: AnyBase + Send + Sync {
|
|||
0
|
||||
}
|
||||
}
|
||||
|
||||
impl<A: ActionTrait> ActionBase for A {
|
||||
fn key(&self) -> ActionKey {
|
||||
ActionKey {
|
||||
action_type_id: self.type_id(),
|
||||
theme_type_id: self.theme_type_id(),
|
||||
referer_type_id: self.referer_type_id(),
|
||||
referer_id: self.referer_id(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,23 +1,19 @@
|
|||
use crate::core::action::ActionTrait;
|
||||
use crate::core::action::{ActionBox, ActionTrait};
|
||||
use crate::core::AnyTo;
|
||||
use crate::trace;
|
||||
use crate::AutoDefault;
|
||||
|
||||
use std::sync::{Arc, RwLock};
|
||||
|
||||
pub type Action = Box<dyn ActionTrait>;
|
||||
use std::sync::RwLock;
|
||||
|
||||
#[derive(AutoDefault)]
|
||||
pub struct ActionsList(Arc<RwLock<Vec<Action>>>);
|
||||
pub struct ActionsList(RwLock<Vec<ActionBox>>);
|
||||
|
||||
impl ActionsList {
|
||||
pub fn new(action: Action) -> Self {
|
||||
let mut list = ActionsList::default();
|
||||
list.add(action);
|
||||
list
|
||||
pub fn new() -> Self {
|
||||
ActionsList::default()
|
||||
}
|
||||
|
||||
pub fn add(&mut self, action: Action) {
|
||||
pub fn add(&mut self, action: ActionBox) {
|
||||
let mut list = self.0.write().unwrap();
|
||||
list.push(action);
|
||||
list.sort_by_key(|a| a.weight());
|
||||
|
|
@ -35,26 +31,12 @@ impl ActionsList {
|
|||
.unwrap()
|
||||
.iter()
|
||||
.map(|a| {
|
||||
if let Some(action) = (&**a).downcast_ref::<A>() {
|
||||
if let Some(action) = (**a).downcast_ref::<A>() {
|
||||
f(action);
|
||||
} else {
|
||||
trace::error!("Failed to downcast action of type {}", (&**a).type_name());
|
||||
trace::error!("Failed to downcast action of type {}", (**a).type_name());
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! actions {
|
||||
() => {
|
||||
Vec::<Action>::new()
|
||||
};
|
||||
( $($action:expr),+ $(,)? ) => {{
|
||||
let mut v = Vec::<Action>::new();
|
||||
$(
|
||||
v.push(Box::new($action));
|
||||
)*
|
||||
v
|
||||
}};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,16 +50,14 @@ impl<C: ComponentTrait> ComponentBase for C {
|
|||
self.setup_before_prepare(cx);
|
||||
|
||||
// Acciones del tema antes de preparar el componente.
|
||||
cx.theme().before_prepare_component(self, cx);
|
||||
action::theme::BeforePrepare::dispatch(self, cx);
|
||||
|
||||
// Acciones de los módulos antes de preparar el componente.
|
||||
action::component::BeforePrepareComponent::dispatch(self, cx, None);
|
||||
if let Some(id) = self.id() {
|
||||
action::component::BeforePrepareComponent::dispatch(self, cx, Some(id));
|
||||
}
|
||||
action::component::BeforePrepare::dispatch(self, cx);
|
||||
action::component::BeforePrepare::dispatch_by_id(self, cx);
|
||||
|
||||
// Renderiza el componente.
|
||||
let markup = match cx.theme().render_component(self, cx) {
|
||||
let markup = match action::theme::RenderComponent::dispatch(self, cx) {
|
||||
Some(html) => html,
|
||||
None => match self.prepare_component(cx) {
|
||||
PrepareMarkup::None => html! {},
|
||||
|
|
@ -69,13 +67,11 @@ impl<C: ComponentTrait> ComponentBase for C {
|
|||
};
|
||||
|
||||
// Acciones del tema después de preparar el componente.
|
||||
cx.theme().after_prepare_component(self, cx);
|
||||
action::theme::AfterPrepare::dispatch(self, cx);
|
||||
|
||||
// Acciones de los módulos después de preparar el componente.
|
||||
action::component::AfterPrepareComponent::dispatch(self, cx, None);
|
||||
if let Some(id) = self.id() {
|
||||
action::component::AfterPrepareComponent::dispatch(self, cx, Some(id));
|
||||
}
|
||||
action::component::AfterPrepare::dispatch(self, cx);
|
||||
action::component::AfterPrepare::dispatch_by_id(self, cx);
|
||||
|
||||
markup
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::core::action::Action;
|
||||
use crate::core::action::ActionBox;
|
||||
use crate::core::theme::ThemeRef;
|
||||
use crate::core::AnyBase;
|
||||
use crate::locale::L10n;
|
||||
|
|
@ -31,7 +31,7 @@ pub trait PackageTrait: AnyBase + Send + Sync {
|
|||
vec![]
|
||||
}
|
||||
|
||||
fn actions(&self) -> Vec<Action> {
|
||||
fn actions(&self) -> Vec<ActionBox> {
|
||||
actions![]
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use crate::base::component::Layout;
|
||||
use crate::core::component::{ComponentBase, ComponentTrait, Context};
|
||||
use crate::core::component::{ComponentBase, ComponentTrait};
|
||||
use crate::core::package::PackageTrait;
|
||||
use crate::html::{html, Favicon, Markup};
|
||||
use crate::locale::L10n;
|
||||
|
|
@ -26,13 +26,13 @@ pub trait ThemeTrait: PackageTrait + Send + Sync {
|
|||
fn before_prepare_body(&self, page: &mut Page) {}
|
||||
|
||||
fn prepare_body(&self, page: &mut Page) -> Markup {
|
||||
let skip_to = concat_string!("#", page.skip_to().get().unwrap_or("content".to_owned()));
|
||||
let skip_to_id = concat_string!("#", page.skip_to().get().unwrap_or("content".to_owned()));
|
||||
|
||||
html! {
|
||||
body id=[page.body_id().get()] class=[page.body_classes().get()] {
|
||||
@if let Some(skip) = L10n::l("skip_to_content").using(page.context().langid()) {
|
||||
div class="skip__to_content" {
|
||||
a href=(skip_to) { (skip) }
|
||||
a href=(skip_to_id) { (skip) }
|
||||
}
|
||||
}
|
||||
(Layout::new().render(page.context()))
|
||||
|
|
@ -80,66 +80,4 @@ pub trait ThemeTrait: PackageTrait + Send + Sync {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
#[allow(unused_variables)]
|
||||
fn before_prepare_component(
|
||||
&self,
|
||||
component: &mut dyn ComponentTrait,
|
||||
cx: &mut Context,
|
||||
) {
|
||||
/*
|
||||
Cómo usarlo:
|
||||
|
||||
match component.type_id() {
|
||||
t if t == TypeId::of::<Block>() => {
|
||||
if let Some(b) = component.downcast_mut::<Block>() {
|
||||
b.alter_title("New title");
|
||||
}
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
#[allow(unused_variables)]
|
||||
fn after_prepare_component(
|
||||
&self,
|
||||
component: &mut dyn ComponentTrait,
|
||||
cx: &mut Context,
|
||||
) {
|
||||
/*
|
||||
Cómo usarlo:
|
||||
|
||||
match component.type_id() {
|
||||
t if t == TypeId::of::<Block>() => {
|
||||
if let Some(b) = component.downcast_mut::<Block>() {
|
||||
b.alter_title("New title");
|
||||
}
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
#[allow(unused_variables)]
|
||||
fn render_component(
|
||||
&self,
|
||||
component: &dyn ComponentTrait,
|
||||
cx: &mut Context,
|
||||
) -> Option<Markup> {
|
||||
None
|
||||
/*
|
||||
Cómo usarlo:
|
||||
|
||||
match component.type_id() {
|
||||
t if t == TypeId::of::<Block>() => {
|
||||
Some(block_default(block))
|
||||
},
|
||||
_ => None,
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -168,7 +168,7 @@ impl Page {
|
|||
// Page RENDER.
|
||||
|
||||
pub fn render(&mut self) -> ResultPage<Markup, ErrorPage> {
|
||||
// Theme actions before preparing the page body.
|
||||
// Theme operations before preparing the page body.
|
||||
self.context.theme().before_prepare_body(self);
|
||||
|
||||
// Packages actions before preparing the page body.
|
||||
|
|
@ -177,7 +177,7 @@ impl Page {
|
|||
// Prepare page body.
|
||||
let body = self.context.theme().prepare_body(self);
|
||||
|
||||
// Theme actions after preparing the page body.
|
||||
// Theme operations after preparing the page body.
|
||||
self.context.theme().after_prepare_body(self);
|
||||
|
||||
// Packages actions after preparing the page body.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue