pub struct Document {
pub lang: Option<String>,
pub head: Element,
pub body: Element,
}Expand description
A complete HTML document: a language, a <head> and a <body>.
The Document owns the doctype — Document::render prepends <!DOCTYPE html>\n,
while Document::root gives you the bare <html> element without it.
§Rendering default
Document::render defaults to pretty, while Element::render defaults to
compact. That asymmetry is in the Swift original and the golden fixtures depend on it,
so it is preserved rather than tidied up.
§Examples
use winged_rust::prelude::*;
use winged_rust::Document;
let page = Document::new(Some("pt-BR"))
.head_children([title().text("RideKeeper")])
.body_children([h1().text("Track every service")]);
assert!(page.render().starts_with("<!DOCTYPE html>\n<html lang=\"pt-BR\">"));Fields§
§lang: Option<String>The document language, rendered as <html lang="…">. Omitted when None.
head: ElementThe <head> element.
body: ElementThe <body> element.
Implementations§
Source§impl Document
impl Document
Sourcepub fn with_parts(lang: Option<&str>, head: Element, body: Element) -> Self
pub fn with_parts(lang: Option<&str>, head: Element, body: Element) -> Self
Creates a document from an existing <head> and <body>.
Sourcepub fn head_children<N: Into<Node>>(
self,
children: impl IntoIterator<Item = N>,
) -> Self
pub fn head_children<N: Into<Node>>( self, children: impl IntoIterator<Item = N>, ) -> Self
Appends nodes to the <head>.
Sourcepub fn body_children<N: Into<Node>>(
self,
children: impl IntoIterator<Item = N>,
) -> Self
pub fn body_children<N: Into<Node>>( self, children: impl IntoIterator<Item = N>, ) -> Self
Appends nodes to the <body>.
Sourcepub fn root(&self) -> Element
pub fn root(&self) -> Element
The <html> element, without the doctype.
Kept separate from render because the static site generator and
several tests want the tree rather than the serialized page.
Sourcepub fn render_with(&self, options: &RenderOptions) -> String
pub fn render_with(&self, options: &RenderOptions) -> String
Renders the document with the given options, prefixed by the doctype.
Sourcepub fn render(&self) -> String
pub fn render(&self) -> String
Renders the document pretty-printed — the Swift default for a document.
Sourcepub fn render_compact(&self) -> String
pub fn render_compact(&self) -> String
Renders the document on a single line.
Trait Implementations§
impl Eq for Document
impl StructuralPartialEq for Document
Auto Trait Implementations§
impl Freeze for Document
impl RefUnwindSafe for Document
impl Send for Document
impl Sync for Document
impl Unpin for Document
impl UnsafeUnpin for Document
impl UnwindSafe for Document
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more