Struct perseus::template::TemplateInner
source · pub struct TemplateInner<G: Html> {
pub is_capsule: bool,
/* private fields */
}
Expand description
The internal representation of a Perseus template, with all the methods
involved in creating and managing it. As this struct
is not Clone
,
it will almost always appear wrapped in a full Template
, which allows
cloning and passing the template around arbitrarily. As that dereferences
to this, you will be able to use any of the methods on this struct
on
Template
.
Fields§
§is_capsule: bool
Whether or not this template is actually a capsule. This impacts significant aspects of internal handling.
There is absolutely no circumstance in which you should ever change this. Ever. You will break your app. Always.
Implementations§
source§impl<G: Html> TemplateInner<G>
impl<G: Html> TemplateInner<G>
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.
Note that this will automatically transform index
to an empty string.
Note that this will prepend __capsule/
to any capsules automatically.
sourcepub fn get_revalidate_interval(&self) -> Option<ComputedDuration>
pub fn get_revalidate_interval(&self) -> Option<ComputedDuration>
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 request states if both are generated.
source§impl<G: Html> TemplateInner<G>
impl<G: Html> TemplateInner<G>
sourcepub fn head<V: Into<GeneratorResult<View<SsrNode>>>>(
self,
val: impl Fn(Scope<'_>) -> V + Send + Sync + 'static
) -> Self
pub fn head<V: Into<GeneratorResult<View<SsrNode>>>>( self, val: impl Fn(Scope<'_>) -> V + Send + Sync + 'static ) -> Self
Sets the document <head>
rendering function to use. The [View
]
produced by this will only be rendered on the engine-side, and will
not be reactive (since it only contains metadata).
This is for heads that do not require state. Those that do should use
.head_with_state()
instead.
sourcepub fn head(self, _val: impl Fn() + 'static) -> Self
pub fn head(self, _val: impl Fn() + 'static) -> Self
Sets the document <head>
rendering function to use. The [View
]
produced by this will only be rendered on the engine-side, and will
not be reactive (since it only contains metadata).
This is for heads that do not require state. Those that do should use
.head_with_state()
instead.
sourcepub fn set_headers<V: Into<GeneratorResult<HeaderMap>>>(
self,
val: impl Fn(Scope<'_>) -> V + Send + Sync + 'static
) -> Self
pub fn set_headers<V: Into<GeneratorResult<HeaderMap>>>( self, val: impl Fn(Scope<'_>) -> V + Send + Sync + 'static ) -> Self
Sets the function to set headers. This will override Perseus’ inbuilt header defaults. This should only be used when your header-setting does not need state.
sourcepub fn set_headers(self, _val: impl Fn() + 'static) -> Self
pub fn set_headers(self, _val: impl Fn() + 'static) -> Self
Sets the function to set headers. This will override Perseus’ inbuilt header defaults. This should only be used when your header-setting does not need state.
sourcepub fn build_paths_fn<V: Into<GeneratorResult<BuildPaths>>>(
self,
val: impl GetBuildPathsUserFnType<V> + Clone + Send + Sync + 'static
) -> Self
pub fn build_paths_fn<V: Into<GeneratorResult<BuildPaths>>>( self, val: impl GetBuildPathsUserFnType<V> + Clone + Send + Sync + 'static ) -> Self
Enables the build paths strategy with the given function.
sourcepub fn build_paths_fn(self, _val: impl Fn() + 'static) -> Self
pub fn build_paths_fn(self, _val: impl Fn() + 'static) -> Self
Enables the build paths strategy with the given function.
sourcepub fn incremental_generation(self) -> Self
pub fn incremental_generation(self) -> Self
Enables the incremental generation strategy.
sourcepub fn incremental_generation(self) -> Self
pub fn incremental_generation(self) -> Self
Enables the incremental generation strategy.
sourcepub fn build_state_fn<S, B, V>(
self,
val: impl GetBuildStateUserFnType<S, B, V> + Clone + Send + Sync + 'static
) -> Selfwhere
S: Serialize + DeserializeOwned + MakeRx,
B: Serialize + DeserializeOwned + Send + Sync + 'static,
V: Into<BlamedGeneratorResult<S>>,
pub fn build_state_fn<S, B, V>( self, val: impl GetBuildStateUserFnType<S, B, V> + Clone + Send + Sync + 'static ) -> Selfwhere S: Serialize + DeserializeOwned + MakeRx, B: Serialize + DeserializeOwned + Send + Sync + 'static, V: Into<BlamedGeneratorResult<S>>,
Enables the build state strategy with the given function.
sourcepub fn build_state_fn(self, _val: impl Fn() + 'static) -> Self
pub fn build_state_fn(self, _val: impl Fn() + 'static) -> Self
Enables the build state strategy with the given function.
sourcepub fn request_state_fn<S, B, V>(
self,
val: impl GetRequestStateUserFnType<S, B, V> + Clone + Send + Sync + 'static
) -> Selfwhere
S: Serialize + DeserializeOwned + MakeRx,
B: Serialize + DeserializeOwned + Send + Sync + 'static,
V: Into<BlamedGeneratorResult<S>>,
pub fn request_state_fn<S, B, V>( self, val: impl GetRequestStateUserFnType<S, B, V> + Clone + Send + Sync + 'static ) -> Selfwhere S: Serialize + DeserializeOwned + MakeRx, B: Serialize + DeserializeOwned + Send + Sync + 'static, V: Into<BlamedGeneratorResult<S>>,
Enables the request state strategy with the given function.
sourcepub fn request_state_fn(self, _val: impl Fn() + 'static) -> Self
pub fn request_state_fn(self, _val: impl Fn() + 'static) -> Self
Enables the request state strategy with the given function.
sourcepub fn should_revalidate_fn<B, V>(
self,
val: impl ShouldRevalidateUserFnType<B, V> + Clone + Send + Sync + 'static
) -> Selfwhere
B: Serialize + DeserializeOwned + Send + Sync + 'static,
V: Into<BlamedGeneratorResult<bool>>,
pub fn should_revalidate_fn<B, V>( self, val: impl ShouldRevalidateUserFnType<B, V> + Clone + Send + Sync + 'static ) -> Selfwhere B: Serialize + DeserializeOwned + Send + Sync + 'static, V: Into<BlamedGeneratorResult<bool>>,
Enables the revalidation strategy (logic variant) with the given function.
sourcepub fn should_revalidate_fn(self, _val: impl Fn() + 'static) -> Self
pub fn should_revalidate_fn(self, _val: impl Fn() + 'static) -> Self
Enables the revalidation strategy (logic variant) with the given function.
sourcepub fn revalidate_after<I: PerseusDuration>(self, val: I) -> Self
pub fn revalidate_after<I: PerseusDuration>(self, val: I) -> Self
Enables the revalidation strategy (time variant). This takes a time
string of a form like 1w
for one week.
- s: second,
- m: minute,
- h: hour,
- d: day,
- w: week,
- M: month (30 days used here, 12M ≠ 1y!),
- y: year (365 days always, leap years ignored, if you want them add them as days)
sourcepub fn revalidate_after<I: PerseusDuration>(self, _val: I) -> Self
pub fn revalidate_after<I: PerseusDuration>(self, _val: I) -> Self
Enables the revalidation strategy (time variant). This takes a time
string of a form like 1w
for one week.
- s: second,
- m: minute,
- h: hour,
- d: day,
- w: week,
- M: month (30 days used here, 12M ≠ 1y!),
- y: year (365 days always, leap years ignored, if you want them add them as days)
sourcepub fn amalgamate_states_fn<S, B, V>(
self,
val: impl AmalgamateStatesUserFnType<S, B, V> + Clone + Send + Sync + 'static
) -> Selfwhere
S: Serialize + DeserializeOwned + MakeRx + Send + Sync + 'static,
B: Serialize + DeserializeOwned + Send + Sync + 'static,
V: Into<BlamedGeneratorResult<S>>,
pub fn amalgamate_states_fn<S, B, V>( self, val: impl AmalgamateStatesUserFnType<S, B, V> + Clone + Send + Sync + 'static ) -> Selfwhere S: Serialize + DeserializeOwned + MakeRx + Send + Sync + 'static, B: Serialize + DeserializeOwned + Send + Sync + 'static, V: Into<BlamedGeneratorResult<S>>,
Enables state amalgamation with the given function. State amalgamation allows you to have one template generate state at both build time and request time. The function you provide here is responsible for rationalizing the two into one single state to be sent to the client, and this will be run just after the request state function completes.
sourcepub fn amalgamate_states_fn(self, _val: impl Fn() + 'static) -> Self
pub fn amalgamate_states_fn(self, _val: impl Fn() + 'static) -> Self
Enables state amalgamation with the given function. State amalgamation allows you to have one template generate state at both build time and request time. The function you provide here is responsible for rationalizing the two into one single state to be sent to the client, and this will be run just after the request state function completes.
sourcepub fn allow_rescheduling(self) -> Self
pub fn allow_rescheduling(self) -> Self
Allow the building of this page’s templates to be rescheduled from build-tim to request-time.
A page whose state isn’t generated at request-tim and isn’t revalidated can be rendered at build-time, unless it depends on capsules that don’t have those properties. If a page that could be rendered at build-time were to render with a widget that revalidates later, that prerender would be invalidated later, leading to render errors. If that situation arises, and this hasn’t been set, building will return an error.
If you receive one of those errors, it’s almost always absolutely fine to enable this, as the performance hit will usually be negligible. If you notice a substantial difference though, you may wish to reconsider.
source§impl<G: Html> TemplateInner<G>
impl<G: Html> TemplateInner<G>
sourcepub fn view_with_state<I, F>(self, val: F) -> Selfwhere
F: for<'app, 'child> Fn(BoundedScope<'app, 'child>, &'child I) -> View<G> + Send + Sync + 'static,
I: MakeUnrx + AnyFreeze + Clone,
I::Unrx: MakeRx<Rx = I> + Serialize + DeserializeOwned + Send + Sync + Clone + 'static,
pub fn view_with_state<I, F>(self, val: F) -> Selfwhere F: for<'app, 'child> Fn(BoundedScope<'app, 'child>, &'child I) -> View<G> + Send + Sync + 'static, I: MakeUnrx + AnyFreeze + Clone, I::Unrx: MakeRx<Rx = I> + Serialize + DeserializeOwned + Send + Sync + Clone + 'static,
Sets the template rendering function to use, if the template takes
state. Templates that do not take state should use .template()
instead.
The closure wrapping this performs will automatically handle suspense state.
sourcepub fn view_with_unreactive_state<F, S>(self, val: F) -> Selfwhere
F: Fn(Scope<'_>, S) -> View<G> + Send + Sync + 'static,
S: MakeRx + Serialize + DeserializeOwned + UnreactiveState + 'static,
<S as MakeRx>::Rx: AnyFreeze + Clone + MakeUnrx<Unrx = S>,
pub fn view_with_unreactive_state<F, S>(self, val: F) -> Selfwhere F: Fn(Scope<'_>, S) -> View<G> + Send + Sync + 'static, S: MakeRx + Serialize + DeserializeOwned + UnreactiveState + 'static, <S as MakeRx>::Rx: AnyFreeze + Clone + MakeUnrx<Unrx = S>,
Sets the template rendering function to use, if the template takes unreactive state.
sourcepub fn view<F>(self, val: F) -> Selfwhere
F: Fn(Scope<'_>) -> View<G> + Send + Sync + 'static,
pub fn view<F>(self, val: F) -> Selfwhere F: Fn(Scope<'_>) -> View<G> + Send + Sync + 'static,
Sets the template rendering function to use for templates that take no
state. Templates that do take state should use
.template_with_state()
instead.
sourcepub fn head_with_state<S, V>(
self,
val: impl Fn(Scope<'_>, S) -> V + Send + Sync + 'static
) -> Selfwhere
S: Serialize + DeserializeOwned + MakeRx + 'static,
V: Into<GeneratorResult<View<SsrNode>>>,
pub fn head_with_state<S, V>( self, val: impl Fn(Scope<'_>, S) -> V + Send + Sync + 'static ) -> Selfwhere S: Serialize + DeserializeOwned + MakeRx + 'static, V: Into<GeneratorResult<View<SsrNode>>>,
Sets the document <head>
rendering function to use. The [View
]
produced by this will only be rendered on the engine-side, and will
not be reactive (since it only contains metadata).
This is for heads that do require state. Those that do not should use
.head()
instead.
sourcepub fn head_with_state(self, _val: impl Fn() + 'static) -> Self
pub fn head_with_state(self, _val: impl Fn() + 'static) -> Self
Sets the document <head>
rendering function to use. The [View
]
produced by this will only be rendered on the engine-side, and will
not be reactive (since it only contains metadata).
This is for heads that do require state. Those that do not should use
.head()
instead.
sourcepub fn set_headers_with_state<S, V>(
self,
val: impl Fn(Scope<'_>, S) -> V + Send + Sync + 'static
) -> Selfwhere
S: Serialize + DeserializeOwned + MakeRx + 'static,
V: Into<GeneratorResult<HeaderMap>>,
pub fn set_headers_with_state<S, V>( self, val: impl Fn(Scope<'_>, S) -> V + Send + Sync + 'static ) -> Selfwhere S: Serialize + DeserializeOwned + MakeRx + 'static, V: Into<GeneratorResult<HeaderMap>>,
Sets the function to set headers. This will override Perseus’ inbuilt header defaults. This should only be used when your header-setting requires knowing the state.
sourcepub fn set_headers_with_state(self, _val: impl Fn() + 'static) -> Self
pub fn set_headers_with_state(self, _val: impl Fn() + 'static) -> Self
Sets the function to set headers. This will override Perseus’ inbuilt header defaults. This should only be used when your header-setting requires knowing the state.
source§impl<G: Html> TemplateInner<G>
impl<G: Html> TemplateInner<G>
sourcepub fn build(self) -> Template<G>
pub fn build(self) -> Template<G>
Builds a full Template
from this TemplateInner
, consuming it in
the process. Once called, the template cannot be modified anymore,
and it will be placed into a smart pointer, allowing it to be cloned
freely with minimal costs.
You should call this just before you return your template.