✨ Añade identificador en componentes
This commit is contained in:
parent
cb04a29388
commit
f0e4aea672
18 changed files with 77 additions and 90 deletions
|
|
@ -6,14 +6,14 @@ macro_rules! action_before_render_component {
|
|||
|
||||
type Action = fn(&$Component, &mut RenderContext);
|
||||
|
||||
pub struct [< BeforeRender $Component >] {
|
||||
pub struct [<BeforeRender $Component>] {
|
||||
action: Option<Action>,
|
||||
weight: isize,
|
||||
}
|
||||
|
||||
impl ActionTrait for [< BeforeRender $Component >] {
|
||||
impl ActionTrait for [<BeforeRender $Component>] {
|
||||
fn new() -> Self {
|
||||
[< BeforeRender $Component >] {
|
||||
[<BeforeRender $Component>] {
|
||||
action: None,
|
||||
weight: 0,
|
||||
}
|
||||
|
|
@ -32,7 +32,7 @@ macro_rules! action_before_render_component {
|
|||
}
|
||||
}
|
||||
|
||||
impl [< BeforeRender $Component >] {
|
||||
impl [<BeforeRender $Component>] {
|
||||
#[allow(dead_code)]
|
||||
pub fn with_action(mut self, action: Action) -> Self {
|
||||
self.action = Some(action);
|
||||
|
|
@ -55,7 +55,7 @@ macro_rules! action_before_render_component {
|
|||
#[inline(always)]
|
||||
pub fn before_render_inline(component: &mut $Component, rcx: &mut RenderContext) {
|
||||
run_actions($ACTION_HANDLE, |action|
|
||||
action_ref::<[< BeforeRender $Component >]>(&**action)
|
||||
action_ref::<[<BeforeRender $Component>]>(&**action)
|
||||
.run(component, rcx)
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,10 @@ impl ComponentTrait for Block {
|
|||
COMPONENT_BLOCK
|
||||
}
|
||||
|
||||
fn id(&self) -> Option<String> {
|
||||
self.id.get()
|
||||
}
|
||||
|
||||
fn weight(&self) -> isize {
|
||||
self.weight
|
||||
}
|
||||
|
|
@ -107,10 +111,6 @@ impl Block {
|
|||
|
||||
// Block GETTERS.
|
||||
|
||||
pub fn id(&self) -> &IdentifierValue {
|
||||
&self.id
|
||||
}
|
||||
|
||||
pub fn classes(&self) -> &Classes {
|
||||
&self.classes
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use crate::core::theme::{all::theme_by_single_name, ThemeStaticRef};
|
||||
use crate::html::{html, Assets, IdentifierValue, JavaScript, Markup, StyleSheet};
|
||||
use crate::html::{html, Assets, JavaScript, Markup, StyleSheet};
|
||||
use crate::locale::{LanguageIdentifier, LANGID};
|
||||
use crate::server::HttpRequest;
|
||||
use crate::{concat_string, config, util, LazyStatic};
|
||||
|
|
@ -120,8 +120,8 @@ impl RenderContext {
|
|||
|
||||
// Context EXTRAS.
|
||||
|
||||
pub fn required_id<T>(&mut self, id: &IdentifierValue) -> String {
|
||||
match id.get() {
|
||||
pub fn required_id<T>(&mut self, id: Option<String>) -> String {
|
||||
match id {
|
||||
Some(id) => id,
|
||||
None => {
|
||||
let prefix = util::single_type_name::<T>()
|
||||
|
|
|
|||
|
|
@ -27,6 +27,10 @@ pub trait ComponentTrait: AnyComponent + BaseComponent + Send + Sync {
|
|||
None
|
||||
}
|
||||
|
||||
fn id(&self) -> Option<String> {
|
||||
None
|
||||
}
|
||||
|
||||
fn weight(&self) -> isize {
|
||||
0
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
use crate::fn_builder;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct AttributeValue(String);
|
||||
|
||||
|
|
@ -8,13 +10,7 @@ impl AttributeValue {
|
|||
|
||||
// AttributeValue BUILDER.
|
||||
|
||||
pub fn with_value(mut self, value: &str) -> Self {
|
||||
self.alter_value(value);
|
||||
self
|
||||
}
|
||||
|
||||
// AttributeValue ALTER.
|
||||
|
||||
#[fn_builder]
|
||||
pub fn alter_value(&mut self, value: &str) -> &mut Self {
|
||||
self.0 = value.trim().to_owned();
|
||||
self
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::concat_string;
|
||||
use crate::{concat_string, fn_builder};
|
||||
|
||||
pub enum ClassesOp {
|
||||
Add,
|
||||
|
|
@ -26,13 +26,7 @@ impl Classes {
|
|||
|
||||
// Classes BUILDER.
|
||||
|
||||
pub fn with_value(mut self, op: ClassesOp, classes: &str) -> Self {
|
||||
self.alter_value(op, classes);
|
||||
self
|
||||
}
|
||||
|
||||
// Classes ALTER.
|
||||
|
||||
#[fn_builder]
|
||||
pub fn alter_value(&mut self, op: ClassesOp, classes: &str) -> &mut Self {
|
||||
let classes = classes.trim();
|
||||
match op {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
use crate::fn_builder;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct IdentifierValue(String);
|
||||
|
||||
|
|
@ -8,13 +10,7 @@ impl IdentifierValue {
|
|||
|
||||
// IdentifierValue BUILDER.
|
||||
|
||||
pub fn with_value(mut self, value: &str) -> Self {
|
||||
self.alter_value(value);
|
||||
self
|
||||
}
|
||||
|
||||
// IdentifierValue ALTER.
|
||||
|
||||
#[fn_builder]
|
||||
pub fn alter_value(&mut self, value: &str) -> &mut Self {
|
||||
self.0 = value.trim().replace(' ', "_");
|
||||
self
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
use crate::fn_builder;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct NameValue(String);
|
||||
|
||||
|
|
@ -8,13 +10,7 @@ impl NameValue {
|
|||
|
||||
// NameValue BUILDER.
|
||||
|
||||
pub fn with_value(mut self, value: &str) -> Self {
|
||||
self.alter_value(value);
|
||||
self
|
||||
}
|
||||
|
||||
// NameValue ALTER.
|
||||
|
||||
#[fn_builder]
|
||||
pub fn alter_value(&mut self, value: &str) -> &mut Self {
|
||||
self.0 = value.trim().replace(' ', "_");
|
||||
self
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
//! Funciones útiles y macros declarativas.
|
||||
//! Funciones útiles.
|
||||
|
||||
use crate::Handle;
|
||||
|
||||
|
|
@ -7,6 +7,7 @@ use crate::Handle;
|
|||
// *************************************************************************************************
|
||||
|
||||
// https://stackoverflow.com/a/71464396
|
||||
#[doc(hidden)]
|
||||
pub const fn handle(
|
||||
module_path: &'static str,
|
||||
file: &'static str,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue