pub struct Element<'a> { /* private fields */ }

Implementations

Assign a class to this element.

use sidoc_html5::Element;
let element = Element::new("p")
  .class("warning");

Assign a “flag attribute” to the element.

Flag attributes do not have (explicit) values, and are used to mark elements as selected or checked and such.

use sidoc_html5::Element;
let element = Element::new("input")
  .raw_attr("type", "checkbox")
  .flag("checked");

Conditionally add a flag attribute.

Flag attributes do not have (explicit) values, and are used to mark elements as selected or checked and such.

use sidoc_html5::Element;
for id in &[1, 2, 3] {
  let element = Element::new("option")
    .flag_if(*id == 3, "selected");
}

Add an attribute.

The attribute value is escaped as needed.

Note: If the value is guaranteed not to require escaping then prefer the Element::raw_attr() method instead.

use sidoc_html5::Element;
let elem = Element::new("input")
  .attr("name", "foo");

Conditionally add an attribute.

The value is escaped as needed.

Add a data--prefixed attribute.

The attribute value is escaped as needed.

use sidoc_html5::Element;
let elem = Element::new("tr")
  .data_attr("name", "foo");

Conditionally add a boolean data- attribute.

Add a data-foo=true attribute to an element:

use sidoc_html5::Element;
let val = 7;
let elem = Element::new("p")
  .data_flag_if(val > 5, "foo");

Add an attribute if its optional value is Some(); ignore it otherwise.

The value is escaped as needed.

Note: If the value is guaranteed to not needing escaping then prefer the Element::raw_optattr() method instead.

use sidoc_html5::Element;
let something = Some("something");
let nothing: Option<&str> = None;
let elem = Element::new("form")
  .optattr("id", something)
  .optattr("name", nothing);

If an an optional input value is set, apply a function on the contained value to allow it to generate the actual attribute value. Do nothing if the optional value is None.

The value returned by the closure is escaped as needed.

use sidoc_html5::Element;
let something = Some("something");
let elem = Element::new("p")
  .optattr_map("id", something, |v| {
    // Have a value -- format it and append "-aboo" to it.
    format!("{}-aboo", v)
  });

If an an optional input value is set, apply a function on the contained value.

Conditionally call a function to add an attribute with a generated value.

use sidoc_html5::Element;
let sv = vec!["foo".to_string(), "bar".to_string()];
Element::new("body")
  .map_attr_if(!sv.is_empty(), "data-mylist", &sv, |v: &Vec<String>| {
    v.join(",")
  });

Methods that don’t transform the input.

Add an attribute.

The attribute value is not escaped.

use sidoc_html5::Element;
let elem = Element::new("form")
  .raw_attr("id", "foo");

Add an attribute if its optional value is Some(); ignore it otherwise.

The value is assumed not to require escaping.

use sidoc_html5::Element;
let ss = "something".to_string();
let something = Some(&ss);
let nothing = None::<&String>;
let elem = Element::new("form")
  .raw_optattr("id", something)
  .raw_optattr("name", nothing);

Add an attribute if a condition is true.

The attribute value is not escaped.

Call a closure for adding child nodes.

use sidoc_html5::Element;
let mut bldr = sidoc::Builder::new();
Element::new("div")
  .sub(&mut bldr, |bldr| {
    Element::new("br")
      .add_empty(bldr);
});

Methods inserting element into a sidoc context.

Consume self and add a empty tag representation of element to a sidoc builder.

An empty/void tag comes is one which does not have a closing tag: <tagname foo="bar">.

Consume self and add a tag containing text content between the opening and closing tag to the supplied sidoc builder.

The supplied text is escaped as needed.

use sidoc_html5::Element;
let mut bldr = sidoc::Builder::new();
let elem = Element::new("textarea")
  .raw_attr("rows", 8)
  .raw_attr("cols", 32)
  .add_content("This is the text content", &mut bldr);

The example above should generate: <textarea rows="8" cols="32">This is the text content</textarea>

Consume self and add a tag containing text content between the opening and closing tag to the supplied sidoc builder.

The supplied text is not escaped.

use sidoc_html5::Element;
let mut bldr = sidoc::Builder::new();
let elem = Element::new("button")
  .add_raw_content("Do Stuff", &mut bldr);

The example above should generate: <button>Do Stuff</button>

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.