Skip to content

Commit c431fc2

Browse files
committed
update root crate documentation
1 parent 4c6d3e3 commit c431fc2

File tree

3 files changed

+34
-19
lines changed

3 files changed

+34
-19
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
2222
* `attr::maxlength_u16`
2323

2424

25+
### Documentation
26+
27+
* Root crate example slightly improved
28+
29+
2530
## [1.5.0] - 2024-12-16
2631

2732
### Deprecated

README.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ This rust library provides a simple and efficient way to generate HTML using Rus
1111
with an intuitive and composable API to create HTML elements.
1212

1313
```rust
14-
use fun_html::{attr::class, elt::h1};
14+
use fun_html::{attr, elt};
1515

16-
let greeting = h1(
17-
[class(["bold"])], // <-- attributes
16+
let greeting = elt::h1(
17+
[attr::class(["bold"])], // <-- attributes
1818
["Hello world!".into()], // <-- children
1919
);
2020
assert_eq!(greeting.to_string(), r#"<h1 class="bold">Hello world!</h1>"#);
@@ -23,14 +23,20 @@ assert_eq!(greeting.to_string(), r#"<h1 class="bold">Hello world!</h1>"#);
2323
Because those are simple rust functions, it is easy to leverage rust features like conditions, loops and iterators:
2424

2525
```rust
26-
let list_values = true;
27-
let element = if list_values {
28-
ul([], (1..=3).map(|n| li([], [n.to_string().into()])))
29-
} else {
30-
text("no value")
26+
use fun_html::{elt, Element};
27+
28+
fn list_view(items: Vec<i32>) -> Element {
29+
if !items.is_empty(){
30+
elt::ul([], items.into_iter().map(|item| elt::li([], [item.to_string().into()])))
31+
} else {
32+
elt::text("no item")
33+
}
3134
};
3235

33-
assert_eq!(element.to_string(), "<ul><li>1</li><li>2</li><li>3</li></ul>")
36+
assert_eq!(
37+
list_view((1..=3).collect()).to_string(),
38+
"<ul><li>1</li><li>2</li><li>3</li></ul>"
39+
);
3440
```
3541

3642
> [!NOTE]

src/lib.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
//! All text and attribute values are automatically escaped to ensure safe and valid HTML output.
1616
//!
1717
//! ```
18-
//! use fun_html::{attr::class, elt::h1};
18+
//! use fun_html::{attr, elt};
1919
//!
20-
//! let greeting = h1(
21-
//! [class(["bold"])], // <-- attributes
20+
//! let greeting = elt::h1(
21+
//! [attr::class(["bold"])], // <-- attributes
2222
//! ["Hello world!".into()], // <-- children
2323
//! );
2424
//! assert_eq!(greeting.to_string(), r#"<h1 class="bold">Hello world!</h1>"#);
@@ -27,16 +27,20 @@
2727
//! Because those are simple rust functions, it is easy to leverage rust features like conditions, loops and iterators:
2828
//!
2929
//! ```
30-
//! # use fun_html::{elt::{li,ul,text}};
30+
//! use fun_html::{elt, Element};
3131
//!
32-
//! let list_values = true;
33-
//! let element = if list_values {
34-
//! ul([], (1..=3).map(|n| li([], [n.to_string().into()])))
35-
//! } else {
36-
//! text("no value")
32+
//! fn list_view(items: Vec<i32>) -> Element {
33+
//! if !items.is_empty(){
34+
//! elt::ul([], items.into_iter().map(|item| elt::li([], [item.to_string().into()])))
35+
//! } else {
36+
//! elt::text("no item")
37+
//! }
3738
//! };
3839
//!
39-
//! assert_eq!(element.to_string(), "<ul><li>1</li><li>2</li><li>3</li></ul>")
40+
//! assert_eq!(
41+
//! list_view((1..=3).collect()).to_string(),
42+
//! "<ul><li>1</li><li>2</li><li>3</li></ul>"
43+
//! );
4044
//! ```
4145
//!
4246
//! ## Escape hatches

0 commit comments

Comments
 (0)