You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
it has type checking (although just checks the validity of the attribute name, not the validity of their content, as it is all string-based) and allows even defining your own typed elements, with custom data types for the attributes! here is an example of the syntax:
Minimal Example
use html_node::{typed::self, elements::div};// ^^^^^^^^^^^^^ bring the `div` element definition into scope// `typed::elements` contains every default html elements'// type defintions.assert_eq!(
typed::html!(<div id="test">hi</div>).to_string(),r#"<div id="test">hi</div>"#);// fails to compile, saying `DivAttributes` does not have field `cool_attr`// typed::html!(<div cool-attr="hi" id="test>hi</div>)// compiles!
typed::html!(<div data-cool-attr="hi" id="test">hi</div>)
Maximal Example
use std::fmt::Display;use html_node::{typed::self, elements::div};#[derive(Debug,Clone)]structLocation{x:i32,y:i32,}implDisplayforLocation{fnfmt(&self,f:&mut std::fmt::Formatter<'_>) -> std::fmt::Result{write!(f,"{},{}",self.x,self.y)}}// generates all global attributes as well as those defined in the macro!
typed::element! {CustomElement("custom-element"){
location:Location,}}let html = typed::html!(
<div class="example">
<CustomElement id="lol" location=Location{ x:1, y:2} />
</div>
);assert_eq!(
html.to_string(),r#"<div class="example"><custom-element id="lol" location="1,2"></custom-element></div>"#);
the cool thing is that the typing is only at compile-time, and it all turns into the same Node type, so you can put typed elements inside untyped elements if needed.
The text was updated successfully, but these errors were encountered:
hi!
i was looking for a crate to do in-rust html templating, found this crate, and unfortunately it looked unmaintained.
i've been working on my own crate for this for a while, and i thought it would be useful to some people here.
docs.rs
it has type checking (although just checks the validity of the attribute name, not the validity of their content, as it is all string-based) and allows even defining your own typed elements, with custom data types for the attributes! here is an example of the syntax:
Minimal Example
Maximal Example
the cool thing is that the typing is only at compile-time, and it all turns into the same
Node
type, so you can put typed elements inside untyped elements if needed.The text was updated successfully, but these errors were encountered: