All Projects → sunng87 → Handlebars Iron

sunng87 / Handlebars Iron

Licence: mit
Handlebars middleware for Iron web framework

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to Handlebars Iron

velvet
A sweet velvety templating package
Stars: ✭ 72 (-39.5%)
Mutual labels:  template-engine, handlebars
Aeromock
Lightweight mock web application server
Stars: ✭ 152 (+27.73%)
Mutual labels:  template-engine, handlebars
Yarte
Yarte stands for Yet Another Rust Template Engine
Stars: ✭ 189 (+58.82%)
Mutual labels:  template-engine, handlebars
Mikado
Mikado is the webs fastest template library for building user interfaces.
Stars: ✭ 323 (+171.43%)
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 (+201.68%)
Mutual labels:  template-engine, handlebars
Handlebars.net
A real .NET Handlebars engine
Stars: ✭ 723 (+507.56%)
Mutual labels:  template-engine, handlebars
Handlebars Rust
Rust templating with Handlebars
Stars: ✭ 632 (+431.09%)
Mutual labels:  template-engine, handlebars
Handlebars.java
Logic-less and semantic Mustache templates with Java
Stars: ✭ 1,204 (+911.76%)
Mutual labels:  template-engine, handlebars
Geco
Simple code generator based on a console project, running on .Net core and using C# interpolated strings
Stars: ✭ 97 (-18.49%)
Mutual labels:  template-engine
Nodejs Mysql Links
A CRUD Web Application with authentication using Nodejs, Mysql and other Javascript technologies
Stars: ✭ 110 (-7.56%)
Mutual labels:  handlebars
Electronjs.org
Electron website
Stars: ✭ 1,341 (+1026.89%)
Mutual labels:  handlebars
Ember Cli Postcss
🔥 A Postcss integration for ember-cli
Stars: ✭ 97 (-18.49%)
Mutual labels:  handlebars
Light Blue Dashboard
🔥 Free and open-source admin dashboard template built with Bootstrap
Stars: ✭ 110 (-7.56%)
Mutual labels:  handlebars
Api2html
Using the data from your API, generate the HTML on the fly! Server-side rendering of the mustache templates
Stars: ✭ 97 (-18.49%)
Mutual labels:  template-engine
Dna.js
🧬 An uncomplicated user interface library for building data-driven semantic templates
Stars: ✭ 114 (-4.2%)
Mutual labels:  template-engine
Utils Decorators
Decorators for web and node applications
Stars: ✭ 95 (-20.17%)
Mutual labels:  webdevelopment
Checklist Going Live
The checklist that is used when a project is going live
Stars: ✭ 1,334 (+1021.01%)
Mutual labels:  webdevelopment
Twital
Twital is a "plugin" for Twig that adds some sugar syntax, which makes its templates similar to PHPTal or VueJS.
Stars: ✭ 116 (-2.52%)
Mutual labels:  template-engine
Webpack Seed
🚀 A Multi-Page Application base on webpack and babel. webpack搭建基于ES6,支持模板的多页面项目
Stars: ✭ 113 (-5.04%)
Mutual labels:  handlebars
Project Based Learning
Curated list of project-based tutorials
Stars: ✭ 60,163 (+50457.14%)
Mutual labels:  webdevelopment

handlebars-iron

Handlebars middleware for the Iron web framework.

Build Status

This library, together with handlebars, iron and hyper, works on both stable and nightly rust.

Both iron and handlebars has backward-incompatible change during 0.x releases. So you will need to choose handlebars-iron version based on those two versions you were using:

handlebars-iron handlebars iron
0.14.x 0.16.x 0.2.x
0.15.x 0.18.x 0.3.x
0.16.0 0.19.x 0.3.x
0.17.x 0.19.x 0.4.x
0.18.x 0.20.x (serde 0.8) 0.4.x
0.19.x 0.22.x 0.4.x
0.20.x 0.23.x 0.4.x
0.21.x 0.24.x 0.4.x
0.22.x 0.24.x 0.5.x
0.23.x 0.25.x (serde 0.9) 0.5.x
0.24.x 0.26.x (serde 1.0) 0.5.x
0.25.x 0.29.x 0.5.x
0.26.x 0.32.x 0.6.x
0.27.x 1.x 0.6.x
0.28.x 2.x 0.6.x
0.29.x 3.x 0.6.x

Usage

Add HandlebarsEngine to your Iron middleware chain as an "after" middleware.

  /// HandlebarsEngine will look up all files with "./examples/templates/**/*.hbs"
  let mut hbse = HandlebarsEngine::new();
  hbse.add(Box::new(DirectorySource::new("./examples/templates/", ".hbs")));

  // load templates from all registered sources
  if let Err(r) = hbse.reload() {
    panic!("{}", r);
  }

  chain.link_after(hbse);

If you want register your own custom helpers, you can initialize the HandlebarsEngine from a custom Handlebars registry.

  let mut hbse = HandlebarsEngine::new();
  hbse.add(Box::new(DirectorySource::new("./examples/templates/", ".hbs")));
  hbse.handlebars_mut().register_helper("helper", my_helper);

  // load templates from all registered sources
  if let Err(r) = hbse.reload() {
    panic!("{}", r);
  }

  chain.link_after(hbse);

You can find more information about custom helper in handlebars-rust document.

In your handler, set Template to response. As required by Handlebars-rust, your data should impl serde::Serialize.

For DirectorySource, handlebars engine will walk the directory specified by prefix, try to register all templates matches the suffix, and extract its name as template name. For instance, ./examples/templates/some/path/index.hbs will be registered as some/path/index.

/// render data with "index" template
/// that is "./examples/templates/index.hbs"
fn hello_world(_: &mut Request) -> IronResult<Response> {
    let mut resp = Response::new();

    let data = ...
    resp.set_mut(Template::new("index", data)).set_mut(status::Ok);
    Ok(resp)
}

By using Template::with You can also render some template without actually register it. But this is not recommended because template string needs to be parsed every time. Consider using a MemorySource if possible.

/// render data with "index" template
/// that is "./examples/templates/index.hbs"
fn hello_world(_: &mut Request) -> IronResult<Response> {
    let mut resp = Response::new();

    let data = ...
    resp.set_mut(Template::with("<h1>{{title}}</h1>", data)).set_mut(status::Ok);
    Ok(resp)
}

Since this is simple library, you may run this example with RUST_LOG=handlebars_iron=info cargo run --example server first, and documentation then.

Rust and its ecosystem are still in early stage, this project might been broken for various reasons. I will try my best to keep this library compiles with latest Rust nightly before the 1.0 final release. If you find anything bad, pull requests and issue reporting are always welcomed.

Live reload

During development you may want to live-reload your templates without having to restart your web server. Here comes the live-reload feature.

Since live-reload may only be useful in development phase, we have made it a optional feature. In order to enable it, you will need to add feature watch in your cargo declaration:

[features]
## create a feature in your app
watch = ["handlebars-iron/watch"]

[dependencies]
handlebars-iron = ...

Check examples/watch_server.rs for further information. To test it: RUST_LOG=handlebars_iron=info cargo run --example watch_server --features watch.

Using handlebars-iron?

Add your project to our adopters.

License

MIT, of course.

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].