Merge pull request #164 from gambhiro/use-log-crate
use macros from the log crate, issue #151
This commit is contained in:
commit
8f8893bab2
|
@ -19,6 +19,8 @@ clap = "2.2.1"
|
||||||
handlebars = "0.20.0"
|
handlebars = "0.20.0"
|
||||||
rustc-serialize = "0.3.18"
|
rustc-serialize = "0.3.18"
|
||||||
pulldown-cmark = "0.0.8"
|
pulldown-cmark = "0.0.8"
|
||||||
|
log = "0.3"
|
||||||
|
env_logger = "0.3.4"
|
||||||
|
|
||||||
# Watch feature
|
# Watch feature
|
||||||
notify = { version = "2.5.5", optional = true }
|
notify = { version = "2.5.5", optional = true }
|
||||||
|
|
|
@ -2,6 +2,9 @@
|
||||||
extern crate mdbook;
|
extern crate mdbook;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate clap;
|
extern crate clap;
|
||||||
|
#[macro_use]
|
||||||
|
extern crate log;
|
||||||
|
extern crate env_logger;
|
||||||
|
|
||||||
// Dependencies for the Watch feature
|
// Dependencies for the Watch feature
|
||||||
#[cfg(feature = "watch")]
|
#[cfg(feature = "watch")]
|
||||||
|
@ -38,6 +41,8 @@ use mdbook::MDBook;
|
||||||
const NAME: &'static str = "mdbook";
|
const NAME: &'static str = "mdbook";
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
env_logger::init().unwrap();
|
||||||
|
|
||||||
// Create a list of valid arguments and sub-commands
|
// Create a list of valid arguments and sub-commands
|
||||||
let matches = App::new(NAME)
|
let matches = App::new(NAME)
|
||||||
.about("Create a book in form of a static website from markdown files")
|
.about("Create a book in form of a static website from markdown files")
|
||||||
|
|
|
@ -42,7 +42,7 @@ impl MDBook {
|
||||||
pub fn new(root: &Path) -> MDBook {
|
pub fn new(root: &Path) -> MDBook {
|
||||||
|
|
||||||
if !root.exists() || !root.is_dir() {
|
if !root.exists() || !root.is_dir() {
|
||||||
output!("{:?} No directory with that name", root);
|
warn!("{:?} No directory with that name", root);
|
||||||
}
|
}
|
||||||
|
|
||||||
MDBook {
|
MDBook {
|
||||||
|
@ -116,7 +116,7 @@ impl MDBook {
|
||||||
|
|
||||||
if !self.root.exists() {
|
if !self.root.exists() {
|
||||||
fs::create_dir_all(&self.root).unwrap();
|
fs::create_dir_all(&self.root).unwrap();
|
||||||
output!("{:?} created", &self.root);
|
info!("{:?} created", &self.root);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
|
@ -73,7 +73,7 @@ extern crate rustc_serialize;
|
||||||
extern crate handlebars;
|
extern crate handlebars;
|
||||||
extern crate pulldown_cmark;
|
extern crate pulldown_cmark;
|
||||||
|
|
||||||
#[macro_use] pub mod macros;
|
#[macro_use] extern crate log;
|
||||||
pub mod book;
|
pub mod book;
|
||||||
mod parse;
|
mod parse;
|
||||||
pub mod renderer;
|
pub mod renderer;
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
#[cfg(feature = "debug")]
|
|
||||||
macro_rules! debug {
|
|
||||||
($fmt:expr) => (println!($fmt));
|
|
||||||
($fmt:expr, $($arg:tt)*) => (println!($fmt, $($arg)*));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(feature = "debug"))]
|
|
||||||
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)*) => ();
|
|
||||||
}
|
|
|
@ -108,7 +108,7 @@ impl Renderer for HtmlHandlebars {
|
||||||
// Write to file
|
// Write to file
|
||||||
let mut file =
|
let mut file =
|
||||||
try!(utils::fs::create_file(&book.get_dest().join(&ch.path).with_extension("html")));
|
try!(utils::fs::create_file(&book.get_dest().join(&ch.path).with_extension("html")));
|
||||||
output!("[*] Creating {:?} ✓", &book.get_dest().join(&ch.path).with_extension("html"));
|
info!("[*] Creating {:?} ✓", &book.get_dest().join(&ch.path).with_extension("html"));
|
||||||
|
|
||||||
try!(file.write_all(&rendered.into_bytes()));
|
try!(file.write_all(&rendered.into_bytes()));
|
||||||
|
|
||||||
|
@ -130,8 +130,8 @@ impl Renderer for HtmlHandlebars {
|
||||||
|
|
||||||
try!(index_file.write_all(content.as_bytes()));
|
try!(index_file.write_all(content.as_bytes()));
|
||||||
|
|
||||||
output!("[*] Creating index.html from {:?} ✓",
|
info!("[*] Creating index.html from {:?} ✓",
|
||||||
book.get_dest().join(&ch.path.with_extension("html")));
|
book.get_dest().join(&ch.path.with_extension("html")));
|
||||||
index = false;
|
index = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -159,7 +159,7 @@ impl Renderer for HtmlHandlebars {
|
||||||
let rendered = try!(handlebars.render("index", &data));
|
let rendered = try!(handlebars.render("index", &data));
|
||||||
let mut file = try!(utils::fs::create_file(&book.get_dest().join("print").with_extension("html")));
|
let mut file = try!(utils::fs::create_file(&book.get_dest().join("print").with_extension("html")));
|
||||||
try!(file.write_all(&rendered.into_bytes()));
|
try!(file.write_all(&rendered.into_bytes()));
|
||||||
output!("[*] Creating print.html ✓");
|
info!("[*] Creating print.html ✓");
|
||||||
|
|
||||||
// Copy static files (js, css, images, ...)
|
// Copy static files (js, css, images, ...)
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ pub fn render_playpen(s: &str, path: &Path) -> String {
|
||||||
|
|
||||||
// Check if the file exists
|
// Check if the file exists
|
||||||
if !playpen.rust_file.exists() || !playpen.rust_file.is_file() {
|
if !playpen.rust_file.exists() || !playpen.rust_file.is_file() {
|
||||||
output!("[-] No file exists for {{{{#playpen }}}}\n {}", playpen.rust_file.to_str().unwrap());
|
warn!("[-] No file exists for {{{{#playpen }}}}\n {}", playpen.rust_file.to_str().unwrap());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -150,9 +150,9 @@ pub fn copy_files_except_ext(from: &Path, to: &Path, recursive: bool, ext_blackl
|
||||||
debug!("[*] creating path for file: {:?}",
|
debug!("[*] creating path for file: {:?}",
|
||||||
&to.join(entry.path().file_name().expect("a file should have a file name...")));
|
&to.join(entry.path().file_name().expect("a file should have a file name...")));
|
||||||
|
|
||||||
output!("[*] Copying file: {:?}\n to {:?}",
|
info!("[*] Copying file: {:?}\n to {:?}",
|
||||||
entry.path(),
|
entry.path(),
|
||||||
&to.join(entry.path().file_name().expect("a file should have a file name...")));
|
&to.join(entry.path().file_name().expect("a file should have a file name...")));
|
||||||
try!(fs::copy(entry.path(),
|
try!(fs::copy(entry.path(),
|
||||||
&to.join(entry.path().file_name().expect("a file should have a file name..."))));
|
&to.join(entry.path().file_name().expect("a file should have a file name..."))));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue