-
-
Notifications
You must be signed in to change notification settings - Fork 586
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
Allow literal string as class in view macro #500
Conversation
if nodes.is_empty() { | ||
let span = Span::call_site(); | ||
quote_spanned! { | ||
span => leptos::Unit | ||
match nodes.len() { | ||
0 => { | ||
let span = Span::call_site(); | ||
quote_spanned! { | ||
span => leptos::Unit | ||
} | ||
} | ||
} else if nodes.len() == 1 { | ||
root_node_to_tokens_ssr(cx, &nodes[0], global_class) | ||
} else { | ||
fragment_to_tokens_ssr(cx, Span::call_site(), nodes, global_class) | ||
1 => root_node_to_tokens_ssr(cx, &nodes[0], global_class), | ||
_ => fragment_to_tokens_ssr(cx, Span::call_site(), nodes, global_class), | ||
} | ||
} else if nodes.is_empty() { | ||
let span = Span::call_site(); | ||
quote_spanned! { | ||
span => leptos::Unit | ||
} | ||
} else if nodes.len() == 1 { | ||
node_to_tokens(cx, &nodes[0], TagType::Unknown, global_class) | ||
} else { | ||
fragment_to_tokens( | ||
cx, | ||
Span::call_site(), | ||
nodes, | ||
true, | ||
TagType::Unknown, | ||
global_class, | ||
) | ||
match nodes.len() { | ||
0 => { | ||
let span = Span::call_site(); | ||
quote_spanned! { | ||
span => leptos::Unit | ||
} | ||
} | ||
1 => node_to_tokens(cx, &nodes[0], TagType::Unknown, global_class), | ||
_ => fragment_to_tokens( | ||
cx, | ||
Span::call_site(), | ||
nodes, | ||
true, | ||
TagType::Unknown, | ||
global_class, | ||
), | ||
} |
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.
This is just a rearrangement, no functional changes. While reading it this is how I rearranged the logic in my head and figured I'd update the code to be the same. Happy to revert if the old way is preferred.
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.
Looks great, thanks!
38f5202
to
97f1795
Compare
Thanks, this looks great and I appreciate the clean-up work here too. |
Render literal string as class in view macro correctly. This is currently allowed but produces incorrect html.
this code:
Pre this PR:
Notice there's an extra attribute
scope-class""=""
.This is because the quotes in
"scope-class"
get rendered and the browser turns that into its own attribute.Post this PR:
The class renders correctly.
As a side note, the
Header
andBanner
component that are inside of thescope-class
scope don't have thescope-class
applied. I don't know if this is intentional because they are components, but there it is.This PR also includes updated error messaging if a user tries to use a class but forgets the trailing comma.
Pre this PR it would say:
Now it says: