-
Notifications
You must be signed in to change notification settings - Fork 10
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
variant of html-to-string-macro
which returns something that impl ToString
(return the nodes themselves)
#25
Comments
html-to-string-macro
which returns something that impl ToString
(return the nodes themselves)html-to-string-macro
which returns something that impl ToString
(return the nodes themselves)
I opened and discussed a similar idea in the original fork of this project with the author: Quoting:
I agree it would probably be a big performance benefit, though I suppose we should measure it before making definitive claims. (To be fair, it shouldn't be hard to show that reducing copying and temporary allocations improves performance.) |
i've made an implementation. shall i push to a fork and let you take a look? also, i didn't really think about the zero-copy. i wanted to make mine as easy-to-use as possible. However, it does use |
alright @infogulch, i've got this test case passing! i'll push my code and update you when it's ready to take a look at. use html_node::{html, text};
#[test]
fn works() {
let html = html!(
<div>
<ul>
{ (0..5).map(|i| html!(<li>{ text!("Item {i}") }</li>)) }
</ul>
</div>
);
let expected = concat!(
"<div>",
"<ul>",
"<li>Item 0</li>",
"<li>Item 1</li>",
"<li>Item 2</li>",
"<li>Item 3</li>",
"<li>Item 4</li>",
"</ul>",
"</div>",
);
assert_eq!(html.to_string(), expected);
} |
pinging @vldm as well ^ |
@infogulch take a look! :) |
Oh so it works by implementing the format trait which makes sense. So would you be able to use something like |
@infogulch - yep! the |
@vidhanio So if you want, we can move html-node to I would like to keep original |
@vldm - maybe there could be a section called "powered by rstml" in the readme that this could be put under? then maybe you could create an example which uses |
@vldm @infogulch i think y'all would be interested in taking a look at this, i added a super cool new feature! |
Interesting, I like how you can define custom elements and attributes. In my case I used |
@infogulch what a coincidence, i originally had the idea to create this to make HTMX in rust much easier and well, the cool thing about the |
I'm delighted to have played a small part in your inspiration to pursue this project! As far as I know htmx only works with the |
i'm away from the keyboard rn, but i have an idea for how to support |
@infogulch... a few hours later, i've cooked up something AMAZING #[derive(Debug, Clone)]
struct Location {
x: i32,
y: i32,
}
impl Display for Location {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{},{}", self.x, self.y)
}
}
typed::element! {
MyElement("my-element") {
location: Location,
}
}
typed::attributes! {
[Hx] {
hx_boost: bool,
}
}
// vvvvvvvvvvvvvvvvvvvvvvvvvvvvv attribute extension list
typed::html! { (hx: Hx, extras)
...
}
and you can have as many extensions as you want! and then, you can create your own decl macro for your crate that wraps macro_rules! html_hx {
($($tt:tt)*) => {::html_node::typed::html!((hx: $crate::Hx) $($tt)*)};
} |
typed_html
does this, and i believe it allows them to do cool things like having iterators in the macro. currently, i believe you would have to use thehtml!
macro to create strings in the loop then join them at the end, which seems kinda jank.would this be possible?
edit: written by myself: https://github.com/vidhanio/html-node
The text was updated successfully, but these errors were encountered: