https://github.com/swlkr/hyped
Write html using plain rust functions
https://github.com/swlkr/hyped
Last synced: 9 months ago
JSON representation
Write html using plain rust functions
- Host: GitHub
- URL: https://github.com/swlkr/hyped
- Owner: swlkr
- License: mit
- Created: 2024-01-03T23:51:08.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-02-07T21:45:10.000Z (almost 2 years ago)
- Last Synced: 2025-03-26T06:11:16.506Z (10 months ago)
- Language: Rust
- Homepage:
- Size: 20.5 KB
- Stars: 31
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# hyped
hyped offers an ergonomic way to render html from plain rust functions
```sh
cargo add hyped
```
# Write some html
```rust
use hyped::*;
fn render_to_string(element: Element) -> String {
render((
doctype(),
html((
head((title("title"), meta().charset("utf-8"))),
body(element)
))
))
}
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
assert_eq!(
render_to_string(div("hyped")),
"title
hyped"
)
}
}
```
# Custom attributes
```rust
use hyped::*;
fn htmx_input() -> Element {
input()
.attr("hx-post", "/")
.attr("hx-target", ".target")
.attr("hx-swap", "outerHTML")
.attr("hx-push-url", "false")
}
fn main() {
let html: String = render(htmx_input());
// html ==
}
```
# Custom elements
```rust
use hyped::*;
fn turbo_frame(children: Element) -> Element {
element("turbo-frame", children)
}
fn main() {
let html: String = render(turbo_frame(div("inside turbo frame")).id("id"));
// html ==
//
//
inside turbo frame
//
}
```