Struct perseus::PerseusAppBase
source · [−]pub struct PerseusAppBase<G: Html, M: MutableStore, T: TranslationsManager> { /* private fields */ }
Expand description
The options for constructing a Perseus app. These encompass all the information Perseus needs to know to create your app. Every Perseus app using the engine must export one of these.
Note that this is an interim storage point, it’s not depended on by any part of the core logic, and therefore custom engines can entirely ignore this.
Implementations
sourceimpl<G: Html, T: TranslationsManager> PerseusAppBase<G, FsMutableStore, T>
impl<G: Html, T: TranslationsManager> PerseusAppBase<G, FsMutableStore, T>
sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new instance of a Perseus app using the default filesystem-based mutable store. For most apps, this will be sufficient. Note that this initializes the translations manager as a dummy, and adds no templates or error pages.
In development, you can get away with defining no error pages, but production apps (e.g. those created with perseus deploy
) MUST set their own custom error pages.
This is asynchronous because it creates a translations manager in the background.
sourceimpl<G: Html, M: MutableStore> PerseusAppBase<G, M, FsTranslationsManager>
impl<G: Html, M: MutableStore> PerseusAppBase<G, M, FsTranslationsManager>
sourcepub fn locales_lit_and_translations_manager(self, locales: Locales) -> Self
pub fn locales_lit_and_translations_manager(self, locales: Locales) -> Self
The same as .locales_and_translations_manager()
, but this accepts a literal Locales
struct
, which means this can be used when you’re using FsTranslationsManager
but when you don’t
know if your app is using i18n or not (almost always middleware).
sourcepub fn locales_and_translations_manager(
self,
default: &str,
other: &[&str]
) -> Self
pub fn locales_and_translations_manager(
self,
default: &str,
other: &[&str]
) -> Self
Sets the internationalization information for an app using the default translations manager (FsTranslationsManager
). This handles locale caching and the like automatically for you,
though you could alternatively use .locales()
and .translations_manager()
independently to customize various behaviors. This takes the same arguments as .locales()
, so
the first argument is the default locale (used as a fallback for users with no locale preferences set in their browsers), and the second is a list of other locales supported.
If you’re not using i18n, you don’t need to call this function. If you for some reason do have to though (e.g. overriding some other preferences in middleware), use .disable_i18n()
,
not this, as you’re very likely to shoot yourself in the foot! (If i18n is disabled, the default locale MUST be set to xx-XX
, for example.)
sourceimpl<G: Html, M: MutableStore, T: TranslationsManager> PerseusAppBase<G, M, T>
impl<G: Html, M: MutableStore, T: TranslationsManager> PerseusAppBase<G, M, T>
sourcepub fn new_with_mutable_store(mutable_store: M) -> Self
pub fn new_with_mutable_store(mutable_store: M) -> Self
Creates a new instance of a Perseus app, with the default options and a custom mutable store.
sourcepub fn root(self, val: &str) -> Self
pub fn root(self, val: &str) -> Self
Sets the HTML ID of the <div>
element at which to insert Perseus.
sourcepub fn templates(self, val: Vec<Box<dyn Fn() -> Template<G>>>) -> Self
pub fn templates(self, val: Vec<Box<dyn Fn() -> Template<G>>>) -> Self
Sets all the app’s templates. This takes a vector of boxed functions that return templates.
sourcepub fn template(self, val: impl Fn() -> Template<G> + 'static) -> Self
pub fn template(self, val: impl Fn() -> Template<G> + 'static) -> Self
Adds a single new template to the app (convenience function). This takes a function that returns a template.
sourcepub fn error_pages(self, val: impl Fn() -> ErrorPages<G> + 'static) -> Self
pub fn error_pages(self, val: impl Fn() -> ErrorPages<G> + 'static) -> Self
Sets the app’s error pages.
sourcepub fn global_state_creator(self, val: GlobalStateCreator) -> Self
pub fn global_state_creator(self, val: GlobalStateCreator) -> Self
Sets the app’s global state creator.
sourcepub fn locales(self, default: &str, other: &[&str]) -> Self
pub fn locales(self, default: &str, other: &[&str]) -> Self
Sets the locales information for the app. The first argument is the default locale (used as a fallback for users with no locale preferences set in their browsers), and the second is a list of other locales supported.
Note that this does not update the translations manager, which must be done separately (if you’re using FsTranslationsManager
, the default, you can use
.locales_and_translations_manager()
to set both at once).
If you’re not using i18n, you don’t need to call this function. If you for some reason do have to though (e.g. overriding some other preferences in middleware), use .disable_i18n()
,
not this, as you’re very likely to shoot yourself in the foot! (If i18n is disabled, the default locale MUST be set to xx-XX
, for example.)
sourcepub fn locales_lit(self, val: Locales) -> Self
pub fn locales_lit(self, val: Locales) -> Self
Sets the locales information directly based on an instance of Locales
. Usually, end users will use .locales()
instead for a friendlier interface.
sourcepub fn translations_manager(
self,
val: impl Future<Output = T> + 'static
) -> Self
pub fn translations_manager(
self,
val: impl Future<Output = T> + 'static
) -> Self
Sets the translations manager. If you’re using the default translations manager (FsTranslationsManager
), you can use .locales_and_translations_manager()
to set this automatically
based on the locales information. This takes a Future<Output = T>
, where T
is your translations manager’s type.
The reason that this takes a Future
is to avoid the use of .await
in your app definition code, which must be synchronous due to constraints of Perseus’ client-side systems.
When your code is run on the server, the Future
will be .await
ed on, but on Wasm, it will be discarded and ignored, since the translations manager isn’t needed in Wasm.
This is generally intended for use with custom translations manager or specific use-cases with the default (mostly to do with custom caching behavior).
sourcepub fn disable_i18n(self) -> Self
pub fn disable_i18n(self) -> Self
Explicitly disables internationalization. You shouldn’t ever need to call this, as it’s the default, but you may want to if you’re writing middleware that doesn’t support i18n.
sourcepub fn static_aliases(self, val: HashMap<String, String>) -> Self
pub fn static_aliases(self, val: HashMap<String, String>) -> Self
Sets all the app’s static aliases. This takes a map of URLs (e.g. /file
) to resource paths, relative to the project directory (e.g. style.css
).
sourcepub fn static_alias(self, url: &str, resource: &str) -> Self
pub fn static_alias(self, url: &str, resource: &str) -> Self
Adds a single static alias (convenience function). This takes a URL path (e.g. /file
) followed by a path to a resource (which must be within the project directory, e.g. style.css
).
sourcepub fn mutable_store(self, val: M) -> Self
pub fn mutable_store(self, val: M) -> Self
Sets the mutable store for the app to use, which you would change for some production server environments if you wanted to store build artifacts that can change at runtime in a place other than on the filesystem (created for serverless functions specifically).
sourcepub fn immutable_store(self, val: ImmutableStore) -> Self
pub fn immutable_store(self, val: ImmutableStore) -> Self
Sets the immutable store for the app to use. You should almost never need to change this unless you’re not working with the CLI.
sourcepub fn index_view_str(self, val: &str) -> Self
pub fn index_view_str(self, val: &str) -> Self
Sets the index view as a string. This should be used if you’re using an index.html
file or the like.
Note: if possible, you should switch to using .index_view()
, which uses a Sycamore view rather than an HTML string.
sourcepub fn index_view<'a>(self, f: impl Fn() -> View<SsrNode> + 'a) -> Self
pub fn index_view<'a>(self, f: impl Fn() -> View<SsrNode> + 'a) -> Self
Sets the index view using a Sycamore view, which avoids the need to write any HTML by hand whatsoever. Note that this must contain a <head>
and <body>
at a minimum.
Warning: this view can’t be reactive (yet). It will be rendered to a static string, which won’t be hydrated.
sourcepub fn get_templates_map(&self) -> TemplateMap<G>
pub fn get_templates_map(&self) -> TemplateMap<G>
Gets the templates in an Rc
-based HashMap
for non-concurrent access.
sourcepub fn get_error_pages(&self) -> ErrorPages<G>
pub fn get_error_pages(&self) -> ErrorPages<G>
Gets the error pages used in the app. This returns an Rc
.
sourcepub fn get_global_state_creator(&self) -> GlobalStateCreator
pub fn get_global_state_creator(&self) -> GlobalStateCreator
Gets the global state creator. This can’t be directly modified by plugins because of reactive type complexities.
sourcepub fn get_locales(&self) -> Locales
pub fn get_locales(&self) -> Locales
Gets the locales information.
sourcepub fn get_plugins(&self) -> Rc<Plugins<G>>
pub fn get_plugins(&self) -> Rc<Plugins<G>>
Gets the plugins registered for the app. These are passed around and used in a way that doesn’t require them to be concurrently accessible, and so are provided in an Rc
.
Trait Implementations
sourceimpl<G: Debug + Html, M: Debug + MutableStore, T: Debug + TranslationsManager> Debug for PerseusAppBase<G, M, T>
impl<G: Debug + Html, M: Debug + MutableStore, T: Debug + TranslationsManager> Debug for PerseusAppBase<G, M, T>
Auto Trait Implementations
impl<G, M, T> !RefUnwindSafe for PerseusAppBase<G, M, T>
impl<G, M, T> !Send for PerseusAppBase<G, M, T>
impl<G, M, T> !Sync for PerseusAppBase<G, M, T>
impl<G, M, T> Unpin for PerseusAppBase<G, M, T> where
M: Unpin,
T: Unpin,
impl<G, M, T> !UnwindSafe for PerseusAppBase<G, M, T>
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