Added a new macro 'output' that can be disabled by a feature

This commit is contained in:
Mathieu David 2015-08-04 17:13:24 +02:00
parent 1095e7c773
commit 4ead44457a
3 changed files with 21 additions and 5 deletions

View File

@ -10,4 +10,6 @@ rustc-serialize = "*"
pulldown-cmark = "*" pulldown-cmark = "*"
[features] [features]
default = ["output"]
debug = [] debug = []
output = []

View File

@ -9,3 +9,15 @@ macro_rules! debug {
($fmt:expr) => (); ($fmt:expr) => ();
($fmt:expr, $($arg:tt)*) => (); ($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)*) => ();
}

View File

@ -7,8 +7,8 @@ use renderer::Renderer;
use book::{BookItems, BookConfig}; use book::{BookItems, BookConfig};
use {theme, utils}; use {theme, utils};
use std::path::{Path, PathBuf, Component}; use std::path::PathBuf;
use std::fs::{self, File, metadata}; use std::fs::{self, File};
use std::error::Error; use std::error::Error;
use std::io::{self, Read, Write}; use std::io::{self, Read, Write};
use std::collections::BTreeMap; use std::collections::BTreeMap;
@ -86,20 +86,22 @@ impl Renderer for HtmlHandlebars {
debug!("[*]: Render template"); debug!("[*]: Render template");
let rendered = try!(handlebars.render("index", &data)); 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 // Write to file
let mut file = try!(utils::path::create_file(&config.dest().join(&item.path).with_extension("html"))); 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())); try!(file.write_all(&rendered.into_bytes()));
// Create an index.html from the first element in SUMMARY.md // Create an index.html from the first element in SUMMARY.md
if index { if index {
debug!("[*] index.html"); debug!("[*]: index.html");
try!(fs::copy( try!(fs::copy(
config.dest().join(&item.path.with_extension("html")), config.dest().join(&item.path.with_extension("html")),
config.dest().join("index.html") config.dest().join("index.html")
)); ));
println!( output!(
"[*] Creating index.html from {:?} ✓", "[*] Creating index.html from {:?} ✓",
config.dest().join(&item.path.with_extension("html")) config.dest().join(&item.path.with_extension("html"))
); );