wip: docs, html! macro, more

This commit is contained in:
Jonathan Kelley committed 2021-07-16 00:27:06 -04:00
1 parent 8f0bb5dc5b
commit caf772cf24
27 files changed
+407 -191

No files matched your search

+4 -4
View File
@@ -26,7 +26,7 @@ pub struct Component {
// accept any path-like argument
name: syn::Path,
body: Vec<ComponentField>,
children: Vec<Node>,
children: Vec<BodyNode>,
manual_props: Option<Expr>,
}
@@ -42,7 +42,7 @@ impl Parse for Component {
syn::braced!(content in stream);
let mut body: Vec<ComponentField> = Vec::new();
let mut children: Vec<Node> = Vec::new();
let mut children: Vec<BodyNode> = Vec::new();
let mut manual_props = None;
parse_component_body(
@@ -78,7 +78,7 @@ pub fn parse_component_body(
content: &ParseBuffer,
cfg: &BodyParseConfig,
body: &mut Vec<ComponentField>,
children: &mut Vec<Node>,
children: &mut Vec<BodyNode>,
manual_props: &mut Option<Expr>,
) -> Result<()> {
'parsing: loop {
@@ -111,7 +111,7 @@ pub fn parse_component_body(
"This item is not allowed to accept children.",
));
}
children.push(content.parse::<Node>()?);
children.push(content.parse::<BodyNode>()?);
}
// consume comma if it exists
+15 -14
View File
@@ -16,7 +16,7 @@ pub struct Element {
key: Option<AttrType>,
attributes: Vec<ElementAttr>,
listeners: Vec<ElementAttr>,
children: Vec<Node>,
children: Vec<BodyNode>,
is_static: bool,
}
@@ -54,7 +54,7 @@ impl Parse for Element {
let mut attributes: Vec<ElementAttr> = vec![];
let mut listeners: Vec<ElementAttr> = vec![];
let mut children: Vec<Node> = vec![];
let mut children: Vec<BodyNode> = vec![];
let mut key = None;
'parsing: loop {
@@ -72,7 +72,7 @@ impl Parse for Element {
name.clone(),
)?;
} else {
children.push(content.parse::<Node>()?);
children.push(content.parse::<BodyNode>()?);
}
// consume comma if it exists
@@ -238,20 +238,9 @@ impl ToTokens for ElementAttr {
AttrType::BumpText(value) => tokens.append_all(quote! {
dioxus_elements::#el_name.#nameident(__cx, format_args_f!(#value))
}),
// __cx.attr(#name, format_args_f!(#value), #namespace, false)
//
// AttrType::BumpText(value) => tokens.append_all(quote! {
// __cx.attr(#name, format_args_f!(#value), #namespace, false)
// }),
AttrType::FieldTokens(exp) => tokens.append_all(quote! {
dioxus_elements::#el_name.#nameident(__cx, #exp)
}),
// __cx.attr(#name_str, #exp, #namespace, false)
// AttrType::FieldTokens(exp) => tokens.append_all(quote! {
// dioxus_elements::#el_name.#nameident(__cx, format_args_f!(#value))
// __cx.attr(#name_str, #exp, #namespace, false)
// }),
// todo: move event handlers on to the elements or onto the nodefactory
AttrType::Event(event) => tokens.append_all(quote! {
@@ -264,3 +253,15 @@ impl ToTokens for ElementAttr {
}
}
}
// __cx.attr(#name, format_args_f!(#value), #namespace, false)
//
// AttrType::BumpText(value) => tokens.append_all(quote! {
// __cx.attr(#name, format_args_f!(#value), #namespace, false)
// }),
// __cx.attr(#name_str, #exp, #namespace, false)
// AttrType::FieldTokens(exp) => tokens.append_all(quote! {
// dioxus_elements::#el_name.#nameident(__cx, format_args_f!(#value))
// __cx.attr(#name_str, #exp, #namespace, false)
// }),
+4 -4
View File
@@ -32,12 +32,12 @@ use syn::{
Error, Ident, LitStr, Result, Token,
};
pub struct RsxRender {
pub struct RsxBody {
custom_context: Option<Ident>,
roots: Vec<Node>,
roots: Vec<BodyNode>,
}
impl Parse for RsxRender {
impl Parse for RsxBody {
fn parse(input: ParseStream) -> Result<Self> {
// if input.peek(LitStr) {
// return input.parse::<LitStr>()?.parse::<RsxRender>();
@@ -83,7 +83,7 @@ impl Parse for RsxRender {
}
}
impl ToTokens for RsxRender {
impl ToTokens for RsxBody {
fn to_tokens(&self, out_tokens: &mut TokenStream2) {
let inner = if self.roots.len() == 1 {
let inner = &self.roots[0];
+9 -9
View File
@@ -10,13 +10,13 @@ use syn::{
// ==============================================
// Parse any div {} as a VElement
// ==============================================
pub enum Node {
pub enum BodyNode {
Element(AmbiguousElement),
Text(TextNode),
RawExpr(Expr),
}
impl Parse for Node {
impl Parse for BodyNode {
fn parse(stream: ParseStream) -> Result<Self> {
// Supposedly this approach is discouraged due to inability to return proper errors
// TODO: Rework this to provide more informative errors
@@ -24,23 +24,23 @@ impl Parse for Node {
if stream.peek(token::Brace) {
let content;
syn::braced!(content in stream);
return Ok(Node::RawExpr(content.parse::<Expr>()?));
return Ok(BodyNode::RawExpr(content.parse::<Expr>()?));
}
if stream.peek(LitStr) {
return Ok(Node::Text(stream.parse::<TextNode>()?));
return Ok(BodyNode::Text(stream.parse::<TextNode>()?));
}
Ok(Node::Element(stream.parse::<AmbiguousElement>()?))
Ok(BodyNode::Element(stream.parse::<AmbiguousElement>()?))
}
}
impl ToTokens for Node {
impl ToTokens for BodyNode {
fn to_tokens(&self, tokens: &mut TokenStream2) {
match &self {
Node::Element(el) => el.to_tokens(tokens),
Node::Text(txt) => txt.to_tokens(tokens),
Node::RawExpr(exp) => tokens.append_all(quote! {
BodyNode::Element(el) => el.to_tokens(tokens),
BodyNode::Text(txt) => txt.to_tokens(tokens),
BodyNode::RawExpr(exp) => tokens.append_all(quote! {
__cx.fragment_from_iter(#exp)
}),
}