From a17cc673e94db7c739ddb2a2cc7f37a526436ce7 Mon Sep 17 00:00:00 2001 From: Ning Sun Date: Mon, 6 Jul 2015 23:16:50 +0800 Subject: [PATCH 1/3] (chore) make watch function an optional feature --- Cargo.toml | 6 +++++- src/lib.rs | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d9a3ad866..e390b108d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,4 +18,8 @@ handlebars = "*" rustc-serialize = "*" plugin = "*" walker = "*" -notify = "*" +notify = { version = "*", optional = true } + +[features] +default = [] +watch = ["notify"] diff --git a/src/lib.rs b/src/lib.rs index 6dac2e4dd..e8a71f004 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -19,12 +19,16 @@ extern crate iron; extern crate rustc_serialize as serialize; extern crate handlebars; extern crate plugin; -extern crate notify; extern crate walker; +#[cfg(feature = "watch")] +extern crate notify; + pub use self::middleware::Template; pub use self::middleware::HandlebarsEngine; +#[cfg(feature = "watch")] pub use self::watch::Watchable; mod middleware; +#[cfg(feature = "watch")] mod watch; From e4b086fa2c319f522ab4ad9360fb715c75c3a6e9 Mon Sep 17 00:00:00 2001 From: Ning Sun Date: Tue, 7 Jul 2015 10:43:48 +0800 Subject: [PATCH 2/3] (fix) fixed example only for watch feature --- examples/watch_server.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/examples/watch_server.rs b/examples/watch_server.rs index 45b4a2b22..9acffc2c1 100644 --- a/examples/watch_server.rs +++ b/examples/watch_server.rs @@ -1,10 +1,13 @@ +#![allow(dead_code, unused_imports)] extern crate iron; extern crate handlebars_iron as hbs; extern crate rustc_serialize; use iron::prelude::*; use iron::{status}; -use hbs::{Template, HandlebarsEngine, Watchable}; +use hbs::{Template, HandlebarsEngine}; +#[cfg(feature = "watch")] +use hbs::Watchable; use rustc_serialize::json::{ToJson, Json}; use std::collections::BTreeMap; use std::sync::Arc; @@ -50,6 +53,7 @@ fn hello_world(_: &mut Request) -> IronResult { Ok(resp) } +#[cfg(feature = "watch")] fn main() { let mut chain = Chain::new(hello_world); let template_engine_ref = Arc::new(HandlebarsEngine::new("./examples/templates/", ".hbs")); @@ -60,3 +64,8 @@ fn main() { println!("Server running at http://localhost:3000/"); Iron::new(chain).http("localhost:3000").unwrap(); } + +#[cfg(not(feature = "watch"))] +fn main() { + println!("Watch only enabled via --features watch option"); +} From cb0e5a5e105c11b3d1ea9f3ba3cfb113f29579ec Mon Sep 17 00:00:00 2001 From: Ning Sun Date: Tue, 7 Jul 2015 16:38:28 +0800 Subject: [PATCH 3/3] (doc) update doc --- README.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bfbf2b286..aa78e66d3 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,19 @@ 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 = "*" +``` + ```rust let template_engine_ref = Arc::new(HandlebarsEngine::new("./examples/templates/", ".hbs")); template_engine_ref.watch(); @@ -65,7 +78,8 @@ feature. chain.link_after(template_engine_ref); ``` -Check `examples/watch_server.rs` for further information. +Check `examples/watch_server.rs` for further information. To test it: +`cargo run --example watch_server --features watch`. ## License