🧑💻 Better names for with/alter/add_component_in
This commit is contained in:
parent
62b32ebcee
commit
15d545897b
9 changed files with 27 additions and 22 deletions
|
|
@ -16,7 +16,7 @@ async fn hello_name(
|
|||
) -> ResultPage<Markup, FatalError> {
|
||||
let name = path.into_inner();
|
||||
Page::new(request)
|
||||
.with_in("content", Html::with(html! { h1 { "Hello " (name) "!" } }))
|
||||
.with_component_in("content", Html::with(html! { h1 { "Hello " (name) "!" } }))
|
||||
.render()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ impl ModuleTrait for HelloWorld {
|
|||
|
||||
async fn hello_world(request: service::HttpRequest) -> ResultPage<Markup, FatalError> {
|
||||
Page::new(request)
|
||||
.with_in("content", Html::with(html! { h1 { "Hello World!" } }))
|
||||
.with_component_in("content", Html::with(html! { h1 { "Hello World!" } }))
|
||||
.render()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -153,8 +153,8 @@ pub async fn summary(request: service::HttpRequest) -> ResultPage<Markup, FatalE
|
|||
Page::new(request)
|
||||
//.with_context(ContextOp::Theme("Bootsier"))
|
||||
.with_title(L10n::n("Admin"))
|
||||
.with_in("top-menu", side_menu)
|
||||
.with_in(
|
||||
.with_component_in("top-menu", side_menu)
|
||||
.with_component_in(
|
||||
"content",
|
||||
flex::Container::new()
|
||||
.add_item(flex::Item::new().add_component(Html::with(html! {
|
||||
|
|
|
|||
|
|
@ -29,11 +29,11 @@ async fn demo(request: service::HttpRequest) -> ResultPage<Markup, FatalError> {
|
|||
"/homedemo/css/styles.css",
|
||||
)))
|
||||
.with_body_classes(ClassesOp::Add, "default-homepage")
|
||||
.with_in("content", hello_world())
|
||||
.with_in("content", welcome())
|
||||
.with_in("content", about_pagetop())
|
||||
.with_in("content", promo_pagetop())
|
||||
.with_in("content", reporting_issues())
|
||||
.with_component_in("content", hello_world())
|
||||
.with_component_in("content", welcome())
|
||||
.with_component_in("content", about_pagetop())
|
||||
.with_component_in("content", promo_pagetop())
|
||||
.with_component_in("content", reporting_issues())
|
||||
.render()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ impl ModuleTrait for User {
|
|||
async fn login(request: service::HttpRequest) -> ResultPage<Markup, FatalError> {
|
||||
Page::new(request)
|
||||
.with_title(L10n::n("Identificación del usuario"))
|
||||
.with_in(
|
||||
.with_component_in(
|
||||
"content",
|
||||
Wrapper::new()
|
||||
.with_id("welcome")
|
||||
|
|
|
|||
|
|
@ -17,11 +17,11 @@ pub struct ComponentsRegions(HashMap<&'static str, AnyComponents>);
|
|||
impl ComponentsRegions {
|
||||
pub fn new(region: &'static str, arc: ArcAnyComponent) -> Self {
|
||||
let mut regions = ComponentsRegions::default();
|
||||
regions.add_in(region, arc);
|
||||
regions.add_component_in(region, arc);
|
||||
regions
|
||||
}
|
||||
|
||||
pub fn add_in(&mut self, region: &'static str, arc: ArcAnyComponent) {
|
||||
pub fn add_component_in(&mut self, region: &'static str, arc: ArcAnyComponent) {
|
||||
if let Some(region) = self.0.get_mut(region) {
|
||||
region.alter_value(ArcAnyOp::Add(arc));
|
||||
} else {
|
||||
|
|
@ -31,8 +31,8 @@ impl ComponentsRegions {
|
|||
|
||||
pub fn get_components(&self, theme: ThemeRef, region: &str) -> AnyComponents {
|
||||
let common = COMMON_REGIONS.read().unwrap();
|
||||
if let Some(hm) = THEME_REGIONS.read().unwrap().get(&theme.handle()) {
|
||||
AnyComponents::merge(&[common.0.get(region), self.0.get(region), hm.0.get(region)])
|
||||
if let Some(r) = THEME_REGIONS.read().unwrap().get(&theme.handle()) {
|
||||
AnyComponents::merge(&[common.0.get(region), self.0.get(region), r.0.get(region)])
|
||||
} else {
|
||||
AnyComponents::merge(&[common.0.get(region), self.0.get(region)])
|
||||
}
|
||||
|
|
@ -47,12 +47,12 @@ pub enum Region {
|
|||
pub fn add_component_in(region: Region, arc: ArcAnyComponent) {
|
||||
match region {
|
||||
Region::Named(name) => {
|
||||
COMMON_REGIONS.write().unwrap().add_in(name, arc);
|
||||
COMMON_REGIONS.write().unwrap().add_component_in(name, arc);
|
||||
}
|
||||
Region::OfTheme(theme, region) => {
|
||||
let mut regions = THEME_REGIONS.write().unwrap();
|
||||
if let Some(hm) = regions.get_mut(&theme.handle()) {
|
||||
hm.add_in(region, arc);
|
||||
if let Some(r) = regions.get_mut(&theme.handle()) {
|
||||
r.add_component_in(region, arc);
|
||||
} else {
|
||||
regions.insert(theme.handle(), ComponentsRegions::new(region, arc));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@
|
|||
//!
|
||||
//! async fn hello_world(request: service::HttpRequest) -> ResultPage<Markup, FatalError> {
|
||||
//! Page::new(request)
|
||||
//! .with_in("content", Html::with(html! { h1 { "Hello World!" } }))
|
||||
//! .with_component_in("content", Html::with(html! { h1 { "Hello World!" } }))
|
||||
//! .render()
|
||||
//! }
|
||||
//!
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ impl fmt::Display for FatalError {
|
|||
let error_page = Page::new(request.clone());
|
||||
if let Ok(page) = error_page
|
||||
.with_title(L10n::n("Error FORBIDDEN"))
|
||||
.with_in("content", Error403)
|
||||
.with_component_in("content", Error403)
|
||||
.with_template("error")
|
||||
.render()
|
||||
{
|
||||
|
|
@ -43,7 +43,7 @@ impl fmt::Display for FatalError {
|
|||
let error_page = Page::new(request.clone());
|
||||
if let Ok(page) = error_page
|
||||
.with_title(L10n::n("Error RESOURCE NOT FOUND"))
|
||||
.with_in("content", Error404)
|
||||
.with_component_in("content", Error404)
|
||||
.with_template("error")
|
||||
.render()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -94,8 +94,13 @@ impl Page {
|
|||
}
|
||||
|
||||
#[fn_builder]
|
||||
pub fn alter_in(&mut self, region: &'static str, component: impl ComponentTrait) -> &mut Self {
|
||||
self.regions.add_in(region, ArcAnyComponent::new(component));
|
||||
pub fn alter_component_in(
|
||||
&mut self,
|
||||
region: &'static str,
|
||||
component: impl ComponentTrait,
|
||||
) -> &mut Self {
|
||||
self.regions
|
||||
.add_component_in(region, ArcAnyComponent::new(component));
|
||||
self
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue