🔥 Remove body and region, not context-specific

This commit is contained in:
Manuel Cillero 2024-04-23 21:40:29 +02:00
parent ece78b2b4a
commit 2d906621de
6 changed files with 76 additions and 170 deletions

View file

@ -3,9 +3,3 @@ pub use html::Html;
mod fluent;
pub use fluent::Fluent;
mod body;
pub use body::Body;
mod region;
pub use region::Region;

View file

@ -1,51 +0,0 @@
use crate::prelude::*;
#[derive(AutoDefault)]
pub struct Body(MixedComponents);
impl ComponentTrait for Body {
fn new() -> Self {
Body::default()
}
fn prepare_component(&self, cx: &mut Context) -> PrepareMarkup {
let skip_to_id = cx.body_skip_to().get().unwrap_or("content".to_owned());
PrepareMarkup::With(html! {
body id=[cx.body_id().get()] class=[cx.body_classes().get()] {
@if let Some(skip) = L10n::l("skip_to_content").using(cx.langid()) {
div class="skip__to_content" {
a href=(concat_string!("#", skip_to_id)) { (skip) }
}
}
(self.components().render(cx))
}
})
}
}
impl Body {
pub fn with(component: impl ComponentTrait) -> Self {
Body::default().add_component(component)
}
// Body BUILDER.
#[fn_builder]
pub fn alter_components(&mut self, op: AnyOp) -> &mut Self {
self.0.alter_value(op);
self
}
#[rustfmt::skip]
pub fn add_component(mut self, component: impl ComponentTrait) -> Self {
self.0.alter_value(AnyOp::Add(AnyComponent::with(component)));
self
}
// Body GETTERS.
pub fn components(&self) -> &MixedComponents {
&self.0
}
}

View file

@ -1,31 +0,0 @@
use crate::prelude::*;
#[derive(AutoDefault)]
pub struct Region(OptionId);
impl ComponentTrait for Region {
fn new() -> Self {
Region::default()
}
fn id(&self) -> Option<String> {
self.0.get()
}
fn prepare_component(&self, cx: &mut Context) -> PrepareMarkup {
match self.id() {
Some(id) => PrepareMarkup::With(cx.prepare_region(id)),
_ => PrepareMarkup::None,
}
}
}
impl Region {
// Region BUILDER.
#[fn_builder]
pub fn alter_id(&mut self, id: impl Into<String>) -> &mut Self {
self.0.alter_value(id);
self
}
}