mod getters;
mod renderers;
mod setters;
mod utils;
mod entity;
mod state_setters;
use std::ops::Deref;
pub(crate) use entity::{Entity, EntityMap, Forever};
pub(crate) use utils::*;
#[cfg(engine)]
use super::fn_types::*;
use super::TemplateFn;
#[cfg(engine)]
use crate::utils::ComputedDuration;
use sycamore::{prelude::create_scope, view::View, web::Html};
#[derive(Debug)]
pub struct Template<G: Html> {
pub(crate) inner: Entity<G>,
}
impl<G: Html> Deref for Template<G> {
type Target = TemplateInner<G>;
fn deref(&self) -> &Self::Target {
&self.inner
}
}
impl<G: Html> Template<G> {
pub fn build(path: &str) -> TemplateInner<G> {
TemplateInner::new(path)
}
}
pub struct TemplateInner<G: Html> {
path: String,
pub(crate) view: TemplateFn<G>,
#[cfg(engine)]
pub(crate) head: Option<HeadFn>,
#[cfg(engine)]
pub(crate) set_headers: Option<SetHeadersFn>,
#[cfg(engine)]
get_build_paths: Option<GetBuildPathsFn>,
#[cfg(engine)]
incremental_generation: bool,
#[cfg(engine)]
get_build_state: Option<GetBuildStateFn>,
#[cfg(engine)]
get_request_state: Option<GetRequestStateFn>,
#[cfg(engine)]
should_revalidate: Option<ShouldRevalidateFn>,
#[cfg(engine)]
revalidate_after: Option<ComputedDuration>,
#[cfg(engine)]
amalgamate_states: Option<AmalgamateStatesFn>,
pub is_capsule: bool,
pub(crate) can_be_rescheduled: bool,
}
impl<G: Html> std::fmt::Debug for TemplateInner<G> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Template")
.field("path", &self.path)
.field("is_capsule", &self.is_capsule)
.finish()
}
}
impl<G: Html> TemplateInner<G> {
fn new(path: impl Into<String> + std::fmt::Display) -> Self {
Self {
path: path.to_string(),
view: Box::new(|_, _, _, _| Ok((View::empty(), create_scope(|_| {})))),
#[cfg(engine)]
head: None,
#[cfg(engine)]
set_headers: None,
#[cfg(engine)]
get_build_paths: None,
#[cfg(engine)]
incremental_generation: false,
#[cfg(engine)]
get_build_state: None,
#[cfg(engine)]
get_request_state: None,
#[cfg(engine)]
should_revalidate: None,
#[cfg(engine)]
revalidate_after: None,
#[cfg(engine)]
amalgamate_states: None,
is_capsule: false,
can_be_rescheduled: false,
}
}
pub fn build(self) -> Template<G> {
Template {
inner: Entity::from(self),
}
}
}
#[cfg(all(not(feature = "hydrate"), any(client, doc)))]
pub(crate) type BrowserNodeType = sycamore::prelude::DomNode;
#[cfg(all(feature = "hydrate", any(client, doc)))]
pub(crate) type BrowserNodeType = sycamore::prelude::HydrateNode;