All Projects → maciejhirsz → Ramhorns

maciejhirsz / Ramhorns

Licence: gpl-3.0
Fast Mustache template engine implementation in pure Rust.

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to Ramhorns

Mikado
Mikado is the webs fastest template library for building user interfaces.
Stars: ✭ 323 (+87.79%)
Mutual labels:  templates, handlebars, mustache
Stubble
Trimmed down {{mustache}} templates in .NET
Stars: ✭ 247 (+43.6%)
Mutual labels:  templates, mustache
HandlebarsCookbook
A cookbook of handlebars and mustache, focus on handlebars.js , mustache.js and lightncandy usage
Stars: ✭ 20 (-88.37%)
Mutual labels:  mustache, handlebars
layouts
Wraps templates with layouts. Layouts can use other layouts and be nested to any depth. This can be used 100% standalone to wrap any kind of file with banners, headers or footer content. Use for markdown, HTML, handlebars views, lo-dash templates, etc. Layouts can also be vinyl files.
Stars: ✭ 28 (-83.72%)
Mutual labels:  templates, handlebars
Gluebert
gluebert.js is a tiny helper lazy loading DOM Elements, StyleSheets and JavaScript files using dynamic import and code splitting
Stars: ✭ 194 (+12.79%)
Mutual labels:  handlebars, mustache
laravel-mjml
Laravel MJML offers support for rendering MJML syntax into in-line HTML that can be sent within mails.
Stars: ✭ 26 (-84.88%)
Mutual labels:  mustache, templates
hyperstache
👨‍🦰 Handlebars just got a trim, alternative JS template engine, 2kb gzip
Stars: ✭ 36 (-79.07%)
Mutual labels:  mustache, handlebars
Handlebars.java
Logic-less and semantic Mustache templates with Java
Stars: ✭ 1,204 (+600%)
Mutual labels:  templates, handlebars
Lightncandy
An extremely fast PHP implementation of handlebars ( http://handlebarsjs.com/ ) and mustache ( http://mustache.github.io/ ),
Stars: ✭ 565 (+228.49%)
Mutual labels:  handlebars, mustache
Handlebars
Fullest Handlebars.js templating support for Atom and Sublime Text 2 / 3. Also drives syntax colouring on Github and in Visual Studio Code. Install from: https://atom.io/packages/Handlebars and https://packagecontrol.io/packages/Handlebars.
Stars: ✭ 292 (+69.77%)
Mutual labels:  handlebars, mustache
Handlebars.net
A real .NET Handlebars engine
Stars: ✭ 723 (+320.35%)
Mutual labels:  handlebars, mustache
Scriban
A fast, powerful, safe and lightweight scripting language and engine for .NET
Stars: ✭ 1,360 (+690.7%)
Mutual labels:  handlebars, mustache
Helm Charts
Jenkins community Helm charts
Stars: ✭ 154 (-10.47%)
Mutual labels:  mustache
Templates
A set of standard document templates.
Stars: ✭ 1,953 (+1035.47%)
Mutual labels:  templates
Latex Koma Template
Generic template for midsize and larger documents based on KOMA script classes.
Stars: ✭ 151 (-12.21%)
Mutual labels:  templates
Aeromock
Lightweight mock web application server
Stars: ✭ 152 (-11.63%)
Mutual labels:  handlebars
Cicero
Accord Project Smart Templates Implementation
Stars: ✭ 166 (-3.49%)
Mutual labels:  templates
Pongo2
Django-syntax like template-engine for Go
Stars: ✭ 2,111 (+1127.33%)
Mutual labels:  templates
Point Of View
Template rendering plugin for Fastify
Stars: ✭ 150 (-12.79%)
Mutual labels:  templates
Helm Charts
Helm charts for Kubernetes curated by Kiwigrid
Stars: ✭ 151 (-12.21%)
Mutual labels:  mustache
Ramhorns logo

Ramhorns

Tests badge Crates.io version badge Docs Crates.io license badge

Fast Mustache template engine implementation in pure Rust.

Ramhorns loads and processes templates at runtime. It comes with a derive macro which allows for templates to be rendered from native Rust data structures without doing temporary allocations, intermediate HashMaps or what have you.

With a touch of magic 🎩, the power of friendship 🥂, and a sparkle of FNV hashing ✨, render times easily compete with static template engines like Askama.

What else do you want, a sticker?

Cargo.toml

[dependencies]
ramhorns = "0.5"

Example

use ramhorns::{Template, Content};

#[derive(Content)]
struct Post<'a> {
    title: &'a str,
    teaser: &'a str,
}

