-
Notifications
You must be signed in to change notification settings - Fork 12
feat: support for custom node #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I added Trying to implement a #[derive(Debug, syn_derive::ToTokens)]
struct If {
token_lt: Token![<],
token_if: Token![if],
condition: Expr,
token_gt: Token![>],
#[to_tokens(|tokens, val| tokens.append_all(val))]
children: Vec<Node>,
close_tag: atoms::CloseTag,
}
html! {
<if condition>
children
</if>
};
My idea was to add fn parse_element(
parser: &mut rstml::recoverable::RecoverableContext,
input: syn::parse::ParseStream,
) -> Option<Self> {
let token_lt = parser.parse_simple(input)?;
let token_if = parser.parse_simple(input)?;
let (condition, open_tag_end): (_, OpenTagEnd) = parser.parse_simple_with_ending(input)?;
let (body, close_tag) = if open_tag_end.token_solidus.is_some() {
// Passed to allow parsing of close_tag
parser.parse_node_body(&OpenTag {
token_lt,
name: parse_quote!(#token_if),
generics: Default::default(),
attributes: Default::default(),
end_tag: open_tag_end.clone(),
})?
} else {
(Vec::new(), None)
};
Some(Self {
token_lt,
token_if,
condition,
open_tag_end,
body,
close_tag,
})
} |
ea7a94a
to
a9aeb58
Compare
@ModProg Sorry, was busy in road trip. I will review pr today. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work, thanks for contribution.
This is also true for attributes, though, isn't it? It should be documented, but that seems like a weakness of the syntax in general, not just of this usage (though comparisons are probably more likely in an if than in an attribute). |
Yes, this is true for attributes, and yes this should be documented. |
a9aeb58
to
711fcfd
Compare
One consideration, currently I'm using But one problem is, that that means, we need the custom We could instead use our own |
Codecov Report
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. @@ Coverage Diff @@
## main #34 +/- ##
==========================================
- Coverage 77.31% 77.23% -0.09%
==========================================
Files 11 12 +1
Lines 692 751 +59
==========================================
+ Hits 535 580 +45
- Misses 157 171 +14
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
I am think current approach with custom trait and Infallible is good enough. I‘d rather have adapter (wrapper type, or macro) that will derive implementation from ToTokens/Parse. For those who want implementation of this trait effortlessly. |
Awesome! |
fixes #11