handlebars-iron 0.10.1

Handlebars templating middleware for Iron.
docs.rs failed to build handlebars-iron-0.10.1
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: handlebars-iron-0.29.0

handlebars-iron

Handlebars middleware for the Iron web framework.

Build Status

The most recent version of handlebars-iron, like Hyper, Iron and Handlebars-rust, now compiles on nightly, beta and latest stable (1.5.0+) channel. Our travis task will track the compatibility on all these channels.

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::new2();
  hbse.add(Box::new(DirectorySource::new("./examples/templates/", ".hbs")));

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

  chain.link_after(hbse);

In your handler, set Template to response. As required by Handlebars-rust, your data should impl serialize::json::ToJson. If you are on nightly channel, it is highly recommended to use tojson_macros to generate default ToJson implementation without repeating yourself.

/// 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)
}

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

0.10.0 of handlebars-iron introduces source API. Directory source and Memory source are supported by default. Previous API (HandlebarsEngine::new() and HandlebarsEngine::from()) is deprecated in 0.10.0 and will be replaced by new2 and from2 in future.

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

License

MIT, of course.