pub struct Document<Head, Body> { /* private fields */ }Expand description
Application-provided head and body ready for document composition.
Implementations§
Source§impl<Head, Body> Document<Head, Body>
impl<Head, Body> Document<Head, Body>
Sourcepub const fn new(head: Head, body: Body) -> Document<Head, Body>
pub const fn new(head: Head, body: Body) -> Document<Head, Body>
Starts document composition with application-owned head and body outputs.
Sourcepub fn with_assets(self, assets: &DocumentAssets) -> Document<Head, Body>
pub fn with_assets(self, assets: &DocumentAssets) -> Document<Head, Body>
Delivers build-generated assets, such as Trunk’s stylesheets, scripts and WASM bootstrap, with the rendered document.
§Examples
use serenade_view::{Document, DocumentAssets};
let assets = DocumentAssets::new(
r#"<link rel="stylesheet" href="/app-1a2b.css">"#,
r#"<script type="module" src="/app-1a2b.js"></script>"#,
);
let rendered = Document::new("<title>Home</title>", "<main>Welcome</main>")
.with_assets(&assets)
.render()?;
assert!(rendered.as_html().contains(r#"href="/app-1a2b.css"></head>"#));
assert!(rendered.as_html().contains(r#"</script></body>"#));Sourcepub fn render(self) -> Result<RenderedDocument, ViewError>where
DefaultDocumentTemplate: DocumentTemplate<Head, Body>,
pub fn render(self) -> Result<RenderedDocument, ViewError>where
DefaultDocumentTemplate: DocumentTemplate<Head, Body>,
Renders the document through the framework’s default template.
String inputs must already be rendered and escaped; they are not sanitized.
View factories require the leptos-ssr feature and a process-wide SSR
executor initialized with initialize_leptos_ssr or by the application.
§Examples
use serenade_view::Document;
let document = Document::new("<title>Home</title>", "<main>Welcome</main>");
let rendered = document.render()?;
assert!(rendered.as_html().contains("<main>Welcome</main>"));§Errors
Returns the default template’s rendering error, or an asset insertion
error as described for Self::render_with.
Sourcepub fn render_with(
self,
template: impl DocumentTemplate<Head, Body>,
) -> Result<RenderedDocument, ViewError>
pub fn render_with( self, template: impl DocumentTemplate<Head, Body>, ) -> Result<RenderedDocument, ViewError>
Renders the document through an application-provided template.
With the leptos-ssr feature, a template can be a function or closure
accepting the head and body DocumentSlots. Both slots and the
template render under the same request-scoped owner. The application
must initialize the SSR executor before rendering view factories.
§Examples
use serenade_view::{Document, DocumentParts, DocumentTemplate, ViewError};
struct FrenchTemplate;
impl DocumentTemplate<&str, &str> for FrenchTemplate {
fn render(self, parts: DocumentParts<&str, &str>) -> Result<String, ViewError> {
Ok(format!(
"<!DOCTYPE html><html lang=\"fr\"><head>{}</head><body>{}</body></html>",
parts.head, parts.body
))
}
}
let document = Document::new("<title>Accueil</title>", "<main>Bienvenue</main>");
let rendered = document.render_with(FrenchTemplate)?;
assert!(rendered.as_html().contains("<html lang=\"fr\">"));§Errors
Returns the template’s rendering error, or an error when assets are
configured and the rendered document lacks </head> or </body>.
Trait Implementations§
impl<Head, Body> Eq for Document<Head, Body>
impl<Head, Body> StructuralPartialEq for Document<Head, Body>
Auto Trait Implementations§
impl<Head, Body> Forget for Document<Head, Body>
impl<Head, Body> Freeze for Document<Head, Body>where
DocumentParts<Head, Body>: Freeze,
impl<Head, Body> Move for Document<Head, Body>
impl<Head, Body> RefUnwindSafe for Document<Head, Body>where
DocumentParts<Head, Body>: RefUnwindSafe,
impl<Head, Body> Send for Document<Head, Body>where
DocumentParts<Head, Body>: Send,
impl<Head, Body> Sync for Document<Head, Body>where
DocumentParts<Head, Body>: Sync,
impl<Head, Body> Unpin for Document<Head, Body>where
DocumentParts<Head, Body>: Unpin,
impl<Head, Body> UnsafeUnpin for Document<Head, Body>where
DocumentParts<Head, Body>: UnsafeUnpin,
impl<Head, Body> UnwindSafe for Document<Head, Body>where
DocumentParts<Head, Body>: UnwindSafe,
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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