Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kaj/ructe
Rust Compiled Templates with static-file handling
https://github.com/kaj/ructe
html loop rust template-engine web
Last synced: about 20 hours ago
JSON representation
Rust Compiled Templates with static-file handling
- Host: GitHub
- URL: https://github.com/kaj/ructe
- Owner: kaj
- Created: 2016-09-15T18:55:13.000Z (over 8 years ago)
- Default Branch: main
- Last Pushed: 2024-06-30T21:33:10.000Z (7 months ago)
- Last Synced: 2025-01-18T13:03:22.660Z (8 days ago)
- Topics: html, loop, rust, template-engine, web
- Language: Rust
- Homepage: https://crates.io/crates/ructe
- Size: 697 KB
- Stars: 455
- Watchers: 9
- Forks: 33
- Open Issues: 18
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
- awesome-rust-cn - kaj/ructe - ci.org/kaj/ructe.svg?branch=master">](https://travis-ci.org/kaj/ructe) (Libraries / Template engine)
- awesome-rust - kaj/ructe - ci.org/kaj/ructe.svg?branch=master">](https://travis-ci.org/kaj/ructe) (Libraries / Template engine)
- awesome-rust - kaj/ructe
- awesome-rust-cn - kaj/ructe
- awesome-rust-zh - kaj/ructe - Rust 模板系统[<img src="https://api.travis-ci.org/kaj/ructe.svg?branch=master">](https://travis-ci.org/kaj/ructe) (库 / 模板引擎)
- trackawesomelist - kaj/ructe (⭐454) - HTML template system (Recently Updated / [Dec 17, 2024](/content/2024/12/17/README.md))
README
# Rust Compiled Templates — ructe
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.[![Crate](https://img.shields.io/crates/v/ructe.svg)](https://crates.io/crates/ructe)
[![docs](https://docs.rs/ructe/badge.svg)](https://docs.rs/ructe)
[![CI](https://github.com/kaj/ructe/workflows/CI/badge.svg)](https://github.com/kaj/ructe/actions)## Design criteria
* As many errors as possible should be caught at compile-time.
* A compiled binary should include all the template code it needs,
no need to read template files at runtime.
* Compilation may take time, running should be fast.
* Writing templates should be almost as easy as writing html.
* The template language should be as expressive as possible.
* It should be possible to write templates for any text-like format,
not only html.
* Any value that implements the `Display` trait should be outputable.
* By default, all values should be html-escaped. There should be an
easy but explicit way to output preformatted html.## Current status
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.### Template format
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](https://docs.rs/ructe/).
Some examples can be seen in
[examples/simple/templates](examples/simple/templates).
A template may look something like this:```html
@use any::rust::Type;
@use super::statics::style_css;@(name: &str, items: &[Type])
@name
@name
- @item.title()
- @item.description()
@for item in items {
}
```
## How to use ructe
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](https://docs.rs/ructe/).
There are also [examples](examples),
both for ructe itself and its futures and for using it with the web
frameworks [axum](examples/axum), [actix-web](examples/actix), [gotham](examples/gotham),
[iron](examples/iron), [nickel](examples/nickel), [tide](examples/tide),
and [warp](examples/warp03).
There is also [a separate example of using ructe with warp and
diesel](https://github.com/kaj/warp-diesel-ructe-sample).