#[derive(Content)]
struct Blog<'a> {
    title: String,        // Strings are cool
    posts: Vec<Post<'a>>, // &'a [Post<'a>] would work too
}

// Standard Mustache action here
let source = "<h1>{{title}}</h1>\
              {{#posts}}<article><h2>{{title}}</h2><p>{{teaser}}</p></article>{{/posts}}\
              {{^posts}}<p>No posts yet :(</p>{{/posts}}";

let tpl = Template::new(source).unwrap();

let rendered = tpl.render(&Blog {
    title: "My Awesome Blog!".to_string(),
    posts: vec![
        Post {
            title: "How I tried Ramhorns and found love 💖",
            teaser: "This can happen to you too",
        },
        Post {
            title: "Rust is kinda awesome",
            teaser: "Yes, even the borrow checker! 🦀",
        },
    ]
});

assert_eq!(rendered, "<h1>My Awesome Blog!</h1>\
                      <article>\
                          <h2>How I tried Ramhorns and found love 💖</h2>\
                          <p>This can happen to you too</p>\
                      </article>\
                      <article>\
                          <h2>Rust is kinda awesome</h2>\
                          <p>Yes, even the borrow checker! 🦀</p>\
                      </article>");

Features

  • Rendering common types, such as &str, String, bools, and numbers into {{variables}}.
  • Unescaped printing with {{{tripple-brace}}} or {{&ampersant}}.
  • Rendering sections {{#foo}} ... {{/foo}}.
  • Rendering inverse sections {{^foo}} ... {{/foo}}.
  • Rendering partials {{>file.html}}.
  • Zero-copy CommonMark rendering from fields marked with #[md].

Benches

Rendering a tiny template:

test a_simple_ramhorns            ... bench:          82 ns/iter (+/- 4) = 1182 MB/s
test b_simple_askama              ... bench:         178 ns/iter (+/- 8) = 544 MB/s
test c_simple_tera                ... bench:         416 ns/iter (+/- 98) = 233 MB/s
test c_simple_tera_from_serialize ... bench:         616 ns/iter (+/- 33) = 157 MB/s
test d_simple_mustache            ... bench:         613 ns/iter (+/- 34) = 158 MB/s
test e_simple_handlebars          ... bench:         847 ns/iter (+/- 40) = 114 MB/s

Rendering a tiny template with partials:

test pa_partials_ramhorns         ... bench:          85 ns/iter (+/- 7) = 1141 MB/s
test pb_partials_askama           ... bench:         210 ns/iter (+/- 9) = 461 MB/s
test pc_partials_mustache         ... bench:         827 ns/iter (+/- 39) = 117 MB/s
test pd_partials_handlebars       ... bench:         846 ns/iter (+/- 29) = 114 MB/s

Compiling a template from a string:

test xa_parse_ramhorns            ... bench:         190 ns/iter (+/- 10) = 821 MB/s
test xb_parse_mustache            ... bench:       3,229 ns/iter (+/- 159) = 48 MB/s
test xe_parse_handlebars          ... bench:       6,883 ns/iter (+/- 383) = 22 MB/s

Worth noting here is that Askama is processing templates at compile time and generates static rust code for rendering. This is great for performance, but it also means you can't swap out templates without recompiling your Rust binaries. In some cases, like for a static site generator, this is unfortunately a deal breaker.

Parsing the templates on runtime is never going to be free, however Ramhorns has a really fast parser built on top of Logos, that makes even that part of the process snappy.

The Mustache crate is the closest thing to Ramhorns in design and feature set.

License

Ramhorns is free software, and is released under the terms of the GNU General Public License version 3. See LICENSE.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].