pub struct Section { /* private fields */ }Expand description
Builder for <section> elements.
Represents a standalone section of a document, typically with a heading.
§Examples
use html_generator::elements::{Section, SemanticElement};
let html = Section::new().id("intro").child("<h2>Intro</h2>").build();
assert!(html.contains("<section"));
assert!(html.contains(r#"id="intro""#));Implementations§
Source§impl Section
impl Section
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§
impl Freeze for Section
impl RefUnwindSafe for Section
impl Send for Section
impl Sync for Section
impl Unpin for Section
impl UnsafeUnpin for Section
impl UnwindSafe for Section
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