pub struct Element<'a, T>where
T: ElementType,{
pub name: Tag<'a>,
pub attributes: Attributes<'a>,
pub children: T,
}
Expand description
The html element type. This is the most common Note: if children is None, then it is handled as an empty element, this is different than having no children
Fields§
§name: Tag<'a>
§attributes: Attributes<'a>
§children: T
Implementations§
Source§impl<'a> Element<'a, ()>
impl<'a> Element<'a, ()>
Sourcepub fn external_style(url: Url) -> Self
pub fn external_style(url: Url) -> Self
An external stylesheet (link tag)
Source§impl<'a> Element<'a, Vec<Node<'a>>>
impl<'a> Element<'a, Vec<Node<'a>>>
Sourcepub fn push<N>(&mut self, node: N)
pub fn push<N>(&mut self, node: N)
Pushes a child not into the element Note: you can also do this yourself, but this is nicer as it will coerce anything that can be a node into a node
Examples found in repository?
9fn main() {
10 // Create a link
11 let link = {
12 let label = Text::create("Click Me");
13 let url = Value::create("http://google.com").unwrap();
14 // Anchor is a helper for the typical case
15 Element::anchor(url, label)
16 };
17 // Create the body. Sugar function takes a list of child nodes
18 let body = Element::body(vec![link]);
19
20 // Create a header manually. There isn't a sugar function here
21 let header = {
22 let mut el = Element::<Vec<Node>>::create(Tag::HEADER);
23 let text = Text::create("Hello world");
24 let title = Element::title(text);
25 el.push(title);
26 el
27 };
28 let html = Element::html(Value::EN, header, body);
29
30 // Convert an element into a node
31 let node: Node = html.into();
32
33 // Nodes can be turned into HTML formatted strings
34 let string: String = node.into();
35
36 println!("{}", string);
37}
Sourcepub fn anchor(url: Value<'a>, label: Text) -> Self
pub fn anchor(url: Value<'a>, label: Text) -> Self
Helper function to create a link given the label and url
Examples found in repository?
9fn main() {
10 // Create a link
11 let link = {
12 let label = Text::create("Click Me");
13 let url = Value::create("http://google.com").unwrap();
14 // Anchor is a helper for the typical case
15 Element::anchor(url, label)
16 };
17 // Create the body. Sugar function takes a list of child nodes
18 let body = Element::body(vec![link]);
19
20 // Create a header manually. There isn't a sugar function here
21 let header = {
22 let mut el = Element::<Vec<Node>>::create(Tag::HEADER);
23 let text = Text::create("Hello world");
24 let title = Element::title(text);
25 el.push(title);
26 el
27 };
28 let html = Element::html(Value::EN, header, body);
29
30 // Convert an element into a node
31 let node: Node = html.into();
32
33 // Nodes can be turned into HTML formatted strings
34 let string: String = node.into();
35
36 println!("{}", string);
37}
Sourcepub fn body<N>(children: Vec<N>) -> Self
pub fn body<N>(children: Vec<N>) -> Self
Creates a body element. Note consumes the children vector
Examples found in repository?
9fn main() {
10 // Create a link
11 let link = {
12 let label = Text::create("Click Me");
13 let url = Value::create("http://google.com").unwrap();
14 // Anchor is a helper for the typical case
15 Element::anchor(url, label)
16 };
17 // Create the body. Sugar function takes a list of child nodes
18 let body = Element::body(vec![link]);
19
20 // Create a header manually. There isn't a sugar function here
21 let header = {
22 let mut el = Element::<Vec<Node>>::create(Tag::HEADER);
23 let text = Text::create("Hello world");
24 let title = Element::title(text);
25 el.push(title);
26 el
27 };
28 let html = Element::html(Value::EN, header, body);
29
30 // Convert an element into a node
31 let node: Node = html.into();
32
33 // Nodes can be turned into HTML formatted strings
34 let string: String = node.into();
35
36 println!("{}", string);
37}
Sourcepub fn html(
lang: Value<'a>,
header: Element<'a, Vec<Node<'a>>>,
body: Element<'a, Vec<Node<'a>>>,
) -> Self
pub fn html( lang: Value<'a>, header: Element<'a, Vec<Node<'a>>>, body: Element<'a, Vec<Node<'a>>>, ) -> Self
Creates the html element Helper here assumes you have a body and header. as thats’s used pretty much always
Examples found in repository?
9fn main() {
10 // Create a link
11 let link = {
12 let label = Text::create("Click Me");
13 let url = Value::create("http://google.com").unwrap();
14 // Anchor is a helper for the typical case
15 Element::anchor(url, label)
16 };
17 // Create the body. Sugar function takes a list of child nodes
18 let body = Element::body(vec![link]);
19
20 // Create a header manually. There isn't a sugar function here
21 let header = {
22 let mut el = Element::<Vec<Node>>::create(Tag::HEADER);
23 let text = Text::create("Hello world");
24 let title = Element::title(text);
25 el.push(title);
26 el
27 };
28 let html = Element::html(Value::EN, header, body);
29
30 // Convert an element into a node
31 let node: Node = html.into();
32
33 // Nodes can be turned into HTML formatted strings
34 let string: String = node.into();
35
36 println!("{}", string);
37}
Sourcepub fn title(title: Text) -> Self
pub fn title(title: Text) -> Self
Creates a html title, with the supplied text
Examples found in repository?
9fn main() {
10 // Create a link
11 let link = {
12 let label = Text::create("Click Me");
13 let url = Value::create("http://google.com").unwrap();
14 // Anchor is a helper for the typical case
15 Element::anchor(url, label)
16 };
17 // Create the body. Sugar function takes a list of child nodes
18 let body = Element::body(vec![link]);
19
20 // Create a header manually. There isn't a sugar function here
21 let header = {
22 let mut el = Element::<Vec<Node>>::create(Tag::HEADER);
23 let text = Text::create("Hello world");
24 let title = Element::title(text);
25 el.push(title);
26 el
27 };
28 let html = Element::html(Value::EN, header, body);
29
30 // Convert an element into a node
31 let node: Node = html.into();
32
33 // Nodes can be turned into HTML formatted strings
34 let string: String = node.into();
35
36 println!("{}", string);
37}
Sourcepub fn inline_script(text: Text) -> Self
pub fn inline_script(text: Text) -> Self
Creates an inline script in to be used in the head section
Sourcepub fn external_script(url: Url) -> Self
pub fn external_script(url: Url) -> Self
An external script tag
Sourcepub fn inline_style(text: Text) -> Self
pub fn inline_style(text: Text) -> Self
Creates an inline script in to be used in the head section
Source§impl<'a, T> Element<'a, T>where
T: ElementType,
impl<'a, T> Element<'a, T>where
T: ElementType,
Sourcepub fn create(name: Tag<'a>) -> Self
pub fn create(name: Tag<'a>) -> Self
Creates a typical element with children, from the provided tag name. This is the typical case
Examples found in repository?
9fn main() {
10 // Create a link
11 let link = {
12 let label = Text::create("Click Me");
13 let url = Value::create("http://google.com").unwrap();
14 // Anchor is a helper for the typical case
15 Element::anchor(url, label)
16 };
17 // Create the body. Sugar function takes a list of child nodes
18 let body = Element::body(vec![link]);
19
20 // Create a header manually. There isn't a sugar function here
21 let header = {
22 let mut el = Element::<Vec<Node>>::create(Tag::HEADER);
23 let text = Text::create("Hello world");
24 let title = Element::title(text);
25 el.push(title);
26 el
27 };
28 let html = Element::html(Value::EN, header, body);
29
30 // Convert an element into a node
31 let node: Node = html.into();
32
33 // Nodes can be turned into HTML formatted strings
34 let string: String = node.into();
35
36 println!("{}", string);
37}
Sourcepub fn set_bool_attribute(&mut self, key: Attribute<'a>)
pub fn set_bool_attribute(&mut self, key: Attribute<'a>)
Sets the supplied attribute as a ‘boolean’ attribute This means it will just appear in the html, and will not render with a =value eg
Sourcepub fn has_bool_attribute(&self, key: &Attribute<'a>) -> bool
pub fn has_bool_attribute(&self, key: &Attribute<'a>) -> bool
Tests whether the attribute exists. Note this returns true for bool attributes, and valued attributes
Sourcepub fn has_attribute(&self, key: &Attribute<'a>) -> bool
pub fn has_attribute(&self, key: &Attribute<'a>) -> bool
Tests whether the attribute exists. Note this returns false for bool attributes, and true for valued attributes
Sourcepub fn set_attribute(&mut self, key: Attribute<'a>, value: Value<'a>)
pub fn set_attribute(&mut self, key: Attribute<'a>, value: Value<'a>)
Sets the attribute to the supplied value Note: sugar over wrapping the value with some.
Sourcepub fn get_attribute_value(&self, key: &Attribute<'a>) -> &Option<Value<'a>>
pub fn get_attribute_value(&self, key: &Attribute<'a>) -> &Option<Value<'a>>
Returns the value of the supplied key note for bool attributes, this will still be none