1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
//! # Handlebars Switch Helper
//!
//! This provides a [Handlebars](http://handlebarsjs.com/) `{{#switch}}` helper to
//! the already incredible [handlebars-rust](https://github.com/sunng87/handlebars-rust)
//! crate.
//!
//! Links of interest:
//!
//! - [Documentation](https://docs.rs/handlebars_switch)
//! - [handlebars-rust](https://github.com/sunng87/handlebars-rust)
//! - [Handlebars](http://handlebarsjs.com)
//!
//! ## Quick Start
//!
//! You can easily add the ``{{#switch}}`` helper to a rust Handlebars object using
//! the `Handlebars#register_helper` method:
//!
//! ```ignore
//! use handlebars::Handlebars;
//! use handlebars_switch::SwitchHelper;
//!
//! let mut handlebars = Handlebars::new();
//! handlebars.register_helper("switch", Box::new(SwitchHelper));
//! ```
//!
//! ### Example
//!
//! Below is an example that renders a different page depending on the user's
//! access level:
//!
//!
//! ```
//! extern crate handlebars_switch;
//! extern crate handlebars;
//! #[macro_use] extern crate serde_json;
//!
//! use handlebars::Handlebars;
//! use handlebars_switch::SwitchHelper;
//!
//! fn main() {
//! let mut handlebars = Handlebars::new();
//! handlebars.register_helper("switch", Box::new(SwitchHelper));
//!
//! let tpl = "\
//! {{#switch access}}\
//! {{#case \"admin\"}}Admin{{/case}}\
//! {{#default}}User{{/default}}\
//! {{/switch}}\
//! ";
//!
//! assert_eq!(
//! handlebars.render_template(tpl, &json!({"access": "admin"})).unwrap(),
//! "Admin"
//! );
//!
//! assert_eq!(
//! handlebars.render_template(tpl, &json!({"access": "nobody"})).unwrap(),
//! "User"
//! );
//! }
//! ```
extern crate handlebars;
#[macro_use]
extern crate serde_json;
pub use self::switch::SwitchHelper;
mod switch;