pub struct Template<G: Html> { /* private fields */ }
Expand description
This allows the specification of all the template templates in an app and how to render them. If no rendering logic is provided at all,
the template will be prerendered at build-time with no state. All closures are stored on the heap to avoid hellish lifetime specification.
All properties for templates are passed around as strings to avoid type maps and other horrible things, this only adds one extra
deserialization call at build time. This only actually owns a two String
s and a bool
.
Implementations
sourceimpl<G: Html> Template<G>
impl<G: Html> Template<G>
sourcepub fn render_for_template_client(
&self,
props: PageProps,
translator: &Translator,
is_server: bool,
router_state: RouterState,
page_state_store: PageStateStore,
global_state: GlobalState,
frozen_app: Rc<RefCell<Option<(FrozenApp, ThawPrefs)>>>,
is_first: Rc<Cell<bool>>,
live_reload_indicator: ReadSignal<bool>
) -> View<G>
pub fn render_for_template_client(
&self,
props: PageProps,
translator: &Translator,
is_server: bool,
router_state: RouterState,
page_state_store: PageStateStore,
global_state: GlobalState,
frozen_app: Rc<RefCell<Option<(FrozenApp, ThawPrefs)>>>,
is_first: Rc<Cell<bool>>,
live_reload_indicator: ReadSignal<bool>
) -> View<G>
Executes the user-given function that renders the template on the client-side ONLY. This takes in an extsing global state.
sourcepub fn render_for_template_server(
&self,
props: PageProps,
translator: &Translator,
is_server: bool,
router_state: RouterState,
page_state_store: PageStateStore
) -> View<G>
pub fn render_for_template_server(
&self,
props: PageProps,
translator: &Translator,
is_server: bool,
router_state: RouterState,
page_state_store: PageStateStore
) -> View<G>
Executes the user-given function that renders the template on the server-side ONLY. This automatically initializes an isolated global state.
sourcepub fn render_head_str(
&self,
props: PageProps,
translator: &Translator
) -> String
pub fn render_head_str(
&self,
props: PageProps,
translator: &Translator
) -> String
Executes the user-given function that renders the document <head>
, returning a string to be interpolated manually. Reactivity
in this function will not take effect due to this string rendering. Note that this function will provide a translator context.
sourcepub async fn get_build_paths(&self) -> Result<Vec<String>, ServerError>
pub async fn get_build_paths(&self) -> Result<Vec<String>, ServerError>
Gets the list of templates that should be prerendered for at build-time.
sourcepub async fn get_build_state(
&self,
path: String,
locale: String
) -> Result<String, ServerError>
pub async fn get_build_state(
&self,
path: String,
locale: String
) -> Result<String, ServerError>
Gets the initial state for a template. This needs to be passed the full path of the template, which may be one of those generated by
.get_build_paths()
. This also needs the locale being rendered to so that more compelx applications like custom documentation
systems can be enabled.
sourcepub async fn get_request_state(
&self,
path: String,
locale: String,
req: Request
) -> Result<String, ServerError>
pub async fn get_request_state(
&self,
path: String,
locale: String,
req: Request
) -> Result<String, ServerError>
Gets the request-time state for a template. This is equivalent to SSR, and will not be performed at build-time. Unlike
.get_build_paths()
though, this will be passed information about the request that triggered the render. Errors here can be caused
by either the server or the client, so the user must specify an ErrorCause
. This is also passed the locale being rendered to.
sourcepub fn amalgamate_states(
&self,
states: States
) -> Result<Option<String>, ServerError>
pub fn amalgamate_states(
&self,
states: States
) -> Result<Option<String>, ServerError>
Amalagmates given request and build states. Errors here can be caused by either the server or the client, so the user must specify
an ErrorCause
.
sourcepub async fn should_revalidate(&self) -> Result<bool, ServerError>
pub async fn should_revalidate(&self) -> Result<bool, ServerError>
Checks, by the user’s custom logic, if this template should revalidate. This function isn’t presently parsed anything, but has
network access etc., and can really do whatever it likes. Errors here can be caused by either the server or the client, so the
user must specify an ErrorCause
.
sourcepub fn get_headers(&self, state: Option<String>) -> HeaderMap
pub fn get_headers(&self, state: Option<String>) -> HeaderMap
Gets the template’s headers for the given state. These will be inserted into any successful HTTP responses for this template, and they have the power to override.
sourcepub fn get_path(&self) -> String
pub fn get_path(&self) -> String
Gets the path of the template. This is the root path under which any generated pages will be served. In the simplest case, there will only be one page rendered, and it will occupy that root position.
sourcepub fn get_revalidate_interval(&self) -> Option<String>
pub fn get_revalidate_interval(&self) -> Option<String>
Gets the interval after which the template will next revalidate.
sourcepub fn revalidates(&self) -> bool
pub fn revalidates(&self) -> bool
Checks if this template can revalidate existing prerendered templates.
sourcepub fn revalidates_with_time(&self) -> bool
pub fn revalidates_with_time(&self) -> bool
Checks if this template can revalidate existing prerendered templates after a given time.
sourcepub fn revalidates_with_logic(&self) -> bool
pub fn revalidates_with_logic(&self) -> bool
Checks if this template can revalidate existing prerendered templates based on some given logic.
sourcepub fn uses_incremental(&self) -> bool
pub fn uses_incremental(&self) -> bool
Checks if this template can render more templates beyond those paths it explicitly defines.
sourcepub fn uses_build_paths(&self) -> bool
pub fn uses_build_paths(&self) -> bool
Checks if this template is a template to generate paths beneath it.
sourcepub fn uses_request_state(&self) -> bool
pub fn uses_request_state(&self) -> bool
Checks if this template needs to do anything on requests for it.
sourcepub fn uses_build_state(&self) -> bool
pub fn uses_build_state(&self) -> bool
Checks if this template needs to do anything at build time.
sourcepub fn can_amalgamate_states(&self) -> bool
pub fn can_amalgamate_states(&self) -> bool
Checks if this template has custom logic to amalgamate build and reqquest states if both are generated.
sourcepub fn is_basic(&self) -> bool
pub fn is_basic(&self) -> bool
Checks if this template defines no rendering logic whatsoever. Such templates will be rendered using SSG. Basic templates can still modify headers.
sourcepub fn template(
self,
val: impl Fn(PageProps) -> View<G> + Send + Sync + 'static
) -> Template<G>
pub fn template(
self,
val: impl Fn(PageProps) -> View<G> + Send + Sync + 'static
) -> Template<G>
Sets the template rendering function to use.
sourcepub fn head(
self,
val: impl Fn(PageProps) -> View<SsrNode> + Send + Sync + 'static
) -> Template<G>
pub fn head(
self,
val: impl Fn(PageProps) -> View<SsrNode> + Send + Sync + 'static
) -> Template<G>
Sets the document head rendering function to use.
sourcepub fn set_headers_fn(
self,
val: impl Fn(Option<String>) -> HeaderMap + Send + Sync + 'static
) -> Template<G>
pub fn set_headers_fn(
self,
val: impl Fn(Option<String>) -> HeaderMap + Send + Sync + 'static
) -> Template<G>
Sets the function to set headers. This will override Perseus’ inbuilt header defaults.
sourcepub fn build_paths_fn(
self,
val: impl GetBuildPathsFnType + Send + Sync + 'static
) -> Template<G>
pub fn build_paths_fn(
self,
val: impl GetBuildPathsFnType + Send + Sync + 'static
) -> Template<G>
Enables the build paths strategy with the given function.
sourcepub fn incremental_generation(self) -> Template<G>
pub fn incremental_generation(self) -> Template<G>
Enables the incremental generation strategy.
sourcepub fn build_state_fn(
self,
val: impl GetBuildStateFnType + Send + Sync + 'static
) -> Template<G>
pub fn build_state_fn(
self,
val: impl GetBuildStateFnType + Send + Sync + 'static
) -> Template<G>
Enables the build state strategy with the given function.
sourcepub fn request_state_fn(
self,
val: impl GetRequestStateFnType + Send + Sync + 'static
) -> Template<G>
pub fn request_state_fn(
self,
val: impl GetRequestStateFnType + Send + Sync + 'static
) -> Template<G>
Enables the request state strategy with the given function.
sourcepub fn should_revalidate_fn(
self,
val: impl ShouldRevalidateFnType + Send + Sync + 'static
) -> Template<G>
pub fn should_revalidate_fn(
self,
val: impl ShouldRevalidateFnType + Send + Sync + 'static
) -> Template<G>
Enables the revalidation strategy (logic variant) with the given function.
sourcepub fn revalidate_after(self, val: String) -> Template<G>
pub fn revalidate_after(self, val: String) -> Template<G>
Enables the revalidation strategy (time variant). This takes a time string of a form like 1w
for one week. More details are available
in the book.
sourcepub fn amalgamate_states_fn(
self,
val: impl Fn(States) -> RenderFnResultWithCause<Option<String>> + Send + Sync + 'static
) -> Template<G>
pub fn amalgamate_states_fn(
self,
val: impl Fn(States) -> RenderFnResultWithCause<Option<String>> + Send + Sync + 'static
) -> Template<G>
Enables state amalgamation with the given function.
Trait Implementations
Auto Trait Implementations
impl<G> !RefUnwindSafe for Template<G>
impl<G> Send for Template<G>
impl<G> Sync for Template<G>
impl<G> Unpin for Template<G>
impl<G> !UnwindSafe for Template<G>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more