All Projects → sunng87 → Handlebars Rust

sunng87 / Handlebars Rust

Licence: mit
Rust templating with Handlebars

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to Handlebars Rust

Handlebars Iron
Handlebars middleware for Iron web framework
Stars: ✭ 119 (-81.17%)
Mutual labels:  template-engine, handlebars
Handlebars.net
A real .NET Handlebars engine
Stars: ✭ 723 (+14.4%)
Mutual labels:  template-engine, handlebars
Handlebars.java
Logic-less and semantic Mustache templates with Java
Stars: ✭ 1,204 (+90.51%)
Mutual labels:  template-engine, handlebars
Aeromock
Lightweight mock web application server
Stars: ✭ 152 (-75.95%)
Mutual labels:  template-engine, handlebars
Yarte
Yarte stands for Yet Another Rust Template Engine
Stars: ✭ 189 (-70.09%)
Mutual labels:  template-engine, handlebars
Mikado
Mikado is the webs fastest template library for building user interfaces.
Stars: ✭ 323 (-48.89%)
Mutual labels:  template-engine, handlebars
velvet
A sweet velvety templating package
Stars: ✭ 72 (-88.61%)
Mutual labels:  template-engine, handlebars
Squirrelly
Semi-embedded JS template engine that supports helpers, filters, partials, and template inheritance. 4KB minzipped, written in TypeScript ⛺
Stars: ✭ 359 (-43.2%)
Mutual labels:  template-engine, handlebars
Binserve
A blazingly fast static web server with routing, templating, and security in a single binary you can set up with zero code. ⚡️🦀
Stars: ✭ 401 (-36.55%)
Mutual labels:  handlebars
Twirl
Twirl is Play's default template engine
Stars: ✭ 498 (-21.2%)
Mutual labels:  template-engine
Spring Comparing Template Engines
Demo project to show different Java templating engines in combination with Spring MVC
Stars: ✭ 377 (-40.35%)
Mutual labels:  template-engine
Bladeone
The standalone version Blade Template Engine without Laravel in a single php file and without dependencies
Stars: ✭ 411 (-34.97%)
Mutual labels:  template-engine
Grmustache.swift
Flexible Mustache templates for Swift
Stars: ✭ 538 (-14.87%)
Mutual labels:  template-engine
Ef.js
The timeless, future facing front-end framework
Stars: ✭ 385 (-39.08%)
Mutual labels:  template-engine
Scalate
Scalate is a Scala based template engine which supports HAML, Mustache and JSP, Erb and Velocity style syntaxes.
Stars: ✭ 570 (-9.81%)
Mutual labels:  template-engine
Carbone
Fast and simple report generator, from JSON to pdf, xslx, docx, odt...
Stars: ✭ 487 (-22.94%)
Mutual labels:  template-engine
Markupsafe
Safely add untrusted strings to HTML/XML markup.
Stars: ✭ 367 (-41.93%)
Mutual labels:  template-engine
Latte
☕ Latte: the intuitive and fast template engine for those who want the most secure PHP sites.
Stars: ✭ 616 (-2.53%)
Mutual labels:  template-engine
Lightncandy
An extremely fast PHP implementation of handlebars ( http://handlebarsjs.com/ ) and mustache ( http://mustache.github.io/ ),
Stars: ✭ 565 (-10.6%)
Mutual labels:  handlebars
Mapache
You can use the theme Mapache for ghost in: Blog - Magazine - Landing page - Personal page - Photographers. and in many other things
Stars: ✭ 477 (-24.53%)
Mutual labels:  handlebars

handlebars-rust

Handlebars templating language implemented in Rust and for Rust.

Handlebars-rust is the template engine that renders the official Rust website rust-lang.org, its book.

Build Status MIT licensed Docs rustc Donate

Getting Started

Quick Start

extern crate handlebars;
#[macro_use]
extern crate serde_json;

use handlebars::Handlebars;

fn main() -> Result<(), Box<dyn Error>> {
    let mut reg = Handlebars::new();
    // render without register
    println!(
        "{}",
        reg.render_template("Hello {{name}}", &json!({"name": "foo"}))?
    );

    // register template using given name
    reg.register_template_string("tpl_1", "Good afternoon, {{name}}")?;
    println!("{}", reg.render("tpl_1", &json!({"name": "foo"}))?);
    Ok(())
}

Code Example

If you are not familiar with handlebars language syntax, it is recommended to walk through their introduction first.

Examples are provided in source tree to demo usage of various api.

  • quick the very basic example of registry and render apis
  • render how to define custom helpers with function, trait impl or macro, and also how to use custom helpers.
  • render_file similar to render, but render to file instead of string
  • partials template inheritance with handlebars
  • decorator how to use decorator to change data or define custom helper
  • script how to define custom helper with rhai scripting language, just like using javascript for handlebarsjs
  • error simple case for error
  • dev_mode a web server hosts handlebars in dev_mode, you can edit the template and see the change without restarting your server.

Minimum Rust Version Policy

Handlebars will track Rust nightly and stable channel. When dropping support for previous stable versions, I will bump major version and clarify in CHANGELOG.

Rust compatibility table

Handlebars version range Minimum Rust version
~3.0.0 1.32
~2.0.0 1.32
~1.1.0 1.30
~1.0.0 1.23

Document

Rust doc.

Changelog

Changelog is available in the source tree named as CHANGELOG.md.

Contributor Guide

Any contribution to this library is welcomed. To get started into development, I have several Help Wanted issues, with the difficulty level labeled. When running into any problem, feel free to contact me on github.

I'm always looking for maintainers to work together on this library, let me know (via email or anywhere in the issue tracker) if you want to join.

Why (this) Handlebars?

Handlebars is a real-world templating system that you can use to build your application without pain.

Features

Isolation of Rust and HTML

This library doesn't attempt to use some macro magic to allow you to write your template within your rust code. I admit that it's fun to do that but it doesn't fit real-world use cases.

Limited but essential control structures built-in

Only essential control directives if and each are built-in. This prevents you from putting too much application logic into your template.

Extensible helper system

You can write your own helper with Rust! It can be a block helper or inline helper. Put your logic into the helper and don't repeat yourself.

A helper can be as a simple as a Rust function like:

handlebars_helper!(hex: |v: i64| format!("0x{:x}", v));

/// register the helper
handlebars.register_helper("hex", Box::new(hex));

And using it in your template:

{{hex 16}}

By default, handlebars-rust ships additional helpers (compared with original js version) that is useful when working with if.

With script_helper feature flag enabled, you can also create helpers using rhai script, just like JavaScript for handlebars-js. This feature was in early stage. Its API was limited at the moment, and can change in future.

Template inheritance

Every time I look into a templating system, I will investigate its support for template inheritance.

Template include is not sufficient for template reuse. In most cases you will need a skeleton of page as parent (header, footer, etc.), and embed your page into this parent.

You can find a real example of template inheritance in examples/partials.rs and templates used by this file.

Auto-reload in dev mode

By turning on dev_mode, handlebars auto reloads any template and scripts that loaded from files or directory. This can be handy for template development.

WebAssembly compatible

Handlebars 3.0 can be used in WebAssembly projects.

Related Projects

Web frameworks

Adopters

The adopters page lists projects that uses handlebars for part of their functionalities.

Extensions

The extensions page has libraries that provide additional helpers, decorators and outputs to handlebars-rust, and you can use in your own projects.

License

This library (handlebars-rust) is open sourced under the MIT 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].