feat(build): generate slot target objects
Add generated targets::<slot> wrapper objects so partial swaps read as target.put/append/replace while preserving existing lower-aware commands and IntoEffect wiring. req: dx/006 req: codegen/001 req: codegen/002 req: component/003
This commit is contained in:
+52
-4
@@ -407,6 +407,45 @@ impl Resources {
|
||||
}
|
||||
out.push_str(&format!("{pad}}}\n\n"));
|
||||
|
||||
out.push_str(&format!("{pad}#[allow(non_upper_case_globals)]\n{pad}pub mod targets {{\n"));
|
||||
out.push_str(&format!("{inner}#[derive(Clone, Copy)]\n"));
|
||||
out.push_str(&format!("{inner}pub struct SlotTarget<T> {{ slot: ::slhx::Slot<T> }}\n"));
|
||||
out.push_str(&format!("{inner}impl<T> SlotTarget<T> {{\n"));
|
||||
out.push_str(&format!("{inner} pub const fn new(slot: ::slhx::Slot<T>) -> Self {{ Self {{ slot }} }}\n"));
|
||||
out.push_str(&format!("{inner} pub const fn slot(self) -> ::slhx::Slot<T> {{ self.slot }}\n"));
|
||||
out.push_str(&format!("{inner} pub const fn id(self) -> ::slhx::ResourceId {{ self.slot.id() }}\n"));
|
||||
out.push_str(&format!("{inner} pub fn put(self, view: &impl ::hemplate::Hemplate) -> impl ::slhx::IntoEffect {{ super::put(self.slot, view) }}\n"));
|
||||
out.push_str(&format!("{inner} pub fn text(self, value: impl ::std::string::ToString) -> impl ::slhx::IntoEffect {{ self.slot.text(value) }}\n"));
|
||||
out.push_str(&format!("{inner}}}\n"));
|
||||
out.push_str(&format!("{inner}#[derive(Clone, Copy)]\n"));
|
||||
out.push_str(&format!("{inner}pub struct KeyedSlotTarget<K, T> {{ slot: ::slhx::KeyedSlot<K, T> }}\n"));
|
||||
out.push_str(&format!("{inner}impl<K, T> KeyedSlotTarget<K, T>\n"));
|
||||
out.push_str(&format!("{inner}where\n"));
|
||||
out.push_str(&format!("{inner} K: ::std::string::ToString,\n"));
|
||||
out.push_str(&format!("{inner}{{\n"));
|
||||
out.push_str(&format!("{inner} pub const fn new(slot: ::slhx::KeyedSlot<K, T>) -> Self {{ Self {{ slot }} }}\n"));
|
||||
out.push_str(&format!("{inner} pub const fn slot(self) -> ::slhx::KeyedSlot<K, T> {{ self.slot }}\n"));
|
||||
out.push_str(&format!("{inner} pub const fn id(self) -> ::slhx::ResourceId {{ self.slot.id() }}\n"));
|
||||
out.push_str(&format!("{inner} pub fn append(self, key: K, view: &impl ::hemplate::Hemplate) -> impl ::slhx::IntoEffect {{ super::append(self.slot, key, view) }}\n"));
|
||||
out.push_str(&format!("{inner} pub fn prepend(self, key: K, view: &impl ::hemplate::Hemplate) -> impl ::slhx::IntoEffect {{ super::prepend(self.slot, key, view) }}\n"));
|
||||
out.push_str(&format!("{inner} pub fn replace(self, key: K, view: &impl ::hemplate::Hemplate) -> impl ::slhx::IntoEffect {{ super::replace(self.slot, key, view) }}\n"));
|
||||
out.push_str(&format!("{inner} pub fn remove(self, key: K) -> impl ::slhx::IntoEffect {{ self.slot.remove(key) }}\n"));
|
||||
out.push_str(&format!("{inner}}}\n"));
|
||||
for res in self.slots.values().filter(|res| component_matches(res, component)) {
|
||||
if res.keyed {
|
||||
out.push_str(&format!(
|
||||
"{inner}pub const {}: KeyedSlotTarget<::std::string::String, ::std::string::String> = KeyedSlotTarget::new(super::slots::{});\n",
|
||||
res.ident, res.ident
|
||||
));
|
||||
} else {
|
||||
out.push_str(&format!(
|
||||
"{inner}pub const {}: SlotTarget<::std::string::String> = SlotTarget::new(super::slots::{});\n",
|
||||
res.ident, res.ident
|
||||
));
|
||||
}
|
||||
}
|
||||
out.push_str(&format!("{pad}}}\n\n"));
|
||||
|
||||
out.push_str(&format!("{pad}#[allow(non_upper_case_globals)]\n{pad}pub mod handles {{\n"));
|
||||
for res in self.handles.values().filter(|res| component_matches(res, component)) {
|
||||
handle_ids.push(res.id);
|
||||
@@ -1312,6 +1351,10 @@ mod tests {
|
||||
assert!(generated.contains("pub const todo: ::slhx::ComponentRef = ::slhx::ComponentRef::new(\"todo\")"));
|
||||
assert!(generated.contains("pub mod slots"));
|
||||
assert!(generated.contains("pub const todos"));
|
||||
assert!(generated.contains("pub mod targets"));
|
||||
assert!(generated.contains("pub struct SlotTarget<T>"));
|
||||
assert!(generated.contains("pub const todos: SlotTarget<::std::string::String> = SlotTarget::new(super::slots::todos);"));
|
||||
assert!(generated.contains("pub fn put(self, view: &impl ::hemplate::Hemplate) -> impl ::slhx::IntoEffect"));
|
||||
assert!(generated.contains("pub mod handles"));
|
||||
assert!(generated.contains("pub const create: ::slhx::Handle<::slhx::Form<::std::string::String>>"));
|
||||
assert!(generated.contains("pub mod params"));
|
||||
@@ -1374,6 +1417,7 @@ mod tests {
|
||||
assert!(generated.contains("pub mod todo"));
|
||||
assert!(generated.contains("pub const create: ::slhx::Handle<()> = ::slhx::Handle::new("));
|
||||
assert!(generated.contains("pub const todos: ::slhx::Slot<::std::string::String> = ::slhx::Slot::new("));
|
||||
assert!(generated.contains("pub const todos: SlotTarget<::std::string::String> = SlotTarget::new(super::slots::todos);"));
|
||||
assert!(generated.contains("pub const click: ::slhx::EventName = ::slhx::EventName::new(\"click\")"));
|
||||
|
||||
let _ = std::fs::remove_dir_all(&base);
|
||||
@@ -1408,6 +1452,8 @@ mod tests {
|
||||
assert!(generated.contains("pub mod todo"));
|
||||
assert!(generated.contains(" pub const COMPONENT: ::slhx::ComponentRef = ::slhx::ComponentRef::new(\"todo\")"));
|
||||
assert!(generated.contains(" pub mod slots"));
|
||||
assert!(generated.contains(" pub mod targets"));
|
||||
assert!(generated.contains(" pub const todos: SlotTarget<::std::string::String> = SlotTarget::new(super::slots::todos);"));
|
||||
assert!(generated.contains(" #[doc(hidden)]\n pub fn lower_html"));
|
||||
assert!(generated.contains(" #[doc(hidden)]\n pub fn render_html(view: &impl ::hemplate::Hemplate) -> ::slhx::SafeHtml"));
|
||||
assert!(generated.contains(" pub fn static_fragment(html: &'static str) -> ::slhx::SafeHtml"));
|
||||
@@ -1514,12 +1560,13 @@ mod slhx {{
|
||||
#[derive(Clone, Copy)] pub struct BuildFingerprint;
|
||||
impl BuildFingerprint {{ pub const fn from_parts(_: &[u32]) -> Self {{ Self }} }}
|
||||
pub struct Effect;
|
||||
#[derive(Clone, Copy)] pub struct ResourceId;
|
||||
pub trait IntoEffect {{}}
|
||||
impl IntoEffect for Effect {{}}
|
||||
#[derive(Clone, Copy)] pub struct Slot<T>(::std::marker::PhantomData<T>);
|
||||
impl<T> Slot<T> {{ pub const fn new(_: u32) -> Self {{ Self(::std::marker::PhantomData) }} pub fn html(self, _: SafeHtml) -> Effect {{ Effect }} }}
|
||||
impl<T> Slot<T> {{ pub const fn new(_: u32) -> Self {{ Self(::std::marker::PhantomData) }} pub const fn id(self) -> ResourceId {{ ResourceId }} pub fn html(self, _: SafeHtml) -> Effect {{ Effect }} pub fn text(self, _: impl ::std::string::ToString) -> Effect {{ Effect }} }}
|
||||
#[derive(Clone, Copy)] pub struct KeyedSlot<K, T>(::std::marker::PhantomData<(K, T)>);
|
||||
impl<K, T> KeyedSlot<K, T> {{ pub const fn new(_: u32) -> Self {{ Self(::std::marker::PhantomData) }} pub fn append_html(self, _: K, _: SafeHtml) -> Effect {{ Effect }} pub fn prepend_html(self, _: K, _: SafeHtml) -> Effect {{ Effect }} pub fn replace_html(self, _: K, _: SafeHtml) -> Effect {{ Effect }} }}
|
||||
impl<K, T> KeyedSlot<K, T> {{ pub const fn new(_: u32) -> Self {{ Self(::std::marker::PhantomData) }} pub const fn id(self) -> ResourceId {{ ResourceId }} pub fn append_html(self, _: K, _: SafeHtml) -> Effect {{ Effect }} pub fn prepend_html(self, _: K, _: SafeHtml) -> Effect {{ Effect }} pub fn replace_html(self, _: K, _: SafeHtml) -> Effect {{ Effect }} pub fn remove(self, _: K) -> Effect {{ Effect }} }}
|
||||
#[derive(Clone, Copy)] pub struct Handle<T>(::std::marker::PhantomData<T>);
|
||||
impl<T> Handle<T> {{ pub const fn new(_: u32) -> Self {{ Self(::std::marker::PhantomData) }} }}
|
||||
#[derive(Clone, Copy)] pub struct Atom<T>(::std::marker::PhantomData<T>);
|
||||
@@ -1791,12 +1838,13 @@ mod slhx {{
|
||||
#[derive(Clone, Copy)] pub struct BuildFingerprint;
|
||||
impl BuildFingerprint {{ pub const fn from_parts(_: &[u32]) -> Self {{ Self }} }}
|
||||
pub struct Effect;
|
||||
#[derive(Clone, Copy)] pub struct ResourceId;
|
||||
pub trait IntoEffect {{}}
|
||||
impl IntoEffect for Effect {{}}
|
||||
#[derive(Clone, Copy)] pub struct Slot<T>(::std::marker::PhantomData<T>);
|
||||
impl<T> Slot<T> {{ pub const fn new(_: u32) -> Self {{ Self(::std::marker::PhantomData) }} pub fn html(self, _: SafeHtml) -> Effect {{ Effect }} }}
|
||||
impl<T> Slot<T> {{ pub const fn new(_: u32) -> Self {{ Self(::std::marker::PhantomData) }} pub const fn id(self) -> ResourceId {{ ResourceId }} pub fn html(self, _: SafeHtml) -> Effect {{ Effect }} pub fn text(self, _: impl ::std::string::ToString) -> Effect {{ Effect }} }}
|
||||
#[derive(Clone, Copy)] pub struct KeyedSlot<K, T>(::std::marker::PhantomData<(K, T)>);
|
||||
impl<K, T> KeyedSlot<K, T> {{ pub const fn new(_: u32) -> Self {{ Self(::std::marker::PhantomData) }} pub fn append_html(self, _: K, _: SafeHtml) -> Effect {{ Effect }} pub fn prepend_html(self, _: K, _: SafeHtml) -> Effect {{ Effect }} pub fn replace_html(self, _: K, _: SafeHtml) -> Effect {{ Effect }} }}
|
||||
impl<K, T> KeyedSlot<K, T> {{ pub const fn new(_: u32) -> Self {{ Self(::std::marker::PhantomData) }} pub const fn id(self) -> ResourceId {{ ResourceId }} pub fn append_html(self, _: K, _: SafeHtml) -> Effect {{ Effect }} pub fn prepend_html(self, _: K, _: SafeHtml) -> Effect {{ Effect }} pub fn replace_html(self, _: K, _: SafeHtml) -> Effect {{ Effect }} pub fn remove(self, _: K) -> Effect {{ Effect }} }}
|
||||
#[derive(Clone, Copy)] pub struct Handle<T>(::std::marker::PhantomData<T>);
|
||||
impl<T> Handle<T> {{ pub const fn new(_: u32) -> Self {{ Self(::std::marker::PhantomData) }} }}
|
||||
#[derive(Clone, Copy)] pub struct Atom<T>(::std::marker::PhantomData<T>);
|
||||
|
||||
Reference in New Issue
Block a user