Crate perseus[][src]

Expand description

Perseus is a blazingly fast frontend web development framework built in Rust with support for major rendering strategies, reactivity without a virtual DOM, and extreme customizability. It wraps the lower-level capabilities of Sycamore and provides a NextJS-like API!

  • ✨ Supports static generation (serving only static resources)
  • ✨ Supports server-side rendering (serving dynamic resources)
  • ✨ Supports revalidation after time and/or with custom logic (updating rendered pages)
  • ✨ Supports incremental regeneration (build on demand)
  • ✨ Open build matrix (use any rendering strategy with anything else, mostly)
  • ✨ CLI harness that lets you build apps with ease and confidence

This is the documentation for the core Perseus crate, but there’s also a CLI and integrations to make serving apps easier!

Resources

These docs will help you as a reference, but the book should be your first port of call for learning about how to use Perseus and how it works.

Features

Perseus performs internationalization using translators, each of which utilizes some translation engine, like Fluent. Each of the available translations are feature-gated, and can be enabled with the translator-[engine-name] feature. You can set the default translator by setting the translator-dflt-[engine-name] (you of course can’t have more than one default translator). You can read more about this system here.

Re-exports

pub use http;
pub use crate::build::build_app;
pub use crate::build::build_template;
pub use crate::build::build_templates_for_locale;
pub use crate::error_pages::ErrorPages;
pub use crate::errors::err_to_status_code;
pub use crate::errors::ErrorCause;
pub use crate::errors::GenericErrorWithCause;
pub use crate::export::export_app;
pub use crate::serve::get_page;
pub use crate::serve::get_render_cfg;
pub use crate::shell::app_shell;
pub use crate::template::RenderFnResult;
pub use crate::template::RenderFnResultWithCause;
pub use crate::template::States;
pub use crate::template::Template;
pub use crate::template::TemplateMap;
pub use crate::translations_manager::FsTranslationsManager;
pub use crate::translations_manager::TranslationsManager;

Modules

Utilities for building your app.

Utilities regarding the formation of error pages for HTTP status codes, like a 404 Not Found page.

Utilities to do with exporting your app to purely static files.

Utilities for manipulating the HTML shell. These are primarily used in exporting and serving.

Utilities relating to working with path prefixes for when a site is hosted at a relative path.

Utilities for managing and creating plugins.

Utilities regarding routing.

Utilities for serving your app. These are platform-agnostic, and you probably want an integration like perseus-actix-web.

Utilities to do with the app shell. You probably don’t want to delve into here.

Utilities for mutable/immutable store managers. See the book for more details on this.

Utilities to do with templating. This is where the bulk of designing apps lies.

Utilities for creating custom translations managers, as well as the default FsTranslationsManager.

Utilities regarding translators, including the default FluentTranslator.

Macros

Creates an app-specific routing struct. Sycamore expects an enum to do this, so we create a struct that behaves similarly. If we don’t do this, we can’t get the information necessary for routing into the enum at all (context and global variables don’t suit this particular case).

Defines the components to create an entrypoint for the app. The actual entrypoint is created in the .perseus/ crate (where we can get all the dependencies without driving the user’s Cargo.toml nuts). This also defines the template map. This is intended to make compatibility with the Perseus CLI significantly easier.

Gets a HashMap of the given templates by their paths for serving. This should be manually wrapped for the pages your app provides for convenience.

Checks if we’re on the server or the client. This must be run inside a reactive scope (e.g. a template! or create_effect), because it uses Sycamore context.

Gets the link to the given resource in internationalized form conveniently.

Translates the given ID conveniently, taking arguments for interpolation as required.

A simple macro for listening for a checkpoint in a test.

Logs the given format!-style data to the browser’s console.

Structs

Manages translations in the app shell. This handles fetching translations from the server as well as caching for performance. This is distinct from TranslationsManager in that it operates on the client-side rather than on the server. This optimizes for users viewing many pages in the same locale, which is by far the most common use of most websites in terms of i18n.

Rendering backend for the DOM.

Represents an HTTP request.

Defines app information about i18n, specifically about which locales are supported.

Rendering backend for Server Side Rendering, aka. SSR.

Manages translations on the client-side for a single locale using Mozilla’s Fluent syntax. This should generally be placed into an Rc<T> and referred to by every template in an app. You do NOT want to be cloning potentially thousands of translations!

Constants

The file extension used by the Fluent translator, which expects FTL files.

Traits

Abstraction over a rendering backend.

Trait that is implemented for enums that can match routes.

Functions

Detects which locale the user should be served and redirects appropriately. This should only be used when the user navigates to a page like /about, without a locale. This will only work on the client-side (needs access to browser i18n settings). Any pages that direct to this should be explicitly excluded from search engines (they don’t show anything until redirected). This is guided by RFC 4647, but is not yet fully compliant (only supports xx-XX form locales). Note that this bypasses Sycamore’s routing logic and triggers a full reload.

Navigates to the specified url. The url should have the same origin as the app.

Type Definitions

All HTTP requests use empty bodies for simplicity of passing them around. They’ll never need payloads (value in path requested).

Attribute Macros

Marks the given function as a Perseus test. Functions marked with this attribute must have the following signature: async fn foo(client: &mut fantoccini::Client) -> Result<>.

Derive Macros

The Route procedural macro.