diff --git a/Cargo.toml b/Cargo.toml index a6a9a2ae..cfd41b2c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,9 +16,9 @@ exclude = [ [dependencies] clap = "2.2.1" -handlebars = "0.16.0" +handlebars = "0.20.0" rustc-serialize = "0.3.18" -pulldown-cmark = "0.0.7" +pulldown-cmark = "0.0.8" # Watch feature 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 } # Serve feature -iron = { version = "0.3", optional = true } -staticfile = { version = "0.2", optional = true } -ws = { version = "0.4.6", optional = true} +iron = { version = "0.4", optional = true } +staticfile = { version = "0.3", optional = true } +ws = { version = "0.5.1", optional = true} # Tests diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index 7178dc47..dd53a040 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -10,7 +10,7 @@ use std::error::Error; use std::io::{self, Read, Write}; use std::collections::BTreeMap; -use handlebars::{Handlebars, JsonRender}; +use handlebars::Handlebars; use rustc_serialize::json::{Json, ToJson}; @@ -57,7 +57,8 @@ impl Renderer for HtmlHandlebars { for item in book.iter() { match *item { - BookItem::Chapter(_, ref ch) | BookItem::Affix(ref ch) => { + BookItem::Chapter(_, ref ch) | + BookItem::Affix(ref ch) => { if ch.path != PathBuf::new() { 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")); // 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")); 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 content = String::new(); 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 // on the front page, however this case should be very very rare... content = content.lines() - .filter(|line| !line.contains("> = match json::decode(&chapters.to_string()) { 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> = None; @@ -52,7 +52,7 @@ pub fn previous(c: &Context, _h: &Helper, r: &Handlebars, rc: &mut RenderContext }, None => { 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) => { previous_chapter.insert("link".to_owned(), p.replace("\\", "/").to_json()); }, - None => { - return Err(RenderError { - desc: "Link could not be converted to str".to_owned(), - }) - }, + None => return Err(RenderError::new("Link could not be converted to str")), } }, - 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")), } debug!("[*]: Inject in context"); @@ -90,7 +84,7 @@ pub fn previous(c: &Context, _h: &Helper, r: &Handlebars, rc: &mut RenderContext Some(t) => { 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 current = c.navigate(rc.get_path(), "path") - .to_string() - .replace("\"", ""); + .to_string() + .replace("\"", ""); debug!("[*]: Decode chapters from JSON"); // Decode json format let decoded: Vec> = match json::decode(&chapters.to_string()) { 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> = None; @@ -145,7 +139,7 @@ pub fn next(c: &Context, _h: &Helper, r: &Handlebars, rc: &mut RenderContext) -> let previous_path = match previous.get("path") { 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 == ¤t { @@ -160,9 +154,7 @@ pub fn next(c: &Context, _h: &Helper, r: &Handlebars, rc: &mut RenderContext) -> debug!("[*]: Inserting title: {}", n); next_chapter.insert("title".to_owned(), n.to_json()); }, - None => { - return Err(RenderError { desc: "No title found for chapter in JSON data".to_owned() }) - }, + None => return Err(RenderError::new("No title found for chapter in JSON data")), } @@ -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 `/` 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"); @@ -188,7 +180,7 @@ pub fn next(c: &Context, _h: &Helper, r: &Handlebars, rc: &mut RenderContext) -> Some(t) => { 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;