Skip to content

crate

weft_build

Build-time routes for Weft apps.

A project's build.rs calls run. It reads app/ (pages and layouts, in directories that mirror the site's URLs) and components/ (one component per .weft file), and writes the Rust that weft::app!() includes: the route table, the root template, and every page, layout and component ready to register.

app/layout.weft                     the root layout (`slot` is where the page goes)
app/page.weft                       /
app/about/page.weft                 /about/
app/blog/layout.weft                wraps every page under /blog/
app/blog/[slug]/page.weft           /blog/:slug/, with `params.slug`
app/blog/[slug]/page.rs             its companion: `scope`, `static_params`, `INTERACTIVE`
app/docs/[...path]/page.weft        /docs/*path/, with `params.path`
app/(marketing)/pricing/page.weft   /pricing/: a group adds no segment
app/_parts/                         a directory starting with `_` is never a route
app/not-found.weft                  what paths no route matches show
components/date-badge.weft          `DateBadge`, with `date-badge.rs` as its companion

Structs

  • App

    Everything in app/ and components/.

  • BuildError

    A problem with a file in app/ or components/.

  • Companion

    What a .rs companion beside a .weft file provides.

  • Page

    A page and where it's served.

  • Unit

    A .weft file as a component.

Functions

generate

pub fn generate(app: &App, root: &Path) -> String

The Rust weft::app!() includes. root is the project root (companion modules are included by absolute path).

pascal

pub fn pascal(words: &[String]) -> String

blog-posts → BlogPosts.

run

pub fn run()

For a project's build.rs: write $OUT_DIR/weft_app.rs from app/ and components/, and rebuild when they change. Problems stop the build with each file and line.

scan

pub fn scan(root: &Path) -> Result<App, Vec<BuildError>>

Read app/ and components/ under root.

Constants

DEFAULT_NOT_FOUND

pub const DEFAULT_NOT_FOUND: &str = …;

The page shown where no route matches, when there's no not-found.weft.