Update all dependencies to latest version

This commit is contained in:
Mathieu David 2016-08-01 14:06:08 +02:00
parent 9c8a563223
commit 5350d62591
3 changed files with 35 additions and 46 deletions

View File

@ -16,9 +16,9 @@ exclude = [
[dependencies] [dependencies]
clap = "2.2.1" clap = "2.2.1"
handlebars = "0.16.0" handlebars = "0.20.0"
rustc-serialize = "0.3.18" rustc-serialize = "0.3.18"
pulldown-cmark = "0.0.7" pulldown-cmark = "0.0.8"
# Watch feature # Watch feature
notify = { version = "2.5.5", optional = true } notify = { version = "2.5.5", optional = true }
@ -26,9 +26,9 @@ time = { version = "0.1.34", optional = true }
crossbeam = { version = "0.2.8", optional = true } crossbeam = { version = "0.2.8", optional = true }
# Serve feature # Serve feature
iron = { version = "0.3", optional = true } iron = { version = "0.4", optional = true }
staticfile = { version = "0.2", optional = true } staticfile = { version = "0.3", optional = true }
ws = { version = "0.4.6", optional = true} ws = { version = "0.5.1", optional = true}
# Tests # Tests

View File

@ -10,7 +10,7 @@ use std::error::Error;
use std::io::{self, Read, Write}; use std::io::{self, Read, Write};
use std::collections::BTreeMap; use std::collections::BTreeMap;
use handlebars::{Handlebars, JsonRender}; use handlebars::Handlebars;
use rustc_serialize::json::{Json, ToJson}; use rustc_serialize::json::{Json, ToJson};
@ -57,7 +57,8 @@ impl Renderer for HtmlHandlebars {
for item in book.iter() { for item in book.iter() {
match *item { match *item {
BookItem::Chapter(_, ref ch) | BookItem::Affix(ref ch) => { BookItem::Chapter(_, ref ch) |
BookItem::Affix(ref ch) => {
if ch.path != PathBuf::new() { if ch.path != PathBuf::new() {
let path = book.get_src().join(&ch.path); let path = book.get_src().join(&ch.path);
@ -105,7 +106,8 @@ impl Renderer for HtmlHandlebars {
debug!("[*]: Create file {:?}", &book.get_dest().join(&ch.path).with_extension("html")); debug!("[*]: Create file {:?}", &book.get_dest().join(&ch.path).with_extension("html"));
// Write to file // Write to file
let mut file = try!(utils::fs::create_file(&book.get_dest().join(&ch.path).with_extension("html"))); let mut file =
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")); output!("[*] Creating {:?} ✓", &book.get_dest().join(&ch.path).with_extension("html"));
try!(file.write_all(&rendered.into_bytes())); try!(file.write_all(&rendered.into_bytes()));
@ -117,14 +119,14 @@ impl Renderer for HtmlHandlebars {
let mut index_file = try!(File::create(book.get_dest().join("index.html"))); let mut index_file = try!(File::create(book.get_dest().join("index.html")));
let mut content = String::new(); let mut content = String::new();
let _source = try!(File::open(book.get_dest().join(&ch.path.with_extension("html")))) let _source = try!(File::open(book.get_dest().join(&ch.path.with_extension("html"))))
.read_to_string(&mut content); .read_to_string(&mut content);
// This could cause a problem when someone displays code containing <base href=...> // This could cause a problem when someone displays code containing <base href=...>
// on the front page, however this case should be very very rare... // on the front page, however this case should be very very rare...
content = content.lines() content = content.lines()
.filter(|line| !line.contains("<base href=")) .filter(|line| !line.contains("<base href="))
.collect::<Vec<&str>>() .collect::<Vec<&str>>()
.join("\n"); .join("\n");
try!(index_file.write_all(content.as_bytes())); try!(index_file.write_all(content.as_bytes()));
@ -218,54 +220,49 @@ impl Renderer for HtmlHandlebars {
// Font Awesome local fallback // Font Awesome local fallback
let mut font_awesome = if let Ok(f) = utils::fs::create_file(&book.get_dest() let mut font_awesome = if let Ok(f) = utils::fs::create_file(&book.get_dest()
.join("_FontAwesome/css/font-awesome.css")) { .join("_FontAwesome/css/font-awesome.css")) {
f f
} else { } else {
return Err(Box::new(io::Error::new(io::ErrorKind::Other, "Could not create font-awesome.css"))); return Err(Box::new(io::Error::new(io::ErrorKind::Other, "Could not create font-awesome.css")));
}; };
try!(font_awesome.write_all(theme::FONT_AWESOME)); try!(font_awesome.write_all(theme::FONT_AWESOME));
let mut font_awesome = if let Ok(f) = utils::fs::create_file(&book.get_dest() let mut font_awesome = if let Ok(f) = utils::fs::create_file(&book.get_dest()
.join("_FontAwesome/fonts/fontawesome-webfon\ .join("_FontAwesome/fonts/fontawesome-webfont.eot")) {
t.eot")) {
f f
} else { } else {
return Err(Box::new(io::Error::new(io::ErrorKind::Other, "Could not create fontawesome-webfont.eot"))); return Err(Box::new(io::Error::new(io::ErrorKind::Other, "Could not create fontawesome-webfont.eot")));
}; };
try!(font_awesome.write_all(theme::FONT_AWESOME_EOT)); try!(font_awesome.write_all(theme::FONT_AWESOME_EOT));
let mut font_awesome = if let Ok(f) = utils::fs::create_file(&book.get_dest() let mut font_awesome = if let Ok(f) = utils::fs::create_file(&book.get_dest()
.join("_FontAwesome/fonts/fontawesome-webfon\ .join("_FontAwesome/fonts/fontawesome-webfont.svg")) {
t.svg")) {
f f
} else { } else {
return Err(Box::new(io::Error::new(io::ErrorKind::Other, "Could not create fontawesome-webfont.svg"))); return Err(Box::new(io::Error::new(io::ErrorKind::Other, "Could not create fontawesome-webfont.svg")));
}; };
try!(font_awesome.write_all(theme::FONT_AWESOME_SVG)); try!(font_awesome.write_all(theme::FONT_AWESOME_SVG));
let mut font_awesome = if let Ok(f) = utils::fs::create_file(&book.get_dest() let mut font_awesome = if let Ok(f) = utils::fs::create_file(&book.get_dest()
.join("_FontAwesome/fonts/fontawesome-webfon\ .join("_FontAwesome/fonts/fontawesome-webfont.ttf")) {
t.ttf")) {
f f
} else { } else {
return Err(Box::new(io::Error::new(io::ErrorKind::Other, "Could not create fontawesome-webfont.ttf"))); return Err(Box::new(io::Error::new(io::ErrorKind::Other, "Could not create fontawesome-webfont.ttf")));
}; };
try!(font_awesome.write_all(theme::FONT_AWESOME_TTF)); try!(font_awesome.write_all(theme::FONT_AWESOME_TTF));
let mut font_awesome = if let Ok(f) = utils::fs::create_file(&book.get_dest() let mut font_awesome = if let Ok(f) = utils::fs::create_file(&book.get_dest()
.join("_FontAwesome/fonts/fontawesome-webfon\ .join("_FontAwesome/fonts/fontawesome-webfont.woff")) {
t.woff")) {
f f
} else { } else {
return Err(Box::new(io::Error::new(io::ErrorKind::Other, "Could not create fontawesome-webfont.woff"))); return Err(Box::new(io::Error::new(io::ErrorKind::Other, "Could not create fontawesome-webfont.woff")));
}; };
try!(font_awesome.write_all(theme::FONT_AWESOME_WOFF)); try!(font_awesome.write_all(theme::FONT_AWESOME_WOFF));
let mut font_awesome = if let Ok(f) = utils::fs::create_file(&book.get_dest() let mut font_awesome = if let Ok(f) = utils::fs::create_file(&book.get_dest()
.join("_FontAwesome/fonts/fontawesome-webfon\ .join("_FontAwesome/fonts/fontawesome-webfont.woff2")) {
t.woff2")) {
f f
} else { } else {
return Err(Box::new(io::Error::new(io::ErrorKind::Other, "Could not create fontawesome-webfont.woff2"))); return Err(Box::new(io::Error::new(io::ErrorKind::Other, "Could not create fontawesome-webfont.woff2")));
}; };
try!(font_awesome.write_all(theme::FONT_AWESOME_WOFF2)); try!(font_awesome.write_all(theme::FONT_AWESOME_WOFF2));
let mut font_awesome = if let Ok(f) = utils::fs::create_file(&book.get_dest() let mut font_awesome = if let Ok(f) = utils::fs::create_file(&book.get_dest()
.join("_FontAwesome/fonts/FontAwesome.ttf")) { .join("_FontAwesome/fonts/FontAwesome.ttf")) {
f f
} else { } else {
return Err(Box::new(io::Error::new(io::ErrorKind::Other, "Could not create FontAwesome.ttf"))); return Err(Box::new(io::Error::new(io::ErrorKind::Other, "Could not create FontAwesome.ttf")));

View File

@ -16,15 +16,15 @@ pub fn previous(c: &Context, _h: &Helper, r: &Handlebars, rc: &mut RenderContext
let chapters = c.navigate(rc.get_path(), "chapters"); let chapters = c.navigate(rc.get_path(), "chapters");
let current = c.navigate(rc.get_path(), "path") let current = c.navigate(rc.get_path(), "path")
.to_string() .to_string()
.replace("\"", ""); .replace("\"", "");
debug!("[*]: Decode chapters from JSON"); debug!("[*]: Decode chapters from JSON");
// Decode json format // Decode json format
let decoded: Vec<BTreeMap<String, String>> = match json::decode(&chapters.to_string()) { let decoded: Vec<BTreeMap<String, String>> = match json::decode(&chapters.to_string()) {
Ok(data) => data, Ok(data) => data,
Err(_) => return Err(RenderError { desc: "Could not decode the JSON data".to_owned() }), Err(_) => return Err(RenderError::new("Could not decode the JSON data")),
}; };
let mut previous: Option<BTreeMap<String, String>> = None; let mut previous: Option<BTreeMap<String, String>> = None;
@ -52,7 +52,7 @@ pub fn previous(c: &Context, _h: &Helper, r: &Handlebars, rc: &mut RenderContext
}, },
None => { None => {
debug!("[*]: No title found for chapter"); debug!("[*]: No title found for chapter");
return Err(RenderError { desc: "No title found for chapter in JSON data".to_owned() }); return Err(RenderError::new("No title found for chapter in JSON data"));
}, },
}; };
@ -68,16 +68,10 @@ pub fn previous(c: &Context, _h: &Helper, r: &Handlebars, rc: &mut RenderContext
Some(p) => { Some(p) => {
previous_chapter.insert("link".to_owned(), p.replace("\\", "/").to_json()); previous_chapter.insert("link".to_owned(), p.replace("\\", "/").to_json());
}, },
None => { None => return Err(RenderError::new("Link could not be converted to str")),
return Err(RenderError {
desc: "Link could not be converted to str".to_owned(),
})
},
} }
}, },
None => { None => return Err(RenderError::new("No path found for chapter in JSON data")),
return Err(RenderError { desc: "No path found for chapter in JSON data".to_owned() })
},
} }
debug!("[*]: Inject in context"); debug!("[*]: Inject in context");
@ -90,7 +84,7 @@ pub fn previous(c: &Context, _h: &Helper, r: &Handlebars, rc: &mut RenderContext
Some(t) => { Some(t) => {
try!(t.render(&updated_context, r, rc)); try!(t.render(&updated_context, r, rc));
}, },
None => return Err(RenderError { desc: "Error with the handlebars template".to_owned() }), None => return Err(RenderError::new("Error with the handlebars template")),
} }
} }
@ -122,14 +116,14 @@ pub fn next(c: &Context, _h: &Helper, r: &Handlebars, rc: &mut RenderContext) ->
let chapters = c.navigate(rc.get_path(), "chapters"); let chapters = c.navigate(rc.get_path(), "chapters");
let current = c.navigate(rc.get_path(), "path") let current = c.navigate(rc.get_path(), "path")
.to_string() .to_string()
.replace("\"", ""); .replace("\"", "");
debug!("[*]: Decode chapters from JSON"); debug!("[*]: Decode chapters from JSON");
// Decode json format // Decode json format
let decoded: Vec<BTreeMap<String, String>> = match json::decode(&chapters.to_string()) { let decoded: Vec<BTreeMap<String, String>> = match json::decode(&chapters.to_string()) {
Ok(data) => data, Ok(data) => data,
Err(_) => return Err(RenderError { desc: "Could not decode the JSON data".to_owned() }), Err(_) => return Err(RenderError::new("Could not decode the JSON data")),
}; };
let mut previous: Option<BTreeMap<String, String>> = None; let mut previous: Option<BTreeMap<String, String>> = None;
@ -145,7 +139,7 @@ pub fn next(c: &Context, _h: &Helper, r: &Handlebars, rc: &mut RenderContext) ->
let previous_path = match previous.get("path") { let previous_path = match previous.get("path") {
Some(p) => p, Some(p) => p,
None => return Err(RenderError { desc: "No path found for chapter in JSON data".to_owned() }), None => return Err(RenderError::new("No path found for chapter in JSON data")),
}; };
if previous_path == &current { if previous_path == &current {
@ -160,9 +154,7 @@ pub fn next(c: &Context, _h: &Helper, r: &Handlebars, rc: &mut RenderContext) ->
debug!("[*]: Inserting title: {}", n); debug!("[*]: Inserting title: {}", n);
next_chapter.insert("title".to_owned(), n.to_json()); next_chapter.insert("title".to_owned(), n.to_json());
}, },
None => { None => return Err(RenderError::new("No title found for chapter in JSON data")),
return Err(RenderError { desc: "No title found for chapter in JSON data".to_owned() })
},
} }
@ -174,7 +166,7 @@ pub fn next(c: &Context, _h: &Helper, r: &Handlebars, rc: &mut RenderContext) ->
// Hack for windows who tends to use `\` as separator instead of `/` // Hack for windows who tends to use `\` as separator instead of `/`
next_chapter.insert("link".to_owned(), l.replace("\\", "/").to_json()); next_chapter.insert("link".to_owned(), l.replace("\\", "/").to_json());
}, },
None => return Err(RenderError { desc: "Link could not converted to str".to_owned() }), None => return Err(RenderError::new("Link could not converted to str")),
} }
debug!("[*]: Inject in context"); debug!("[*]: Inject in context");
@ -188,7 +180,7 @@ pub fn next(c: &Context, _h: &Helper, r: &Handlebars, rc: &mut RenderContext) ->
Some(t) => { Some(t) => {
try!(t.render(&updated_context, r, rc)); try!(t.render(&updated_context, r, rc));
}, },
None => return Err(RenderError { desc: "Error with the handlebars template".to_owned() }), None => return Err(RenderError::new("Error with the handlebars template")),
} }
break; break;