diff --git a/Cargo.toml b/Cargo.toml index c0b84656..31524c77 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,4 +10,6 @@ rustc-serialize = "*" pulldown-cmark = "*" [features] +default = ["output"] debug = [] +output = [] diff --git a/src/macros.rs b/src/macros.rs index bb5271e3..551eded8 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -9,3 +9,15 @@ macro_rules! debug { ($fmt:expr) => (); ($fmt:expr, $($arg:tt)*) => (); } + +#[cfg(feature = "output")] +macro_rules! output { + ($fmt:expr) => (println!($fmt)); + ($fmt:expr, $($arg:tt)*) => (println!($fmt, $($arg)*)); +} + +#[cfg(not(feature = "output"))] +macro_rules! output { + ($fmt:expr) => (); + ($fmt:expr, $($arg:tt)*) => (); +} diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index 1a1a5f70..093ee1bf 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -7,8 +7,8 @@ use renderer::Renderer; use book::{BookItems, BookConfig}; use {theme, utils}; -use std::path::{Path, PathBuf, Component}; -use std::fs::{self, File, metadata}; +use std::path::PathBuf; +use std::fs::{self, File}; use std::error::Error; use std::io::{self, Read, Write}; use std::collections::BTreeMap; @@ -86,20 +86,22 @@ impl Renderer for HtmlHandlebars { debug!("[*]: Render template"); let rendered = try!(handlebars.render("index", &data)); - debug!("[*] Write to file"); + debug!("[*]: Create file {:?}", &config.dest().join(&item.path).with_extension("html")); // Write to file let mut file = try!(utils::path::create_file(&config.dest().join(&item.path).with_extension("html"))); + output!("[*] Creating {:?} ✓", &config.dest().join(&item.path).with_extension("html")); + try!(file.write_all(&rendered.into_bytes())); // Create an index.html from the first element in SUMMARY.md if index { - debug!("[*] index.html"); + debug!("[*]: index.html"); try!(fs::copy( config.dest().join(&item.path.with_extension("html")), config.dest().join("index.html") )); - println!( + output!( "[*] Creating index.html from {:?} ✓", config.dest().join(&item.path.with_extension("html")) );