🚚 Define acción base "before_render_component"
This commit is contained in:
parent
d8812433f1
commit
cb04a29388
12 changed files with 81 additions and 81 deletions
|
|
@ -153,7 +153,7 @@ impl MegaMenuItem {
|
||||||
|
|
||||||
define_handle!(COMPONENT_MEGAMENU);
|
define_handle!(COMPONENT_MEGAMENU);
|
||||||
|
|
||||||
action_before_render_component!(ACTION_BEFORE_RENDER_MENU, MegaMenu);
|
action_before_render_component!(ACTION_BEFORE_RENDER_MENU for MegaMenu);
|
||||||
|
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ use pagetop::prelude::*;
|
||||||
|
|
||||||
define_handle!(COMPONENT_CONTAINER);
|
define_handle!(COMPONENT_CONTAINER);
|
||||||
|
|
||||||
action_before_render_component!(ACTION_BEFORE_RENDER_CONTAINER, Container);
|
action_before_render_component!(ACTION_BEFORE_RENDER_CONTAINER for Container);
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub enum ContainerType {
|
pub enum ContainerType {
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ use pagetop::prelude::*;
|
||||||
|
|
||||||
define_handle!(COMPONENT_FORM);
|
define_handle!(COMPONENT_FORM);
|
||||||
|
|
||||||
action_before_render_component!(ACTION_BEFORE_RENDER_FORM, Form);
|
action_before_render_component!(ACTION_BEFORE_RENDER_FORM for Form);
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub enum FormMethod {
|
pub enum FormMethod {
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ use pagetop::prelude::*;
|
||||||
|
|
||||||
define_handle!(COMPONENT_COLUMN);
|
define_handle!(COMPONENT_COLUMN);
|
||||||
|
|
||||||
action_before_render_component!(ACTION_BEFORE_RENDER_COLUMN, Column);
|
action_before_render_component!(ACTION_BEFORE_RENDER_COLUMN for Column);
|
||||||
|
|
||||||
const SIZE__DEFAULT: &str = "col-md";
|
const SIZE__DEFAULT: &str = "col-md";
|
||||||
const SIZE__1_OF_12: &str = "col-md-1";
|
const SIZE__1_OF_12: &str = "col-md-1";
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ use crate::component::grid;
|
||||||
|
|
||||||
define_handle!(COMPONENT_ROW);
|
define_handle!(COMPONENT_ROW);
|
||||||
|
|
||||||
action_before_render_component!(ACTION_BEFORE_RENDER_ROW, Row);
|
action_before_render_component!(ACTION_BEFORE_RENDER_ROW for Row);
|
||||||
|
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
pub mod action;
|
||||||
|
|
||||||
pub mod component;
|
pub mod component;
|
||||||
|
|
||||||
pub mod theme;
|
pub mod theme;
|
||||||
|
|
|
||||||
1
pagetop/src/base/action.rs
Normal file
1
pagetop/src/base/action.rs
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
mod before_render_component;
|
||||||
64
pagetop/src/base/action/before_render_component.rs
Normal file
64
pagetop/src/base/action/before_render_component.rs
Normal file
|
|
@ -0,0 +1,64 @@
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! action_before_render_component {
|
||||||
|
( $ACTION_HANDLE:ident for $Component:ty ) => {
|
||||||
|
$crate::paste! {
|
||||||
|
$crate::define_handle!($ACTION_HANDLE);
|
||||||
|
|
||||||
|
type Action = fn(&$Component, &mut RenderContext);
|
||||||
|
|
||||||
|
pub struct [< BeforeRender $Component >] {
|
||||||
|
action: Option<Action>,
|
||||||
|
weight: isize,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ActionTrait for [< BeforeRender $Component >] {
|
||||||
|
fn new() -> Self {
|
||||||
|
[< BeforeRender $Component >] {
|
||||||
|
action: None,
|
||||||
|
weight: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle(&self) -> Handle {
|
||||||
|
$ACTION_HANDLE
|
||||||
|
}
|
||||||
|
|
||||||
|
fn weight(&self) -> isize {
|
||||||
|
self.weight
|
||||||
|
}
|
||||||
|
|
||||||
|
fn as_ref_any(&self) -> &dyn AnyAction {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl [< BeforeRender $Component >] {
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub fn with_action(mut self, action: Action) -> Self {
|
||||||
|
self.action = Some(action);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub fn with_weight(mut self, weight: isize) -> Self {
|
||||||
|
self.weight = weight;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn run(&self, component: &mut $Component, rcx: &mut RenderContext) {
|
||||||
|
if let Some(action) = self.action {
|
||||||
|
action(component, rcx)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn before_render_inline(component: &mut $Component, rcx: &mut RenderContext) {
|
||||||
|
run_actions($ACTION_HANDLE, |action|
|
||||||
|
action_ref::<[< BeforeRender $Component >]>(&**action)
|
||||||
|
.run(component, rcx)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
@ -2,7 +2,7 @@ use crate::prelude::*;
|
||||||
|
|
||||||
define_handle!(COMPONENT_BLOCK);
|
define_handle!(COMPONENT_BLOCK);
|
||||||
|
|
||||||
action_before_render_component!(ACTION_BEFORE_RENDER_BLOCK, Block);
|
action_before_render_component!(ACTION_BEFORE_RENDER_BLOCK for Block);
|
||||||
|
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
|
|
||||||
|
|
@ -11,20 +11,18 @@ pub enum L10nOp {
|
||||||
Escaped(&'static str, &'static Locales),
|
Escaped(&'static str, &'static Locales),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for L10nOp {
|
||||||
|
fn default() -> Self {
|
||||||
|
L10nOp::None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
pub struct L10n {
|
pub struct L10n {
|
||||||
op: L10nOp,
|
op: L10nOp,
|
||||||
args: HashMap<&'static str, String>,
|
args: HashMap<&'static str, String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for L10n {
|
|
||||||
fn default() -> Self {
|
|
||||||
L10n {
|
|
||||||
op: L10nOp::None,
|
|
||||||
args: HashMap::new(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ComponentTrait for L10n {
|
impl ComponentTrait for L10n {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
L10n::default()
|
L10n::default()
|
||||||
|
|
|
||||||
|
|
@ -74,68 +74,3 @@ pub fn component_ref<C: 'static>(component: &dyn ComponentTrait) -> &C {
|
||||||
pub fn component_mut<C: 'static>(component: &mut dyn ComponentTrait) -> &mut C {
|
pub fn component_mut<C: 'static>(component: &mut dyn ComponentTrait) -> &mut C {
|
||||||
component.as_mut_any().downcast_mut::<C>().unwrap()
|
component.as_mut_any().downcast_mut::<C>().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[macro_export]
|
|
||||||
macro_rules! action_before_render_component {
|
|
||||||
( $ACTION_HANDLE:ident, $Component:ty ) => {
|
|
||||||
$crate::paste! {
|
|
||||||
$crate::define_handle!($ACTION_HANDLE);
|
|
||||||
|
|
||||||
type Action = fn(&$Component, &mut RenderContext);
|
|
||||||
|
|
||||||
pub struct [< BeforeRender $Component >] {
|
|
||||||
action: Option<Action>,
|
|
||||||
weight: isize,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ActionTrait for [< BeforeRender $Component >] {
|
|
||||||
fn new() -> Self {
|
|
||||||
[< BeforeRender $Component >] {
|
|
||||||
action: None,
|
|
||||||
weight: 0,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn handle(&self) -> Handle {
|
|
||||||
$ACTION_HANDLE
|
|
||||||
}
|
|
||||||
|
|
||||||
fn weight(&self) -> isize {
|
|
||||||
self.weight
|
|
||||||
}
|
|
||||||
|
|
||||||
fn as_ref_any(&self) -> &dyn AnyAction {
|
|
||||||
self
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl [< BeforeRender $Component >] {
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn with_action(mut self, action: Action) -> Self {
|
|
||||||
self.action = Some(action);
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn with_weight(mut self, weight: isize) -> Self {
|
|
||||||
self.weight = weight;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn run(&self, component: &mut $Component, rcx: &mut RenderContext) {
|
|
||||||
if let Some(action) = self.action {
|
|
||||||
action(component, rcx)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline(always)]
|
|
||||||
pub fn before_render_inline(component: &mut $Component, rcx: &mut RenderContext) {
|
|
||||||
run_actions($ACTION_HANDLE, |action|
|
|
||||||
action_ref::<[< BeforeRender $Component >]>(&**action)
|
|
||||||
.run(component, rcx)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,7 @@
|
||||||
//!
|
//!
|
||||||
//! define_locale!(LOCALE_SAMPLE, "static/locales");
|
//! define_locale!(LOCALE_SAMPLE, "static/locales");
|
||||||
//! ```
|
//! ```
|
||||||
//! Y utiliza el componente [L10n](crate::core::component::L10n) para incluir, en respuestas a las
|
//! Y utiliza el componente [L10n](crate::base::component::L10n) para incluir, en respuestas a las
|
||||||
//! peticiones web, textos y contenidos opcionalmente traducibles según el contexto de renderizado.
|
//! peticiones web, textos y contenidos opcionalmente traducibles según el contexto de renderizado.
|
||||||
|
|
||||||
use crate::{args, config, trace, LazyStatic};
|
use crate::{args, config, trace, LazyStatic};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue