Feat: wowza got it all working
This commit is contained in:
1 parent
da00df6688
commit
4b8e9f4a12
8 files changed
+233
-105
No files matched your search
@@ -1,46 +1,127 @@
|
||||
use dioxus_core_macro::rsx;
|
||||
|
||||
pub mod dioxus {
|
||||
pub mod builder {
|
||||
pub struct Builder;
|
||||
|
||||
struct AttrVal;
|
||||
|
||||
impl Into<AttrVal> for &'static str {
|
||||
fn into(self) -> AttrVal {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<AttrVal> for String {
|
||||
fn into(self) -> AttrVal {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
// impl<T> From<T> for AttrVal {
|
||||
// fn from(_: T) -> Self {
|
||||
// todo!()
|
||||
// }
|
||||
// }
|
||||
|
||||
impl Builder {
|
||||
// fn attr<T>(mut self, key: &str, value: impl Into<AttrVal>) -> Self {
|
||||
pub fn attr<T>(mut self, key: &str, value: T) -> Self {
|
||||
Self
|
||||
}
|
||||
|
||||
pub fn on<T>(mut self, key: &str, value: T) -> Self {
|
||||
Self
|
||||
}
|
||||
|
||||
pub fn finish(mut self) {
|
||||
// Self
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Bump;
|
||||
pub fn div(bump: &Bump) -> Builder {
|
||||
todo!()
|
||||
}
|
||||
pub fn h1(bump: &Bump) -> Builder {
|
||||
todo!()
|
||||
}
|
||||
pub fn h2(bump: &Bump) -> Builder {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
}
|
||||
use dioxus::builder::Bump;
|
||||
pub fn main() {
|
||||
// render(rsx! {
|
||||
// _ {}
|
||||
// div { // we can actually support just a list of nodes too
|
||||
// h1 {"Hello Dioxus"}
|
||||
// p {"This is a beautful app you're building"}
|
||||
// section {
|
||||
// "custom section to the rescue",
|
||||
// class: "abc123"
|
||||
// }
|
||||
// span {
|
||||
// class: "abc123"
|
||||
// "Try backwards too."
|
||||
// "Anything goes!"
|
||||
// "As long as it's within the rules"
|
||||
// {0..10.map(|f| rsx!{
|
||||
// div {
|
||||
// h3 {"totally okay to drop in iterators and expressions"}
|
||||
// p {"however, debug information is lost"}
|
||||
// }
|
||||
// })}
|
||||
// }
|
||||
// span {
|
||||
// "Feel free"
|
||||
// class: "abc123"
|
||||
// "To mix to your heart's content"
|
||||
// }
|
||||
// span { class: "some-very-long-and-tedious-class-name-is-now-separated"
|
||||
// "Very ergonomic"
|
||||
// }
|
||||
// span { "Innovative design 🛠"
|
||||
// class: "some-very-long-and-tedious-class-name-is-now-separated"
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
|
||||
let g = String::from("asd");
|
||||
|
||||
let lazy = rsx! {
|
||||
div {
|
||||
a: "asd",
|
||||
a: "asd",
|
||||
a: "asd",
|
||||
a: "asd",
|
||||
a: "asd",
|
||||
a: {rsx!{ h1 {"hello world"} }}, // include
|
||||
a: {g},
|
||||
b: {1 + 2},
|
||||
onclick: {move |_| {
|
||||
println!("hello world!")
|
||||
}},
|
||||
div {
|
||||
a: "asd"
|
||||
div {
|
||||
div {
|
||||
div {
|
||||
// let lazy = rsx! {
|
||||
// div {
|
||||
// a: "asd",
|
||||
// a: "asd",
|
||||
// a: "asd",
|
||||
// a: "asd",
|
||||
// a: "asd",
|
||||
// // a: {rsx!{ h1 {"hello world"} }}, // include
|
||||
// a: {&g},
|
||||
// b: {1 + 2},
|
||||
// onclick: {move |e: ()| {
|
||||
// println!("hello world!")
|
||||
// }},
|
||||
// div {
|
||||
// a: "asd"
|
||||
// div {
|
||||
// div {
|
||||
// div {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
h1 {
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// h1 {
|
||||
|
||||
}
|
||||
h2 {
|
||||
"child"
|
||||
}
|
||||
"Childnode"
|
||||
}
|
||||
};
|
||||
// }
|
||||
// h2 {
|
||||
// "child"
|
||||
// }
|
||||
// "Childnode"
|
||||
// }
|
||||
// };
|
||||
|
||||
render(lazy);
|
||||
// render(lazy);
|
||||
}
|
||||
|
||||
fn render(f: impl Fn(())) {}
|
||||
fn render(f: impl Fn(&dioxus::builder::Bump)) {}
|
||||
@@ -49,7 +49,9 @@ use {
|
||||
// ==============================================
|
||||
// Parse any stream coming from the rsx! macro
|
||||
// ==============================================
|
||||
pub struct RsxRender {}
|
||||
pub struct RsxRender {
|
||||
el: Element,
|
||||
}
|
||||
|
||||
impl Parse for RsxRender {
|
||||
fn parse(input: ParseStream) -> Result<Self> {
|
||||
@@ -57,20 +59,22 @@ impl Parse for RsxRender {
|
||||
// can only accept one root per component
|
||||
// fragments can be used as
|
||||
// _ { content }
|
||||
let g: Element = input.parse()?;
|
||||
Ok(Self {})
|
||||
let el: Element = input.parse()?;
|
||||
Ok(Self { el })
|
||||
}
|
||||
}
|
||||
|
||||
impl ToTokens for RsxRender {
|
||||
fn to_tokens(&self, tokens: &mut TokenStream2) {
|
||||
let new_toks = quote! {
|
||||
move |_| {
|
||||
todo!()
|
||||
}
|
||||
fn to_tokens(&self, out_tokens: &mut TokenStream2) {
|
||||
let new_toks = ToToksCtx::new(&self.el).to_token_stream();
|
||||
// let new_toks = ToToksCtx::new(&self.kind).to_token_stream();
|
||||
|
||||
// create a lazy tree that accepts a bump allocator
|
||||
let final_tokens = quote! {
|
||||
move |bump: &Bump| { #new_toks }
|
||||
};
|
||||
|
||||
new_toks.to_tokens(tokens)
|
||||
final_tokens.to_tokens(out_tokens);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,14 +104,23 @@ impl ToTokens for ToToksCtx<&Node> {
|
||||
impl Parse for Node {
|
||||
fn parse(s: ParseStream) -> Result<Self> {
|
||||
let fork = s.fork();
|
||||
if let Ok(text) = fork.parse::<TextNode>() {
|
||||
|
||||
let ret = if let Ok(text) = fork.parse::<TextNode>() {
|
||||
s.advance_to(&fork);
|
||||
return Ok(Self::Text(text));
|
||||
Ok(Self::Text(text))
|
||||
} else if let Ok(el) = s.parse::<Element>() {
|
||||
return Ok(Self::Element(el));
|
||||
Ok(Self::Element(el))
|
||||
} else {
|
||||
// TODO: Span information
|
||||
panic!("Not a valid child node");
|
||||
};
|
||||
|
||||
// consume comma if it exists
|
||||
// we don't actually care if there *are* commas after elements/text
|
||||
if s.peek(Token![,]) {
|
||||
let _ = s.parse::<Token![,]>();
|
||||
}
|
||||
ret
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,37 +138,37 @@ struct Element {
|
||||
|
||||
impl ToTokens for ToToksCtx<&Element> {
|
||||
fn to_tokens(&self, tokens: &mut TokenStream2) {
|
||||
todo!()
|
||||
// todo!()
|
||||
// // let ctx = self.ctx;
|
||||
// let name = &self.inner.name;
|
||||
// tokens.append_all(quote! {
|
||||
// dioxus::builder::#name(bump)
|
||||
// });
|
||||
// for attr in self.inner.attrs.iter() {
|
||||
// self.recurse(attr).to_tokens(tokens);
|
||||
// }
|
||||
// match &self.inner.children {
|
||||
// MaybeExpr::Expr(expr) => tokens.append_all(quote! {
|
||||
// .children(#expr)
|
||||
// }),
|
||||
// MaybeExpr::Literal(nodes) => {
|
||||
// let mut children = nodes.iter();
|
||||
// if let Some(child) = children.next() {
|
||||
// let mut inner_toks = TokenStream2::new();
|
||||
// self.recurse(child).to_tokens(&mut inner_toks);
|
||||
// while let Some(child) = children.next() {
|
||||
// quote!(,).to_tokens(&mut inner_toks);
|
||||
// self.recurse(child).to_tokens(&mut inner_toks);
|
||||
// }
|
||||
// tokens.append_all(quote! {
|
||||
// .children([#inner_toks])
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// tokens.append_all(quote! {
|
||||
// .finish()
|
||||
// });
|
||||
let name = &self.inner.name;
|
||||
tokens.append_all(quote! {
|
||||
dioxus::builder::#name(bump)
|
||||
});
|
||||
for attr in self.inner.attrs.iter() {
|
||||
self.recurse(attr).to_tokens(tokens);
|
||||
}
|
||||
match &self.inner.children {
|
||||
MaybeExpr::Expr(expr) => tokens.append_all(quote! {
|
||||
.children(#expr)
|
||||
}),
|
||||
MaybeExpr::Literal(nodes) => {
|
||||
let mut children = nodes.iter();
|
||||
if let Some(child) = children.next() {
|
||||
let mut inner_toks = TokenStream2::new();
|
||||
self.recurse(child).to_tokens(&mut inner_toks);
|
||||
while let Some(child) = children.next() {
|
||||
quote!(,).to_tokens(&mut inner_toks);
|
||||
self.recurse(child).to_tokens(&mut inner_toks);
|
||||
}
|
||||
tokens.append_all(quote! {
|
||||
.children([#inner_toks])
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
tokens.append_all(quote! {
|
||||
.finish()
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -214,7 +227,8 @@ impl Parse for Element {
|
||||
panic!("Entry is not an attr or element\n {}", content)
|
||||
}
|
||||
|
||||
let children = MaybeExpr::Literal(Vec::new());
|
||||
let children = MaybeExpr::Literal(children);
|
||||
// let children = MaybeExpr::Literal(Vec::new());
|
||||
// // Contents of an element can either be a brace (in which case we just copy verbatim), or a
|
||||
// // sequence of nodes.
|
||||
// let children = if s.peek(token::Brace) {
|
||||
|
||||
Reference in new issue
Block a user