Crate ructe [] [src]

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 templates::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>
})

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

StaticFiles

Handler for static files.

Functions

compile_static_files

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

compile_templates

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