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
//! # Handlebars for Iron //! //! This library combines [Handlebars templating library](https://github.com/sunng87/handlebars-rust) and [Iron web framework](http://ironframework.io) together. It gives you a `HandlebarsEngine` as Iron `AfterMiddleware`, so you can render your data with specified handlebars template. //! //! ## Setup //! //! Handlebars-iron provides two kinds of template source: `DirectorySource` and `MemorySource` by default. `DirectorySource` helps you to load template files from a directory, which `MemorySource` loads template as string in memory. //! //! To load files from file system, you need to specify template root and file suffix. Handlebars-iron will scan the directory and loads all templates that matches the suffix. The file's relative path name will be applied as template name. //! //! ```ignore //! /// 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.description()); //! } //! //! chain.link_after(hbse); //! //! ``` //! //! ## Usage //! //! From any of your handler, you can set template name and data into our `Template` struct. Remember you need to make your data `ToJson`-able, which is required by handlebars-rust. //! //! We have implemented Modifier for `Template` on `Response`, so you can just use `response.set` to put set template into response and let it processed by our middleware. //! //! Also we made `Response` plugin for `Template` via `HandlebarsEngine`. So you can test your handler from a test case, and retrieve the `Template` you set into it by `response.get::<HandlebarsEngine>`. //! extern crate iron; #[cfg(not(feature = "serde_type"))] extern crate rustc_serialize as serialize; #[cfg(feature = "serde_type")] extern crate serde; #[cfg(feature = "serde_type")] extern crate serde_json; extern crate handlebars; extern crate plugin; extern crate walkdir; #[cfg(feature = "watch")] extern crate notify; #[macro_use] extern crate log; pub use self::middleware::Template; pub use self::middleware::HandlebarsEngine; pub use self::source::{Source, SourceError}; pub use self::sources::directory::DirectorySource; pub use self::sources::memory::MemorySource; #[cfg(feature = "watch")] pub use self::watch::Watchable; mod middleware; #[cfg(feature = "watch")] mod watch; mod source; mod sources;