[][src]Crate ructe

Rust Compiled Templates is a HTML template system for Rust.

Ructe works by converting your templates (and static files) to rust source code, which is then compiled with your project. This has the benefits that:

  1. Many syntactical and logical errors in templates are caught compile-time, rather than in a running server.
  2. No extra latency on the first request, since the template are compiled before starting the program.
  3. The template files does not have to be distributed / installed. Templates (and static assets) are included in the compiled program, which can be a single binary.

The template syntax, which is inspired by Twirl, the Scala-based template engine in Play framework, is documented in the Template syntax module. A sample template may look like this:

@use ::Group;
@use super::page_base;

@(title: &str, user: Option<String>, groups: &[Group])

@:page_base(title, &user, {
  <div class="group">
    @if groups.is_empty() {
      <p>No pictures.</p>
    }
    @for g in groups {
      <div class="item"><h2>@g.title</h2>
        <p><a href="@g.url"><img src="/img/@g.photo.id-s.jpg"></a></p>
        <p>@g.count pictures</p>
      </div>
    }
  </div>
})

There are some examples in the repository. There is also a separate example of using ructe with warp and diesel.

Modules

How_to_use_ructe

This module describes how to configure and use Rust Compiled Templates.

Template_syntax

This module describes the template syntax used by ructe.

Using_static_files

Apart from handling templates for dynamic content, ructe also helps with constants for static content.

templates

The module containing your generated template code will also contain everything from here.

Structs

Ructe

The main build-time interface of ructe.

StaticFiles

Handler for static files.

Enums

RucteError

The build-time error type for Ructe.

Functions

compile_static_filesDeprecated

Create a statics module inside outdir, containing static file data for all files in indir.

compile_templatesDeprecated

Create a templates module in outdir containing rust code for all templates found in indir.

Type Definitions

Result

A result where the error type is a RucteError.