Crates.io | fun-html |
lib.rs | fun-html |
version | 1.3.0 |
source | src |
created_at | 2024-11-03 09:40:21.167946 |
updated_at | 2024-11-05 12:18:14.260365 |
description | HTML as a rust function |
homepage | |
repository | https://github.com/jcornaz/fun-html |
max_upload_size | |
id | 1433526 |
size | 53,920 |
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
std
: enabled by default. must be disabled to compile to no_std
rocket_v05
: implements the Responder
trait from rocket 0.5 for [Document
] and [Element
]
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).
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.