hyped

Crates.iohyped
lib.rshyped
version0.1.1
sourcesrc
created_at2024-01-06 19:10:16.444496
updated_at2024-01-17 17:44:39.35751
descriptionAn ergonomic way to render html using plain old rust
homepagehttps://github.com/swlkr/hyped
repositoryhttps://github.com/swlkr/hyped
max_upload_size
id1091146
size16,382
swlkr (swlkr)

documentation

README

hyped

hyped offers an ergonomic way to render html from plain rust functions

cargo add hyped

Write some html

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")),
        "<!DOCTYPE html><html><head><title>title</title></head><body><div>hyped</div></body></html>"
      )
  }
}

Custom attributes

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 == <input hx-post="/" hx-target=".target" hx-swap="outerHTML" hx-push-url="false">
}

Custom elements

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 ==
  // <turbo-frame id="id">
  //   <div>inside turbo frame</div>
  // </turbo-frame>
}
Commit count: 0

cargo fmt