vidhanio / hypertext Goto Github PK
View Code? Open in Web Editor NEWA blazing fast type-checked HTML macro crate.
Home Page: https://docs.rs/hypertext
License: MIT License
A blazing fast type-checked HTML macro crate.
Home Page: https://docs.rs/hypertext
License: MIT License
Very exciting crate, Vidhan, thank you! In the main docs it says
it will only render the HTML to a string when you finally call
Renderable::render
at the end. This makes composing nested HTML elements extremely cheap.
But... how DO you create nested html elements?
in html-node
, I have been used to writing a template function, with all the html boilerplate in, and passing in some page-specific html. But this doesn't work, seemingly deliberately in hypertext?
Like this:
fn template(inner: ???) -> ??? {
rsx! {
<html>
<head>
<title>TITLE</title>n
</head>
<body>
{ inner }
</body>
</html>
}
}
fn index_page() -> ??? {
template(rsx! {
<div>
<h1>My Cool Site</h1>
</div>
})
}
How do I pass around pre-rendered html between functions? the return value of rsx!
is a closure, which seems to populate a mutable string? This was very surprising!
Thank you so much for your help!
This would allow easily mapping Options into lazy render functions with macros. The desired effect is that if a value is None, nothing is rendered.
This could also apply to other wrapper types like Arc, Rc, Box, Result, etc.
let user: Option<User> = get_user().await;
maud! {
h1 {
( user.map(|user| maud! { h1 { (user.name) } }) )
}
}
Currently you have to do
maud! {
@if let Some(user) = user {
}
}
Which isn't really awful, except it doesn't compose very well.
This comment on maud explains my use-case well lambda-fairy/maud#240 (comment)
Hello,
Cool library!
I was trying to add support for htmx attributes which use hx-*
convention.
I added
#[allow(dead_code, non_upper_case_globals)]
pub trait HtmxAttributes: GlobalAttributes {
const hx_get: Attribute = Attribute;
const hx_post: Attribute = Attribute;
const hx_target: Attribute = Attribute;
}
impl<T: GlobalAttributes> HtmxAttributes for T {}
but those end up with underscores in the generated html.
Any workarounds?
Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.