pub struct Nav { /* private fields */ }Expand description
Builder for <nav> elements.
Represents a navigation section containing links to other pages or sections within the page.
§Examples
use html_generator::elements::{Nav, SemanticElement};
let html = Nav::new()
.aria_label("Primary")
.child(r#"<a href="/">Home</a>"#)
.build();
assert!(html.contains("<nav"));
assert!(html.contains(r#"aria-label="Primary""#));Implementations§
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new builder with default values.
§Examples
use html_generator::elements::{Article, SemanticElement};
let html = Article::new().build();
assert!(html.contains("<article"));Sourcepub fn id(self, id: &str) -> Self
pub fn id(self, id: &str) -> Self
Sets the id attribute.
§Examples
use html_generator::elements::{Article, SemanticElement};
let html = Article::new().id("post-1").build();
assert!(html.contains(r#"id="post-1""#));Sourcepub fn class(self, class: &str) -> Self
pub fn class(self, class: &str) -> Self
Sets the class attribute.
§Examples
use html_generator::elements::{Article, SemanticElement};
let html = Article::new().class("post").build();
assert!(html.contains(r#"class="post""#));Sourcepub fn aria_label(self, label: &str) -> Self
pub fn aria_label(self, label: &str) -> Self
Sets the aria-label attribute.
§Examples
use html_generator::elements::{Article, SemanticElement};
let html = Article::new().aria_label("Latest post").build();
assert!(html.contains(r#"aria-label="Latest post""#));Sourcepub fn aria_labelledby(self, id: &str) -> Self
pub fn aria_labelledby(self, id: &str) -> Self
Sets the aria-labelledby attribute.
§Examples
use html_generator::elements::{Article, SemanticElement};
let html = Article::new().aria_labelledby("title-1").build();
assert!(html.contains(r#"aria-labelledby="title-1""#));Sourcepub fn attr(self, key: &str, value: &str) -> Self
pub fn attr(self, key: &str, value: &str) -> Self
Adds a custom attribute.
§Examples
use html_generator::elements::{Article, SemanticElement};
let html = Article::new().attr("data-id", "42").build();
assert!(html.contains(r#"data-id="42""#));Sourcepub fn child(self, html: &str) -> Self
pub fn child(self, html: &str) -> Self
Appends child HTML content.
§Examples
use html_generator::elements::{Article, SemanticElement};
let html = Article::new().child("<p>Body</p>").build();
assert!(html.contains("<p>Body</p>"));Trait Implementations§
Auto Trait Implementations§
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more