From 4ead44457aa7295e81c4c49a68f41196c66a648c Mon Sep 17 00:00:00 2001 From: Mathieu David Date: Tue, 4 Aug 2015 17:13:24 +0200 Subject: [PATCH] Added a new macro 'output' that can be disabled by a feature --- Cargo.toml | 2 ++ src/macros.rs | 12 ++++++++++++ src/renderer/html_handlebars/hbs_renderer.rs | 12 +++++++----- 3 files changed, 21 insertions(+), 5 deletions(-) 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")) );