💥 Agrupa componentes en packs en lugar de bundles
This commit is contained in:
parent
f1f6f495bb
commit
9a63cacd8f
11 changed files with 67 additions and 67 deletions
|
|
@ -12,7 +12,7 @@ pub struct Block {
|
|||
id : IdentifierValue,
|
||||
classes : Classes,
|
||||
title : AttributeValue,
|
||||
components: ComponentsBundle,
|
||||
components: PackComponents,
|
||||
template : String,
|
||||
}
|
||||
|
||||
|
|
@ -98,12 +98,12 @@ impl Block {
|
|||
}
|
||||
|
||||
pub fn with_component(mut self, component: impl ComponentTrait) -> Self {
|
||||
self.components.alter_bundle(BundleOp::Add, component);
|
||||
self.components.alter_pack(PackOp::Add, component);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn alter_components(&mut self, op: BundleOp, component: impl ComponentTrait) -> &mut Self {
|
||||
self.components.alter_bundle(op, component);
|
||||
pub fn alter_components(&mut self, op: PackOp, component: impl ComponentTrait) -> &mut Self {
|
||||
self.components.alter_pack(op, component);
|
||||
self
|
||||
}
|
||||
|
||||
|
|
@ -123,7 +123,7 @@ impl Block {
|
|||
&self.title
|
||||
}
|
||||
|
||||
pub fn components(&self) -> &ComponentsBundle {
|
||||
pub fn components(&self) -> &PackComponents {
|
||||
&self.components
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ pub use definition::{component_mut, component_ref, AnyComponent, BaseComponent,
|
|||
mod one;
|
||||
pub use one::OneComponent;
|
||||
|
||||
mod bundle;
|
||||
pub use bundle::{BundleOp, ComponentsBundle};
|
||||
mod pack;
|
||||
pub use pack::{PackComponents, PackOp};
|
||||
|
||||
mod renderable;
|
||||
pub use renderable::{IsRenderable, Renderable};
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use crate::{fn_builder, Handle};
|
|||
|
||||
use std::sync::{Arc, RwLock};
|
||||
|
||||
pub enum BundleOp {
|
||||
pub enum PackOp {
|
||||
Add,
|
||||
AddAfterId(&'static str),
|
||||
AddBeforeId(&'static str),
|
||||
|
|
@ -17,41 +17,41 @@ pub enum BundleOp {
|
|||
pub type ArcLockComponent = Arc<RwLock<dyn ComponentTrait>>;
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
pub struct ComponentsBundle(Vec<ArcLockComponent>);
|
||||
pub struct PackComponents(Vec<ArcLockComponent>);
|
||||
|
||||
impl ComponentsBundle {
|
||||
impl PackComponents {
|
||||
pub fn new() -> Self {
|
||||
ComponentsBundle::default()
|
||||
PackComponents::default()
|
||||
}
|
||||
|
||||
pub fn new_with(component: impl ComponentTrait) -> Self {
|
||||
let mut bundle = ComponentsBundle::new();
|
||||
bundle.alter_bundle(BundleOp::Add, component);
|
||||
let mut bundle = PackComponents::new();
|
||||
bundle.alter_pack(PackOp::Add, component);
|
||||
bundle
|
||||
}
|
||||
|
||||
pub(crate) fn merge(one: Option<&ComponentsBundle>, other: Option<&ComponentsBundle>) -> Self {
|
||||
pub(crate) fn merge(one: Option<&PackComponents>, other: Option<&PackComponents>) -> Self {
|
||||
if let Some(one) = one {
|
||||
let mut components = one.0.clone();
|
||||
if let Some(other) = other {
|
||||
components.append(&mut other.0.clone());
|
||||
}
|
||||
ComponentsBundle(components)
|
||||
PackComponents(components)
|
||||
} else if let Some(other) = other {
|
||||
ComponentsBundle(other.0.clone())
|
||||
PackComponents(other.0.clone())
|
||||
} else {
|
||||
ComponentsBundle::default()
|
||||
PackComponents::default()
|
||||
}
|
||||
}
|
||||
|
||||
// ComponentsBundle BUILDER.
|
||||
// PackComponents BUILDER.
|
||||
|
||||
#[fn_builder]
|
||||
pub fn alter_bundle(&mut self, op: BundleOp, component: impl ComponentTrait) -> &mut Self {
|
||||
pub fn alter_pack(&mut self, op: PackOp, component: impl ComponentTrait) -> &mut Self {
|
||||
let arc = Arc::new(RwLock::new(component));
|
||||
match op {
|
||||
BundleOp::Add => self.0.push(arc),
|
||||
BundleOp::AddAfterId(id) => {
|
||||
PackOp::Add => self.0.push(arc),
|
||||
PackOp::AddAfterId(id) => {
|
||||
match self
|
||||
.0
|
||||
.iter()
|
||||
|
|
@ -61,7 +61,7 @@ impl ComponentsBundle {
|
|||
_ => self.0.push(arc),
|
||||
}
|
||||
}
|
||||
BundleOp::AddBeforeId(id) => {
|
||||
PackOp::AddBeforeId(id) => {
|
||||
match self
|
||||
.0
|
||||
.iter()
|
||||
|
|
@ -71,8 +71,8 @@ impl ComponentsBundle {
|
|||
_ => self.0.insert(0, arc),
|
||||
}
|
||||
}
|
||||
BundleOp::AddFirst => self.0.insert(0, arc),
|
||||
BundleOp::RemoveById(id) => {
|
||||
PackOp::AddFirst => self.0.insert(0, arc),
|
||||
PackOp::RemoveById(id) => {
|
||||
if let Some(index) = self
|
||||
.0
|
||||
.iter()
|
||||
|
|
@ -81,7 +81,7 @@ impl ComponentsBundle {
|
|||
self.0.remove(index);
|
||||
}
|
||||
}
|
||||
BundleOp::ReplaceById(id) => {
|
||||
PackOp::ReplaceById(id) => {
|
||||
for c in self.0.iter_mut() {
|
||||
if c.read().unwrap().id().as_deref() == Some(id) {
|
||||
*c = arc;
|
||||
|
|
@ -89,12 +89,12 @@ impl ComponentsBundle {
|
|||
}
|
||||
}
|
||||
}
|
||||
BundleOp::Reset => self.0.clear(),
|
||||
PackOp::Reset => self.0.clear(),
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
// ComponentsBundle GETTERS.
|
||||
// PackComponents GETTERS.
|
||||
|
||||
pub fn get_by_id(&self, id: &'static str) -> Option<&ArcLockComponent> {
|
||||
self.0
|
||||
|
|
@ -114,7 +114,7 @@ impl ComponentsBundle {
|
|||
.filter(move |&c| c.read().unwrap().handle() == handle)
|
||||
}
|
||||
|
||||
// ComponentsBundle PREPARE.
|
||||
// PackComponents PREPARE.
|
||||
|
||||
pub fn prepare(&self, rcx: &mut RenderContext) -> Markup {
|
||||
let mut components = self.0.clone();
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::core::component::{BundleOp, ComponentTrait, ComponentsBundle};
|
||||
use crate::core::component::{ComponentTrait, PackComponents, PackOp};
|
||||
use crate::LazyStatic;
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
|
@ -8,7 +8,7 @@ static THEME_REGIONS: LazyStatic<RwLock<HashMap<&'static str, ComponentsRegions>
|
|||
LazyStatic::new(|| RwLock::new(HashMap::new()));
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct ComponentsRegions(HashMap<&'static str, ComponentsBundle>);
|
||||
pub struct ComponentsRegions(HashMap<&'static str, PackComponents>);
|
||||
|
||||
impl ComponentsRegions {
|
||||
pub fn new() -> Self {
|
||||
|
|
@ -17,17 +17,17 @@ impl ComponentsRegions {
|
|||
|
||||
pub fn add_to(&mut self, region: &'static str, component: impl ComponentTrait) {
|
||||
if let Some(region) = self.0.get_mut(region) {
|
||||
region.alter_bundle(BundleOp::Add, component);
|
||||
region.alter_pack(PackOp::Add, component);
|
||||
} else {
|
||||
self.0.insert(region, ComponentsBundle::new_with(component));
|
||||
self.0.insert(region, PackComponents::new_with(component));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_extended_bundle(&self, theme: &str, region: &str) -> ComponentsBundle {
|
||||
pub fn get_extended_pack(&self, theme: &str, region: &str) -> PackComponents {
|
||||
if let Some(hm_theme) = THEME_REGIONS.read().unwrap().get(theme) {
|
||||
ComponentsBundle::merge(self.0.get(region), hm_theme.0.get(region))
|
||||
PackComponents::merge(self.0.get(region), hm_theme.0.get(region))
|
||||
} else {
|
||||
ComponentsBundle::merge(self.0.get(region), None)
|
||||
PackComponents::merge(self.0.get(region), None)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -177,7 +177,7 @@ impl Page {
|
|||
// Acciones del tema después de preparar la página.
|
||||
self.context.theme().after_prepare_page(self);
|
||||
|
||||
// Finalmente, renderizar la página.
|
||||
// Finalmente, renderiza la página.
|
||||
let lang = self.langid().language.as_str();
|
||||
let dir = match self.langid().character_direction() {
|
||||
CharacterDirection::LTR => "ltr",
|
||||
|
|
@ -195,7 +195,7 @@ impl Page {
|
|||
pub fn prepare_region(&mut self, region: &str) -> Option<Markup> {
|
||||
let render = self
|
||||
.regions
|
||||
.get_extended_bundle(self.context.theme().single_name(), region)
|
||||
.get_extended_pack(self.context.theme().single_name(), region)
|
||||
.prepare(self.context());
|
||||
if render.is_empty() {
|
||||
None
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue