Trait NodeExt

Source
pub trait NodeExt
where Self: Sized,
{
Show 16 methods // Required methods fn children(&self) -> &RefCell<Vec<Node>>; fn data(&self) -> &NodeData; fn append_children(&self, children: Vec<Node>); fn append_child(&self, child: Node); // Provided methods fn tag_name(&self) -> Option<String> { ... } fn attr(self, name: &str, value: &str) -> Self { ... } fn borrow_attr(&self, name: &str, value: &str) { ... } fn attrs(self, attributes: Vec<(&str, &str)>) -> Self { ... } fn borrow_attrs(&self, attributes: Vec<(&str, &str)>) { ... } fn find_attribute(&self, attribute_name: &str) -> Option<usize> { ... } fn attribute_eq(&self, attribute_name: &str, value: &str) -> bool { ... } fn add_class(&self, class_value: &str) { ... } fn remove_class(&self, class_value: &str) { ... } fn has_class(&self, class_value: &str) -> bool { ... } fn toggle_class(&self, class_value: &str) { ... } fn remove_attribute(&self, name: &str) { ... }
}
Expand description

Methods for easy interaction with a DOM Node.

Required Methods§

Source

fn children(&self) -> &RefCell<Vec<Node>>

The children of this node.

Source

fn data(&self) -> &NodeData

The NodeData.

Source

fn append_children(&self, children: Vec<Node>)

Appends the given children to the node.

Source

fn append_child(&self, child: Node)

Appends the given child to the node.

Provided Methods§

Source

fn tag_name(&self) -> Option<String>

Returns the tag name as string if available.

Source

fn attr(self, name: &str, value: &str) -> Self

Adds an Attribute with given name and value to the node.

If the attribute is already present, it will be overridden.

Examples found in repository?
examples/hello-world.rs (line 15)
3fn main() {
4    let valid_html = document(
5        LanguageTag::parse("en-US").unwrap(),
6        head(vec![
7            link("text/css", "/static/css/main.css"),
8        ]),
9        body(vec![
10            h1(vec![text("Hello World!")]),
11            p(vec![text("This is the first paragraph created with lewp-html!")])
12                .attrs(vec![("class", "prelude"), ("id", "first-paragraph")]),
13            h2(vec![text("The elegant way to create HTML!")]),
14            p(vec![text("Creating HTML has never been easier. This paragraph is highlighted!")])
15                .attr("class", "highlighted"),
16        ]),
17    )
18    .into_html();
19    println!("{}", valid_html);
20}
Source

fn borrow_attr(&self, name: &str, value: &str)

Adds an Attribute with given name and value to the node without consuming self.

If the attribute is already present, it will be overridden.

Source

fn attrs(self, attributes: Vec<(&str, &str)>) -> Self

Adds a list of attributes to the node.

The attributes are tuples of name and value. Attributes that are already set are being overridden.

Examples found in repository?
examples/hello-world.rs (line 12)
3fn main() {
4    let valid_html = document(
5        LanguageTag::parse("en-US").unwrap(),
6        head(vec![
7            link("text/css", "/static/css/main.css"),
8        ]),
9        body(vec![
10            h1(vec![text("Hello World!")]),
11            p(vec![text("This is the first paragraph created with lewp-html!")])
12                .attrs(vec![("class", "prelude"), ("id", "first-paragraph")]),
13            h2(vec![text("The elegant way to create HTML!")]),
14            p(vec![text("Creating HTML has never been easier. This paragraph is highlighted!")])
15                .attr("class", "highlighted"),
16        ]),
17    )
18    .into_html();
19    println!("{}", valid_html);
20}
Source

fn borrow_attrs(&self, attributes: Vec<(&str, &str)>)

Adds a list of attributes to the node without consuming self.

The attributes are tuples of name and value. Attributes that are already set are being overridden.

Source

fn find_attribute(&self, attribute_name: &str) -> Option<usize>

Returns the attribute index if present.

Source

fn attribute_eq(&self, attribute_name: &str, value: &str) -> bool

Checks if the given attribute matches the value.

Source

fn add_class(&self, class_value: &str)

Adds value to the class attribute. Adds the class attribute if it is not present.

Source

fn remove_class(&self, class_value: &str)

Removes the given value from the class attribute.

Source

fn has_class(&self, class_value: &str) -> bool

True if value is available in class attribute.

Source

fn toggle_class(&self, class_value: &str)

Toggles the given value of the class attribute. Creates the class attribute if not set yet.

Source

fn remove_attribute(&self, name: &str)

Removes the attribute with the given name. Does nothing if the attribute does not exist. This method does not compare its values.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§