Giter Club home page Giter Club logo

ructe's Introduction

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 docs CI

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. 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()
       <dd>@item.description()
     }
     </dl>
   <body>
</html>

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. There are also examples, both for ructe itself and its futures and for using it with the web frameworks actix-web, iron, nickel, gotham, and warp. There is also a separate example of using ructe with warp and diesel.

ructe's People

Contributors

kaj avatar kornelski avatar noughmad avatar eroc33 avatar dkotrada avatar jo-so avatar klosspeter avatar prabirshrestha avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.