Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
/ructePublic

Rust Compiled Templates with static-file handling

NotificationsYou must be signed in to change notification settings

kaj/ructe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

CratedocsCI

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 theDisplay trait should be outputable.
  • By default, all values should be html-escaped. There should be aneasy 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 compiledand can be called from rust code.

Template format

A template consists of three basic parts:First a preamble ofuse statements, each prepended by an@ sign.Secondly a declaration of the parameters the template takes.And third, the template body.

The full syntax is describedin the documentation.Some examples can be seen inexamples/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><linkrel="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>

How to use ructe

Ructe compiles your templates to rust code that should be compiled withyour other rust code, so it needs to be called before compiling,as describedin the documentation.There are alsoexamples,both for ructe itself and its futures and for using it with the webframeworksaxum,actix-web,gotham,tide,andwarp.There is alsoa separate example of using ructe with warp anddiesel.


[8]ページ先頭

©2009-2025 Movatter.jp