Modifica identificador por handler()
This commit is contained in:
parent
e8226daa4b
commit
68a347382d
40 changed files with 200 additions and 152 deletions
|
|
@ -1,5 +1,7 @@
|
|||
use pagetop::prelude::*;
|
||||
|
||||
pub const ADMIN_MODULE: &str = "pagetop-admin::module::admin";
|
||||
|
||||
localize!("src/locales");
|
||||
|
||||
mod summary;
|
||||
|
|
@ -7,6 +9,10 @@ mod summary;
|
|||
pub struct Admin;
|
||||
|
||||
impl ModuleTrait for Admin {
|
||||
fn handler(&self) -> &'static str {
|
||||
ADMIN_MODULE
|
||||
}
|
||||
|
||||
fn name(&self) -> String {
|
||||
l("module_name")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
use pagetop::prelude::*;
|
||||
|
||||
pub const NODE_MODULE: &str = "pagetop-node::module::node";
|
||||
|
||||
localize!("src/locales");
|
||||
|
||||
//mod entity;
|
||||
|
|
@ -8,6 +10,10 @@ mod migration;
|
|||
pub struct Node;
|
||||
|
||||
impl ModuleTrait for Node {
|
||||
fn handler(&self) -> &'static str {
|
||||
NODE_MODULE
|
||||
}
|
||||
|
||||
fn name(&self) -> String {
|
||||
l("module_name")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
use pagetop::prelude::*;
|
||||
|
||||
pub const USER_MODULE: &str = "pagetop-user::module::user";
|
||||
|
||||
localize!("src/locales");
|
||||
|
||||
mod migration;
|
||||
|
|
@ -7,6 +9,10 @@ mod migration;
|
|||
pub struct User;
|
||||
|
||||
impl ModuleTrait for User {
|
||||
fn handler(&self) -> &'static str {
|
||||
USER_MODULE
|
||||
}
|
||||
|
||||
fn name(&self) -> String {
|
||||
l("module_name")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,30 +1,26 @@
|
|||
use crate::Lazy;
|
||||
use crate::api::TypeId;
|
||||
use super::{ActionItem, ActionsHolder};
|
||||
|
||||
use std::sync::RwLock;
|
||||
use std::collections::HashMap;
|
||||
|
||||
// Registered actions.
|
||||
static ACTIONS: Lazy<RwLock<HashMap<TypeId, ActionsHolder>>> = Lazy::new(|| {
|
||||
static ACTIONS: Lazy<RwLock<HashMap<&str, ActionsHolder>>> = Lazy::new(|| {
|
||||
RwLock::new(HashMap::new())
|
||||
});
|
||||
|
||||
pub fn add_action(action: ActionItem) {
|
||||
let mut hmap = ACTIONS.write().unwrap();
|
||||
let action_id = action.type_id();
|
||||
if let Some(actions) = hmap.get_mut(&action_id) {
|
||||
let action_handler = action.handler();
|
||||
if let Some(actions) = hmap.get_mut(action_handler) {
|
||||
actions.add(action);
|
||||
} else {
|
||||
hmap.insert(action_id, ActionsHolder::new_with(action));
|
||||
hmap.insert(action_handler, ActionsHolder::new_with(action));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run_actions<B, F>(action_id: TypeId, f: F)
|
||||
where
|
||||
F: FnMut(&ActionItem) -> B
|
||||
{
|
||||
if let Some(actions) = ACTIONS.read().unwrap().get(&action_id) {
|
||||
pub fn run_actions<B, F>(action_handler: &str, f: F) where F: FnMut(&ActionItem) -> B {
|
||||
if let Some(actions) = ACTIONS.read().unwrap().get(action_handler) {
|
||||
actions.iter_map(f)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ pub use std::any::Any as AnyAction;
|
|||
pub trait ActionTrait: AnyAction + Send + Sync {
|
||||
fn new() -> Self where Self: Sized;
|
||||
|
||||
fn handler(&self) -> &'static str;
|
||||
|
||||
fn weight(&self) -> isize {
|
||||
0
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,19 +1,25 @@
|
|||
use crate::api::action::{ActionTrait, AnyAction};
|
||||
use super::{Assets, ComponentTrait};
|
||||
|
||||
pub struct ActionBeforeRenderComponent {
|
||||
pub const BEFORE_RENDER_COMPONENT_ACTION: &str = "pagetop::action::before_render_component";
|
||||
|
||||
pub struct BeforeRenderComponentAction {
|
||||
action: Option<fn(&mut dyn ComponentTrait, &mut Assets)>,
|
||||
weight: isize,
|
||||
}
|
||||
|
||||
impl ActionTrait for ActionBeforeRenderComponent {
|
||||
impl ActionTrait for BeforeRenderComponentAction {
|
||||
fn new() -> Self {
|
||||
ActionBeforeRenderComponent {
|
||||
BeforeRenderComponentAction {
|
||||
action: None,
|
||||
weight: 0,
|
||||
}
|
||||
}
|
||||
|
||||
fn handler(&self) -> &'static str {
|
||||
BEFORE_RENDER_COMPONENT_ACTION
|
||||
}
|
||||
|
||||
fn weight(&self) -> isize {
|
||||
self.weight
|
||||
}
|
||||
|
|
@ -23,7 +29,7 @@ impl ActionTrait for ActionBeforeRenderComponent {
|
|||
}
|
||||
}
|
||||
|
||||
impl ActionBeforeRenderComponent {
|
||||
impl BeforeRenderComponentAction {
|
||||
pub fn with_action(mut self, action: fn(&mut dyn ComponentTrait, &mut Assets)) -> Self {
|
||||
self.action = Some(action);
|
||||
self
|
||||
|
|
|
|||
|
|
@ -1,24 +1,18 @@
|
|||
use crate::html::{Markup, html};
|
||||
use crate::api::{TypeId, action::{action_ref, run_actions}};
|
||||
use crate::api::action::{action_ref, run_actions};
|
||||
use crate::util;
|
||||
use super::{ActionBeforeRenderComponent, Assets};
|
||||
use super::{BEFORE_RENDER_COMPONENT_ACTION, BeforeRenderComponentAction};
|
||||
use super::Assets;
|
||||
|
||||
pub use std::any::Any as AnyComponent;
|
||||
|
||||
pub trait BaseComponent {
|
||||
fn type_name(&self) -> &'static str;
|
||||
|
||||
fn single_name(&self) -> &'static str;
|
||||
|
||||
fn qualified_name(&self, last: usize) -> &'static str;
|
||||
}
|
||||
|
||||
pub trait ComponentTrait: AnyComponent + BaseComponent + Send + Sync {
|
||||
|
||||
pub trait ComponentTrait: AnyComponent + Send + Sync {
|
||||
fn new() -> Self where Self: Sized;
|
||||
|
||||
fn handler(&self) -> &'static str;
|
||||
|
||||
fn name(&self) -> String {
|
||||
self.single_name().to_owned()
|
||||
util::single_type_name::<Self>().to_owned()
|
||||
}
|
||||
|
||||
fn description(&self) -> Option<String> {
|
||||
|
|
@ -47,20 +41,6 @@ pub trait ComponentTrait: AnyComponent + BaseComponent + Send + Sync {
|
|||
fn as_mut_any(&mut self) -> &mut dyn AnyComponent;
|
||||
}
|
||||
|
||||
impl<C: ?Sized + ComponentTrait> BaseComponent for C {
|
||||
fn type_name(&self) -> &'static str {
|
||||
std::any::type_name::<Self>()
|
||||
}
|
||||
|
||||
fn single_name(&self) -> &'static str {
|
||||
util::partial_type_name(std::any::type_name::<Self>(), 1)
|
||||
}
|
||||
|
||||
fn qualified_name(&self, last: usize) -> &'static str {
|
||||
util::partial_type_name(std::any::type_name::<Self>(), last)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn component_ref<C: 'static>(component: &dyn ComponentTrait) -> &C {
|
||||
component.as_ref_any().downcast_ref::<C>().unwrap()
|
||||
}
|
||||
|
|
@ -75,8 +55,8 @@ pub fn render_component(component: &mut dyn ComponentTrait, assets: &mut Assets)
|
|||
|
||||
// Acciones de los módulos antes de renderizar el componente.
|
||||
run_actions(
|
||||
TypeId::of::<ActionBeforeRenderComponent>(),
|
||||
|a| action_ref::<ActionBeforeRenderComponent>(&**a).run(component, assets)
|
||||
BEFORE_RENDER_COMPONENT_ACTION,
|
||||
|a| action_ref::<BeforeRenderComponentAction>(&**a).run(component, assets)
|
||||
);
|
||||
|
||||
// Acciones del tema antes de renderizar el componente.
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
mod action;
|
||||
pub use action::ActionBeforeRenderComponent;
|
||||
pub use action::{
|
||||
BEFORE_RENDER_COMPONENT_ACTION,
|
||||
BeforeRenderComponentAction,
|
||||
};
|
||||
|
||||
mod assets;
|
||||
pub use assets::{
|
||||
|
|
@ -12,7 +15,6 @@ pub use assets::{
|
|||
mod definition;
|
||||
pub use definition::{
|
||||
AnyComponent,
|
||||
BaseComponent,
|
||||
ComponentTrait,
|
||||
component_ref,
|
||||
component_mut,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
pub use std::any::TypeId;
|
||||
|
||||
pub mod action; // API to define functions that alter the behavior of PageTop core.
|
||||
pub mod component; // API para crear nuevos componentes.
|
||||
pub mod module; // API para añadir módulos con nuevas funcionalidades.
|
||||
|
|
|
|||
|
|
@ -18,9 +18,9 @@ pub fn register_module(module: &'static dyn ModuleTrait) {
|
|||
}
|
||||
|
||||
fn add_to(list: &mut Vec<&dyn ModuleTrait>, module: &'static dyn ModuleTrait) {
|
||||
if !MODULES.read().unwrap().iter().any(|m| m.type_name() == module.type_name()) {
|
||||
if !list.iter().any(|m| m.type_name() == module.type_name()) {
|
||||
trace::debug!("Registering \"{}\" module", module.single_name());
|
||||
if !MODULES.read().unwrap().iter().any(|m| m.handler() == module.handler()) {
|
||||
if !list.iter().any(|m| m.handler() == module.handler()) {
|
||||
trace::debug!("Register module: \"{}\"", module.name());
|
||||
list.push(module);
|
||||
|
||||
let mut dependencies = module.dependencies();
|
||||
|
|
|
|||
|
|
@ -1,21 +1,16 @@
|
|||
use crate::{app, util};
|
||||
use crate::app;
|
||||
use crate::api::action::ActionItem;
|
||||
use crate::util;
|
||||
|
||||
#[cfg(any(feature = "mysql", feature = "postgres", feature = "sqlite"))]
|
||||
use crate::db::MigrationItem;
|
||||
|
||||
pub trait BaseModule {
|
||||
fn type_name(&self) -> &'static str;
|
||||
|
||||
fn single_name(&self) -> &'static str;
|
||||
|
||||
fn qualified_name(&self, last: usize) -> &'static str;
|
||||
}
|
||||
|
||||
/// Los módulos deben implementar este *trait*.
|
||||
pub trait ModuleTrait: BaseModule + Send + Sync {
|
||||
pub trait ModuleTrait: Send + Sync {
|
||||
fn handler(&self) -> &'static str;
|
||||
|
||||
fn name(&self) -> String {
|
||||
self.single_name().to_owned()
|
||||
util::single_type_name::<Self>().to_owned()
|
||||
}
|
||||
|
||||
fn description(&self) -> Option<String> {
|
||||
|
|
@ -40,17 +35,3 @@ pub trait ModuleTrait: BaseModule + Send + Sync {
|
|||
vec![]
|
||||
}
|
||||
}
|
||||
|
||||
impl<M: ?Sized + ModuleTrait> BaseModule for M {
|
||||
fn type_name(&self) -> &'static str {
|
||||
std::any::type_name::<Self>()
|
||||
}
|
||||
|
||||
fn single_name(&self) -> &'static str {
|
||||
util::partial_type_name(std::any::type_name::<Self>(), 1)
|
||||
}
|
||||
|
||||
fn qualified_name(&self, last: usize) -> &'static str {
|
||||
util::partial_type_name(std::any::type_name::<Self>(), last)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,5 @@
|
|||
mod definition;
|
||||
pub use definition::{
|
||||
BaseModule,
|
||||
ModuleTrait,
|
||||
};
|
||||
pub use definition::ModuleTrait;
|
||||
|
||||
pub(crate) mod all;
|
||||
pub use all::{
|
||||
register_module,
|
||||
};
|
||||
pub use all::register_module;
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@ static THEMES: Lazy<RwLock<Vec<&dyn ThemeTrait>>> = Lazy::new(|| {
|
|||
|
||||
pub fn register_theme(theme: &'static dyn ThemeTrait) {
|
||||
let mut themes = THEMES.write().unwrap();
|
||||
if !themes.iter().any(|t| t.name() == theme.name()) {
|
||||
trace::debug!("Registering \"{}\" theme", theme.single_name());
|
||||
if !themes.iter().any(|t| t.handler() == theme.handler()) {
|
||||
trace::debug!("Register theme: \"{}\"", theme.name());
|
||||
themes.push(theme);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,18 +6,12 @@ use crate::response::page::Page;
|
|||
use crate::base::component::Chunck;
|
||||
use crate::util;
|
||||
|
||||
pub trait BaseTheme {
|
||||
fn type_name(&self) -> &'static str;
|
||||
|
||||
fn single_name(&self) -> &'static str;
|
||||
|
||||
fn qualified_name(&self, last: usize) -> &'static str;
|
||||
}
|
||||
|
||||
/// Los temas deben implementar este "trait".
|
||||
pub trait ThemeTrait: BaseTheme + Send + Sync {
|
||||
pub trait ThemeTrait: Send + Sync {
|
||||
fn handler(&self) -> &'static str;
|
||||
|
||||
fn name(&self) -> String {
|
||||
self.single_name().to_owned()
|
||||
util::single_type_name::<Self>().to_owned()
|
||||
}
|
||||
|
||||
fn description(&self) -> Option<String> {
|
||||
|
|
@ -93,8 +87,8 @@ pub trait ThemeTrait: BaseTheme + Send + Sync {
|
|||
/*
|
||||
Cómo usarlo:
|
||||
|
||||
match component.single_name() {
|
||||
"Block" => {
|
||||
match component.handler() {
|
||||
BLOCK_COMPONENT => {
|
||||
let block = component_mut::<Block>(component);
|
||||
block.alter_title("New title");
|
||||
},
|
||||
|
|
@ -113,8 +107,8 @@ pub trait ThemeTrait: BaseTheme + Send + Sync {
|
|||
/*
|
||||
Cómo usarlo:
|
||||
|
||||
match component.single_name() {
|
||||
"Block" => {
|
||||
match component.handler() {
|
||||
BLOCK_COMPONENT => {
|
||||
let block = component_ref::<Block>(component);
|
||||
match block.template() {
|
||||
"default" => Some(block_default(block)),
|
||||
|
|
@ -137,17 +131,3 @@ pub trait ThemeTrait: BaseTheme + Send + Sync {
|
|||
.render()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: ?Sized + ThemeTrait> BaseTheme for T {
|
||||
fn type_name(&self) -> &'static str {
|
||||
std::any::type_name::<Self>()
|
||||
}
|
||||
|
||||
fn single_name(&self) -> &'static str {
|
||||
util::partial_type_name(std::any::type_name::<Self>(), 1)
|
||||
}
|
||||
|
||||
fn qualified_name(&self, last: usize) -> &'static str {
|
||||
util::partial_type_name(std::any::type_name::<Self>(), last)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,5 @@
|
|||
mod definition;
|
||||
pub use definition::{
|
||||
BaseTheme,
|
||||
ThemeTrait,
|
||||
};
|
||||
pub use definition::ThemeTrait;
|
||||
|
||||
pub(crate) mod all;
|
||||
pub use all::{
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use crate::prelude::*;
|
||||
|
||||
pub const TYPENAME_BLOCK: &str = "pagetop::base::component::block::Block";
|
||||
pub const BLOCK_COMPONENT: &str = "pagetop::component::block";
|
||||
|
||||
pub struct Block {
|
||||
renderable: fn() -> bool,
|
||||
|
|
@ -25,6 +25,10 @@ impl ComponentTrait for Block {
|
|||
}
|
||||
}
|
||||
|
||||
fn handler(&self) -> &'static str {
|
||||
BLOCK_COMPONENT
|
||||
}
|
||||
|
||||
fn is_renderable(&self) -> bool {
|
||||
(self.renderable)()
|
||||
}
|
||||
|
|
@ -34,7 +38,7 @@ impl ComponentTrait for Block {
|
|||
}
|
||||
|
||||
fn default_render(&self, assets: &mut Assets) -> Markup {
|
||||
let id = assets.serial_id(self.single_name(), self.id());
|
||||
let id = assets.serial_id("block", self.id());
|
||||
html! {
|
||||
div id=(id) class=[self.classes()] {
|
||||
@match self.title() {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use crate::prelude::*;
|
||||
|
||||
pub const TYPENAME_CHUNCK: &str = "pagetop::base::component::chunck::Chunck";
|
||||
pub const CHUNCK_COMPONENT: &str = "pagetop::component::chunck";
|
||||
|
||||
pub struct Chunck {
|
||||
renderable: fn() -> bool,
|
||||
|
|
@ -19,6 +19,10 @@ impl ComponentTrait for Chunck {
|
|||
}
|
||||
}
|
||||
|
||||
fn handler(&self) -> &'static str {
|
||||
CHUNCK_COMPONENT
|
||||
}
|
||||
|
||||
fn is_renderable(&self) -> bool {
|
||||
(self.renderable)()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use crate::prelude::*;
|
||||
|
||||
pub const TYPENAME_CONTAINER: &str = "pagetop::base::component::container::Container";
|
||||
pub const CONTAINER_COMPONENT: &str = "pagetop::component::container";
|
||||
|
||||
pub enum ContainerType { Header, Footer, Main, Section, Wrapper }
|
||||
|
||||
|
|
@ -29,6 +29,10 @@ impl ComponentTrait for Container {
|
|||
}
|
||||
}
|
||||
|
||||
fn handler(&self) -> &'static str {
|
||||
CONTAINER_COMPONENT
|
||||
}
|
||||
|
||||
fn is_renderable(&self) -> bool {
|
||||
(self.renderable)()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use crate::prelude::*;
|
||||
|
||||
pub const TYPENAME_BUTTON: &str = "pagetop::base::component::form::button::Button";
|
||||
pub const BUTTON_COMPONENT: &str = "pagetop::component::form::button";
|
||||
|
||||
pub enum ButtonType {Button, Reset, Submit}
|
||||
|
||||
|
|
@ -32,6 +32,10 @@ impl ComponentTrait for Button {
|
|||
.with_classes("form-button", ClassesOp::AddFirst)
|
||||
}
|
||||
|
||||
fn handler(&self) -> &'static str {
|
||||
BUTTON_COMPONENT
|
||||
}
|
||||
|
||||
fn is_renderable(&self) -> bool {
|
||||
(self.renderable)()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use crate::prelude::*;
|
||||
|
||||
pub const TYPENAME_DATE: &str = "pagetop::base::component::form::date::Date";
|
||||
pub const DATE_COMPONENT: &str = "pagetop::component::form::date";
|
||||
|
||||
pub struct Date {
|
||||
renderable : fn() -> bool,
|
||||
|
|
@ -40,6 +40,10 @@ impl ComponentTrait for Date {
|
|||
.with_classes("form-type-date", ClassesOp::AddFirst)
|
||||
}
|
||||
|
||||
fn handler(&self) -> &'static str {
|
||||
DATE_COMPONENT
|
||||
}
|
||||
|
||||
fn is_renderable(&self) -> bool {
|
||||
(self.renderable)()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use crate::prelude::*;
|
||||
|
||||
pub const TYPENAME_FORM: &str = "pagetop::base::component::form::form::Form";
|
||||
pub const FORM_COMPONENT: &str = "pagetop::component::form";
|
||||
|
||||
pub enum FormMethod {Get, Post}
|
||||
|
||||
|
|
@ -31,6 +31,10 @@ impl ComponentTrait for Form {
|
|||
}
|
||||
}
|
||||
|
||||
fn handler(&self) -> &'static str {
|
||||
FORM_COMPONENT
|
||||
}
|
||||
|
||||
fn is_renderable(&self) -> bool {
|
||||
(self.renderable)()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use crate::prelude::*;
|
||||
|
||||
pub const TYPENAME_HIDDEN: &str = "pagetop::base::component::form::hidden::Hidden";
|
||||
pub const HIDDEN_COMPONENT: &str = "pagetop::component::form::hidden";
|
||||
|
||||
pub struct Hidden {
|
||||
weight: isize,
|
||||
|
|
@ -17,6 +17,10 @@ impl ComponentTrait for Hidden {
|
|||
}
|
||||
}
|
||||
|
||||
fn handler(&self) -> &'static str {
|
||||
HIDDEN_COMPONENT
|
||||
}
|
||||
|
||||
fn weight(&self) -> isize {
|
||||
self.weight
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use crate::prelude::*;
|
||||
|
||||
pub const TYPENAME_INPUT: &str = "pagetop::base::component::form::input::Input";
|
||||
pub const INPUT_COMPONENT: &str = "pagetop::component::form::input";
|
||||
|
||||
pub enum InputType {Email, Password, Search, Telephone, Textfield, Url}
|
||||
|
||||
|
|
@ -50,6 +50,10 @@ impl ComponentTrait for Input {
|
|||
.with_classes("form-type-textfield", ClassesOp::AddFirst)
|
||||
}
|
||||
|
||||
fn handler(&self) -> &'static str {
|
||||
INPUT_COMPONENT
|
||||
}
|
||||
|
||||
fn is_renderable(&self) -> bool {
|
||||
(self.renderable)()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +1,21 @@
|
|||
mod form;
|
||||
pub use form::{
|
||||
TYPENAME_FORM, Form, FormMethod
|
||||
FORM_COMPONENT, Form, FormMethod
|
||||
};
|
||||
|
||||
mod input;
|
||||
pub use input::{
|
||||
TYPENAME_INPUT, Input, InputType
|
||||
INPUT_COMPONENT, Input, InputType
|
||||
};
|
||||
mod hidden;
|
||||
pub use hidden::{
|
||||
TYPENAME_HIDDEN, Hidden
|
||||
HIDDEN_COMPONENT, Hidden
|
||||
};
|
||||
mod date;
|
||||
pub use date::{
|
||||
TYPENAME_DATE, Date
|
||||
DATE_COMPONENT, Date
|
||||
};
|
||||
mod button;
|
||||
pub use button::{
|
||||
TYPENAME_BUTTON, Button, ButtonType
|
||||
BUTTON_COMPONENT, Button, ButtonType
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use crate::prelude::*;
|
||||
|
||||
pub const TYPENAME_COLUMN: &str = "pagetop::base::component::grid::column::Column";
|
||||
pub const COLUMN_COMPONENT: &str = "pagetop::component::grid::column";
|
||||
|
||||
pub struct Column {
|
||||
renderable: fn() -> bool,
|
||||
|
|
@ -23,6 +23,10 @@ impl ComponentTrait for Column {
|
|||
}
|
||||
}
|
||||
|
||||
fn handler(&self) -> &'static str {
|
||||
COLUMN_COMPONENT
|
||||
}
|
||||
|
||||
fn is_renderable(&self) -> bool {
|
||||
(self.renderable)()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
mod row;
|
||||
pub use row::{
|
||||
TYPENAME_ROW, Row
|
||||
ROW_COMPONENT, Row
|
||||
};
|
||||
mod column;
|
||||
pub use column::{
|
||||
TYPENAME_COLUMN, Column
|
||||
COLUMN_COMPONENT, Column
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use crate::prelude::*;
|
||||
|
||||
pub const TYPENAME_ROW: &str = "pagetop::base::component::grid::row::Row";
|
||||
pub const ROW_COMPONENT: &str = "pagetop::component::grid::row";
|
||||
|
||||
pub struct Row {
|
||||
renderable: fn() -> bool,
|
||||
|
|
@ -23,6 +23,10 @@ impl ComponentTrait for Row {
|
|||
}
|
||||
}
|
||||
|
||||
fn handler(&self) -> &'static str {
|
||||
ROW_COMPONENT
|
||||
}
|
||||
|
||||
fn is_renderable(&self) -> bool {
|
||||
(self.renderable)()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use crate::prelude::*;
|
||||
|
||||
pub const TYPENAME_IMAGE: &str = "pagetop::base::component::image::Image";
|
||||
pub const IMAGE_COMPONENT: &str = "pagetop::component::image";
|
||||
|
||||
pub struct Image {
|
||||
renderable: fn() -> bool,
|
||||
|
|
@ -23,6 +23,10 @@ impl ComponentTrait for Image {
|
|||
}
|
||||
}
|
||||
|
||||
fn handler(&self) -> &'static str {
|
||||
IMAGE_COMPONENT
|
||||
}
|
||||
|
||||
fn is_renderable(&self) -> bool {
|
||||
(self.renderable)()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use crate::prelude::*;
|
||||
|
||||
pub const TYPENAME_MENU: &str = "pagetop::base::component::menu::Menu";
|
||||
pub const TYPENAME_MENUITEM: &str = "pagetop::base::component::menu::MenuItem";
|
||||
pub const MENU_COMPONENT: &str = "pagetop::component::menu";
|
||||
pub const MENUITEM_COMPONENT: &str = "pagetop::component::menu";
|
||||
|
||||
pub enum MenuItemType {
|
||||
Label(String),
|
||||
|
|
@ -30,6 +30,10 @@ impl ComponentTrait for MenuItem {
|
|||
}
|
||||
}
|
||||
|
||||
fn handler(&self) -> &'static str {
|
||||
MENUITEM_COMPONENT
|
||||
}
|
||||
|
||||
fn is_renderable(&self) -> bool {
|
||||
(self.renderable)()
|
||||
}
|
||||
|
|
@ -190,6 +194,10 @@ impl ComponentTrait for Menu {
|
|||
}
|
||||
}
|
||||
|
||||
fn handler(&self) -> &'static str {
|
||||
MENU_COMPONENT
|
||||
}
|
||||
|
||||
fn is_renderable(&self) -> bool {
|
||||
(self.renderable)()
|
||||
}
|
||||
|
|
@ -211,7 +219,7 @@ impl ComponentTrait for Menu {
|
|||
))
|
||||
.add_jquery();
|
||||
|
||||
let id = assets.serial_id(self.single_name(), self.id());
|
||||
let id = assets.serial_id("menu", self.id());
|
||||
html! {
|
||||
ul id=(id) class=[self.classes()] {
|
||||
(self.items().render(assets))
|
||||
|
|
|
|||
|
|
@ -1,28 +1,28 @@
|
|||
mod container;
|
||||
pub use container::{
|
||||
TYPENAME_CONTAINER, Container, ContainerType
|
||||
CONTAINER_COMPONENT, Container, ContainerType
|
||||
};
|
||||
|
||||
pub mod grid;
|
||||
|
||||
mod chunck;
|
||||
pub use chunck::{
|
||||
TYPENAME_CHUNCK, Chunck
|
||||
CHUNCK_COMPONENT, Chunck
|
||||
};
|
||||
mod block;
|
||||
pub use block::{
|
||||
TYPENAME_BLOCK, Block
|
||||
BLOCK_COMPONENT, Block
|
||||
};
|
||||
mod image;
|
||||
pub use image::{
|
||||
TYPENAME_IMAGE, Image
|
||||
IMAGE_COMPONENT, Image
|
||||
};
|
||||
mod menu;
|
||||
pub use menu::{
|
||||
TYPENAME_MENU, TYPENAME_MENUITEM, Menu, MenuItem, MenuItemType
|
||||
MENU_COMPONENT, MENUITEM_COMPONENT, Menu, MenuItem, MenuItemType
|
||||
};
|
||||
|
||||
pub mod form;
|
||||
pub use form::{
|
||||
TYPENAME_FORM, Form, FormMethod
|
||||
FORM_COMPONENT, Form, FormMethod
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,10 +1,16 @@
|
|||
use crate::prelude::*;
|
||||
|
||||
pub const DEMOPAGE_MODULE: &str = "pagetop::module::demopage";
|
||||
|
||||
localize!("src/base/module/demopage/locales");
|
||||
|
||||
pub struct Demopage;
|
||||
|
||||
impl ModuleTrait for Demopage {
|
||||
fn handler(&self) -> &'static str {
|
||||
DEMOPAGE_MODULE
|
||||
}
|
||||
|
||||
fn name(&self) -> String {
|
||||
l("module_name")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,16 @@
|
|||
use crate::prelude::*;
|
||||
|
||||
pub const ALINER_THEME: &str = "pagetop::theme::aliner";
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/aliner.rs"));
|
||||
|
||||
pub struct Aliner;
|
||||
|
||||
impl ThemeTrait for Aliner {
|
||||
fn handler(&self) -> &'static str {
|
||||
ALINER_THEME
|
||||
}
|
||||
|
||||
fn configure_theme(&self, cfg: &mut app::web::ServiceConfig) {
|
||||
theme_static_files!(cfg, "/aliner");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
use crate::prelude::*;
|
||||
|
||||
pub const BOOTSIER_THEME: &str = "pagetop::theme::bootsier";
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/bootsier.rs"));
|
||||
|
||||
localize!("src/base/theme/bootsier/locales");
|
||||
|
|
@ -7,6 +9,10 @@ localize!("src/base/theme/bootsier/locales");
|
|||
pub struct Bootsier;
|
||||
|
||||
impl ThemeTrait for Bootsier {
|
||||
fn handler(&self) -> &'static str {
|
||||
BOOTSIER_THEME
|
||||
}
|
||||
|
||||
fn configure_theme(&self, cfg: &mut app::web::ServiceConfig) {
|
||||
theme_static_files!(cfg, "/bootsier");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,16 @@
|
|||
use crate::prelude::*;
|
||||
|
||||
pub const BULMIX_THEME: &str = "pagetop::theme::bulmix";
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/bulmix.rs"));
|
||||
|
||||
pub struct Bulmix;
|
||||
|
||||
impl ThemeTrait for Bulmix {
|
||||
fn handler(&self) -> &'static str {
|
||||
BULMIX_THEME
|
||||
}
|
||||
|
||||
fn configure_theme(&self, cfg: &mut app::web::ServiceConfig) {
|
||||
theme_static_files!(cfg, "/bulmix");
|
||||
}
|
||||
|
|
@ -29,12 +35,12 @@ impl ThemeTrait for Bulmix {
|
|||
component: &mut dyn ComponentTrait,
|
||||
_assets: &mut Assets
|
||||
) {
|
||||
match component.type_name() {
|
||||
grid::TYPENAME_ROW => {
|
||||
match component.handler() {
|
||||
grid::ROW_COMPONENT => {
|
||||
let row = component_mut::<grid::Row>(component);
|
||||
row.alter_classes("columns", ClassesOp::SetDefault);
|
||||
},
|
||||
grid::TYPENAME_COLUMN => {
|
||||
grid::COLUMN_COMPONENT => {
|
||||
let col = component_mut::<grid::Column>(component);
|
||||
col.alter_classes("column", ClassesOp::SetDefault);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,6 +1,11 @@
|
|||
use crate::prelude::*;
|
||||
|
||||
pub const MINIMAL_THEME: &str = "pagetop::theme::minimal";
|
||||
|
||||
pub struct Minimal;
|
||||
|
||||
impl ThemeTrait for Minimal {
|
||||
fn handler(&self) -> &'static str {
|
||||
MINIMAL_THEME
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ pub use crate::{
|
|||
};
|
||||
|
||||
pub use crate::{action_item, api::{
|
||||
TypeId,
|
||||
action::*,
|
||||
component::*,
|
||||
module::*,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
use crate::api::action::{ActionTrait, AnyAction};
|
||||
use super::Page;
|
||||
|
||||
pub const BEFORE_RENDER_PAGE_ACTION: &str = "pagetop::action::before_render_page";
|
||||
|
||||
pub struct ActionBeforeRenderPage {
|
||||
action: Option<fn(&mut Page)>,
|
||||
weight: isize,
|
||||
|
|
@ -14,6 +16,10 @@ impl ActionTrait for ActionBeforeRenderPage {
|
|||
}
|
||||
}
|
||||
|
||||
fn handler(&self) -> &'static str {
|
||||
BEFORE_RENDER_PAGE_ACTION
|
||||
}
|
||||
|
||||
fn weight(&self) -> isize {
|
||||
self.weight
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
mod action;
|
||||
pub use action::ActionBeforeRenderPage;
|
||||
pub use action::{
|
||||
BEFORE_RENDER_PAGE_ACTION,
|
||||
ActionBeforeRenderPage,
|
||||
};
|
||||
|
||||
mod page;
|
||||
pub use page::Page;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
use crate::{Lazy, app, trace};
|
||||
use crate::config::SETTINGS;
|
||||
use crate::html::*;
|
||||
use crate::api::{TypeId, action::{action_ref, run_actions}};
|
||||
use crate::api::action::{action_ref, run_actions};
|
||||
use crate::api::component::*;
|
||||
use super::ActionBeforeRenderPage;
|
||||
use super::{BEFORE_RENDER_PAGE_ACTION, ActionBeforeRenderPage};
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
|
|
@ -152,7 +152,7 @@ impl<'a> Page<'a> {
|
|||
pub fn render(&mut self) -> app::Result<Markup> {
|
||||
// Acciones de los módulos antes de renderizar la página.
|
||||
run_actions(
|
||||
TypeId::of::<ActionBeforeRenderPage>(),
|
||||
BEFORE_RENDER_PAGE_ACTION,
|
||||
|a| action_ref::<ActionBeforeRenderPage>(&**a).run(self)
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -46,3 +46,7 @@ pub fn partial_type_name(type_name: &'static str, last: usize) -> &'static str {
|
|||
}
|
||||
&type_name[(positions[last - 1].0 + 2)..]
|
||||
}
|
||||
|
||||
pub fn single_type_name<T: ?Sized>() -> &'static str {
|
||||
partial_type_name(std::any::type_name::<T>(), 1)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue