Struct perseus::Template

source ·
pub struct Template<G: Html> { /* private fields */ }
Expand description

A single template in an app. Each template is comprised of a Sycamore view, a state type, and some functions involved with generating that state. Pages can then be generated from particular states. For instance, a single docs template could have a state struct that stores a title and some content, which could then render as many pages as desired.

You can read more about the templates system here.

Note that all template states are passed around as Strings to avoid type maps and other inefficiencies, since they need to be transmitted over the network anyway. As such, this struct is entirely state-agnostic, since all the state-relevant functions merely return Strings. The various proc macros used to annotate such functions (e.g. #[perseus::build_state]) perform serialization/deserialization automatically for convenience.

Implementations

Creates a new Template. By default, this has absolutely no associated data. If rendered, it would result in a blank screen.

Executes the user-given function that renders the template on the server-side ONLY. This automatically initializes an isolated global state.

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.

Gets the list of templates that should be prerendered for at build-time.

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 complex applications like custom documentation systems can be enabled.

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.

Amalgamates given request and build states. Errors here can be caused by either the server or the client, so the user must specify an ErrorCause.

This takes a separate build state and request state to ensure there are no Nones for either of the states. This will only be called if both states are generated.

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.

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.

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.

Gets the interval after which the template will next revalidate.

Checks if this template can revalidate existing prerendered templates.

Checks if this template can revalidate existing prerendered templates after a given time.

Checks if this template can revalidate existing prerendered templates based on some given logic.

Checks if this template can render more templates beyond those paths it explicitly defines.

Checks if this template is a template to generate paths beneath it.

Checks if this template needs to do anything on requests for it.

Checks if this template needs to do anything at build time.

Checks if this template has custom logic to amalgamate build and request states if both are generated.

Checks if this template defines no rendering logic whatsoever. Such templates will be rendered using SSG. Basic templates can still modify headers (which could hypothetically be using global state that’s dependent on server-side generation).

Sets the template rendering function to use. This function might take in some state (use the #[perseus::template_rx] macro for serialization convenience) and/or some global state, and then it must return a Sycamore [View].

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).

Sets the function to set headers. This will override Perseus’ inbuilt header defaults.

Enables the build paths strategy with the given function.

Enables the incremental generation strategy.

Enables the build state strategy with the given function.

Enables the request state strategy with the given function.

Enables the revalidation strategy (logic variant) with the given function.

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)

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. See [States] for further details.

Trait Implementations

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Converts self into T using Into<T>. Read more
Converts self into a target type. Read more
Causes self to use its Binary implementation when Debug-formatted.
Causes self to use its Display implementation when Debug-formatted. Read more
Causes self to use its LowerExp implementation when Debug-formatted. Read more
Causes self to use its LowerHex implementation when Debug-formatted. Read more
Causes self to use its Octal implementation when Debug-formatted.
Causes self to use its Pointer implementation when Debug-formatted. Read more
Causes self to use its UpperExp implementation when Debug-formatted. Read more
Causes self to use its UpperHex implementation when Debug-formatted. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Pipes by value. This is generally the method you want to use. Read more
Borrows self and passes that borrow into the pipe function. Read more
Mutably borrows self and passes that borrow into the pipe function. Read more
Borrows self, then passes self.borrow() into the pipe function. Read more
Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
Borrows self, then passes self.as_ref() into the pipe function.
Mutably borrows self, then passes self.as_mut() into the pipe function. Read more
Borrows self, then passes self.deref() into the pipe function.
Mutably borrows self, then passes self.deref_mut() into the pipe function. Read more
Pipes a value into a function that cannot ordinarily be called in suffix position. Read more
Pipes a trait borrow into a function that cannot normally be called in suffix position. Read more
Pipes a trait mutable borrow into a function that cannot normally be called in suffix position. Read more
Pipes a trait borrow into a function that cannot normally be called in suffix position. Read more
Pipes a trait mutable borrow into a function that cannot normally be called in suffix position. Read more
Pipes a dereference into a function that cannot normally be called in suffix position. Read more
Pipes a mutable dereference into a function that cannot normally be called in suffix position. Read more
Pipes a reference into a function that cannot ordinarily be called in suffix position. Read more
Pipes a mutable reference into a function that cannot ordinarily be called in suffix position. Read more
Immutable access to a value. Read more
Mutable access to a value. Read more
Immutable access to the Borrow<B> of a value. Read more
Mutable access to the BorrowMut<B> of a value. Read more
Immutable access to the AsRef<R> view of a value. Read more
Mutable access to the AsMut<R> view of a value. Read more
Immutable access to the Deref::Target of a value. Read more
Mutable access to the Deref::Target of a value. Read more
Calls .tap() only in debug builds, and is erased in release builds.
Calls .tap_mut() only in debug builds, and is erased in release builds. Read more
Calls .tap_borrow() only in debug builds, and is erased in release builds. Read more
Calls .tap_borrow_mut() only in debug builds, and is erased in release builds. Read more
Calls .tap_ref() only in debug builds, and is erased in release builds. Read more
Calls .tap_ref_mut() only in debug builds, and is erased in release builds. Read more
Calls .tap_deref() only in debug builds, and is erased in release builds. Read more
Calls .tap_deref_mut() only in debug builds, and is erased in release builds. Read more
Provides immutable access for inspection. Read more
Calls tap in debug builds, and does nothing in release builds.
Provides mutable access for modification. Read more
Calls tap_mut in debug builds, and does nothing in release builds.
Provides immutable access to the reference for inspection.
Calls tap_ref in debug builds, and does nothing in release builds.
Provides mutable access to the reference for modification.
Calls tap_ref_mut in debug builds, and does nothing in release builds.
Provides immutable access to the borrow for inspection. Read more
Calls tap_borrow in debug builds, and does nothing in release builds.
Provides mutable access to the borrow for modification.
Calls tap_borrow_mut in debug builds, and does nothing in release builds. Read more
Immutably dereferences self for inspection.
Calls tap_deref in debug builds, and does nothing in release builds.
Mutably dereferences self for modification.
Calls tap_deref_mut in debug builds, and does nothing in release builds. Read more
Attempts to convert self into T using TryInto<T>. Read more
Attempts to convert self into a target type. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.