rocket-include-handlebars 0.1.1

This is a crate which provides macros `handlebars_resources_initialize!` and `handlebars_response!` to statically include HBS (Handlebars) files from your Rust project and make them be the HTTP response sources quickly.
docs.rs failed to build rocket-include-handlebars-0.1.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: rocket-include-handlebars-0.13.7

Include Handlebars Templates for Rocket Framework

This is a crate which provides macros handlebars_resources_initialize! and handlebars_response! to statically include HBS (Handlebars) files from your Rust project and make them be the HTTP response sources quickly.

Example

#![feature(plugin)]
#![plugin(rocket_codegen)]

#[macro_use] extern crate lazy_static;

#[macro_use] extern crate rocket_include_handlebars;
extern crate rocket_etag_if_none_match;

extern crate rocket;
extern crate handlebars;

handlebars_resources_initialize!(
    "index", "included-handlebars/index.hbs",
    "index-2", "included-handlebars/index2.hbs"
);

use std::collections::HashMap;

use rocket::local::Client;
use rocket::http::Status;

use rocket_include_handlebars::HandlebarsResponse;
use rocket_etag_if_none_match::EtagIfNoneMatch;

#[get("/")]
fn index() -> HandlebarsResponse {
    let mut map = HashMap::new();

    map.insert("title", "Title");
    map.insert("body", "Hello, world!");

    handlebars_response!("index", &map)
}

#[get("/2")]
fn index_2() -> HandlebarsResponse {
    let mut map = HashMap::new();

    map.insert("title", "Title");
    map.insert("body", "Hello, world!");

    handlebars_response!("index-2", &map)
}
  • handlebars_resources_initialize! is used for including HBS files into your executable binary file. You need to specify each file's ID and its path. For instance, the above example uses index to represent the file included-handlebars/index.hbs and index-2 to represent the file included-handlebars/index2.hbs. An ID cannot be repeating.
  • handlebars_response! is used for retrieving and rendering the file you input through the macro handlebars_resources_initialize! as a HandlebarsResponse instance with rendered HTML. When its respond_to method is called, three HTTP headers, Content-Type, Content-Length and Etag, will be automatically added, and the rendered HTML can optionally be minified.

Refer to tests/index.rs to see the example completely.

License

MIT