Display-as compile-time template crate


I’d like to announce the display-as crate. display-as is a compile-time templating system (like askama or ructe) that supports multiple output Formats, and can be extended to handle any utf8 text format you wish. Each Format has its own escaping function which is applied to string data. display-as is designed to each object implementing a trait DisplayAs may be easily and correctly used within another template, and each template can embed types of another format (e.g. how URLs and JavaScript show up in HTML).

Currently I myself am only using HTML and URL on my website, but anticipate using the Math format with MathJax in the nearish future. You can mix Formats within a given template, and a given type can have different representations in multiple Formats.

The template language ([see example] (https://github.com/droundy/progressions-website/blob/master/src/activity.html)) I use allows inclusion of arbitrary rust code within a template, including loops and the definition of local variables to be used later in the template. An include! macro combined with local variables gives the same power as “extends” in jinja2 to allow the reuse of the overall structure of a document.

Anyhow, it’s still somewhat sparsely documented and I’m open to breaking changes as I refine the API. But I’m also already using display-as for a real website under development. (For the curious, it’s a learning progression for partial derivatives in upper division physics which may be down for development as you read this) There is built in support for use with the warp web framework, which is tested and used. I’d be happy to add support for other frameworks.