fun-html

Crates.iofun-html
lib.rsfun-html
version1.3.0
sourcesrc
created_at2024-11-03 09:40:21.167946
updated_at2024-11-05 12:18:14.260365
descriptionHTML as a rust function
homepage
repositoryhttps://github.com/jcornaz/fun-html
max_upload_size
id1433526
size53,920
Jonathan Cornaz (jcornaz)

documentation

README

fun-html

Crates.io Version License MSRV Build Status docs.rs

This rust library provides a simple and efficient way to generate HTML using Rust functions, with an intuitive and composable API to create HTML elements.

use fun_html::{attr::class, elt::h1};

let greeting = h1(
  [class(["bold"])], // <-- attributes
  ["Hello world!".into()], // <-- children
);
assert_eq!(greeting.to_string(), r#"<h1 class="bold">Hello world!</h1>"#);

Because those are simple rust functions, it is easy to leverage rust features like conditions, loops and iterators:

let list_values = true;
let element = if list_values {
 ul([], (1..=3).map(|n| li([], [n.to_string().into()])))
} else {
 text("no value")
};

assert_eq!(element.to_string(), "<ul><li>1</li><li>2</li><li>3</li></ul>")

[!NOTE]

The crate fun-htmx provide additional attributes for use with HTMX

Feature flags

MSRV

The minimum supported rust version is currently 1.60.

It will be updated when required, and that will not be considered a breaking change (it can happen in a minor version).

MIT License

Copyright (c) 2024 Jonathan Cornaz

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Commit count: 74

cargo fmt