Crates.io | ructe |
lib.rs | ructe |
version | 0.17.2 |
source | src |
created_at | 2016-09-24 13:06:50.311834 |
updated_at | 2024-06-30 21:33:00.120127 |
description | Rust Compiled Templates, efficient type-safe web page templates. |
homepage | |
repository | https://github.com/kaj/ructe |
max_upload_size | |
id | 6604 |
size | 127,482 |
This is my attempt at writing a HTML template system for Rust. Some inspiration comes from the scala template system used in play 2, as well as plain old jsp.
Display
trait should be outputable.Ructes is in a rather early stage, but does work; templates can be transpiled to rust functions, which are then compiled and can be called from rust code.
A template consists of three basic parts:
First a preamble of use
statements, each prepended by an @
sign.
Secondly a declaration of the parameters the template takes.
And third, the template body.
The full syntax is described in the documentation. Some examples can be seen in examples/simple/templates. A template may look something like this:
@use any::rust::Type;
@use super::statics::style_css;
@(name: &str, items: &[Type])
<html>
<head>
<title>@name</title>
<link rel="stylesheet" href="/static/@style_css.name" type="text/css"/>
</head>
<body>
<h1>@name</h1>
<dl>
@for item in items {
<dt>@item.title()</dt>
<dd>@item.description()</dd>
}
</dl>
<body>
</html>
Ructe compiles your templates to rust code that should be compiled with your other rust code, so it needs to be called before compiling, as described in the documentation. There are also examples, both for ructe itself and its futures and for using it with the web frameworks axum, actix-web, gotham, iron, nickel, tide, and warp. There is also a separate example of using ructe with warp and diesel.